]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git/blame - db/migrations.go
Add missing index and view
[perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git] / db / migrations.go
CommitLineData
4215df47 1package db
2
3type Migration struct {
4 Version int64
5 Up []string
6 Down []string
7}
8
9var migrations []Migration = []Migration{
10 {
11 Version: 1,
12 Up: []string{
13 `CREATE TABLE users (
14 id BIGSERIAL PRIMARY KEY,
15 email text NOT NULL,
16 password_hash text NOT NULL,
17 otp_secret text,
18 is_otp_setup boolean,
19 status smallint,
20 UNIQUE(email)
21 )`,
22 `CREATE TABLE market_configs (
23 id BIGSERIAL PRIMARY KEY,
24 market_name text NOT NULL,
25 user_id bigint NOT NULL REFERENCES users(id),
26 config jsonb,
27 UNIQUE(user_id, market_name)
28 )`,
18344354 29 `CREATE INDEX IF NOT EXISTS market_configs_user_id ON market_configs (user_id)`,
17b68539 30 `CREATE TABLE reports (
31 id BIGSERIAL PRIMARY KEY,
32 date timestamp with time zone NOT NULL,
33 market_config_id bigint NOT NULL,
34 debug boolean
35 )`,
36 "CREATE INDEX IF NOT EXISTS reports_market_config_id ON reports (market_config_id)",
4215df47 37 `CREATE TABLE report_lines (
38 id BIGSERIAL PRIMARY KEY,
39 date timestamp with time zone NOT NULL,
17b68539 40 report_id bigint NOT NULL REFERENCES reports(id),
4215df47 41 type text,
42 payload jsonb
43 )`,
44 "CREATE INDEX IF NOT EXISTS report_lines_report_id ON report_lines (report_id)",
45 "CREATE INDEX IF NOT EXISTS report_lines_type ON report_lines (type)",
46 },
2b2fd737 47 Down: []string{"DROP TABLE users", "DROP TABLE market_configs", "DROP TABLE report_lines", "DROP TABLE reports"},
4215df47 48 },
18344354
IB
49 {
50 Version: 201805061000,
51 Up: []string{
52 `CREATE VIEW "view_balances" AS
53 SELECT report_lines.id,
54 reports.id AS report_id,
55 market_configs.market_name,
56 users.id AS user_id,
57 users.email AS user_email,
58 reports.date AS report_date,
59 report_lines.date,
60 report_lines.payload
61 FROM (((report_lines
62 JOIN reports ON ((reports.id = report_lines.report_id)))
63 JOIN market_configs ON ((reports.market_config_id = market_configs.id)))
64 JOIN users ON ((market_configs.user_id = users.id)))
65 WHERE report_lines.payload::jsonb->'checkpoint' IS NOT NULL`,
66 `CREATE INDEX checkpoints_idx ON report_lines ((payload->>'checkpoint'))`,
67 },
68 Down: []string{"DROP VIEW view_balances", "DROP INDEX checkpoints_idx"},
69 },
4215df47 70}