aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--db/db.go9
-rw-r--r--db/migrations.go28
2 files changed, 19 insertions, 18 deletions
diff --git a/db/db.go b/db/db.go
index 63de87c..2adc8c8 100644
--- a/db/db.go
+++ b/db/db.go
@@ -59,11 +59,12 @@ func migratedb() error {
59 59
60 mig := make([]migrate.Migration, 0) 60 mig := make([]migrate.Migration, 0)
61 61
62 for _, migration := range migrations { 62 for i := range migrations {
63 index := i
63 mig = append(mig, migrate.Migration{ 64 mig = append(mig, migrate.Migration{
64 Version: migration.Version, 65 Version: migrations[index].Version,
65 Up: func(db orm.DB) error { 66 Up: func(db orm.DB) error {
66 for _, query := range migration.Up { 67 for _, query := range migrations[index].Up {
67 _, err := db.Exec(query) 68 _, err := db.Exec(query)
68 if err != nil { 69 if err != nil {
69 return err 70 return err
@@ -73,7 +74,7 @@ func migratedb() error {
73 return nil 74 return nil
74 }, 75 },
75 Down: func(db orm.DB) error { 76 Down: func(db orm.DB) error {
76 for _, query := range migration.Down { 77 for _, query := range migrations[index].Down {
77 _, err := db.Exec(query) 78 _, err := db.Exec(query)
78 if err != nil { 79 if err != nil {
79 return err 80 return err
diff --git a/db/migrations.go b/db/migrations.go
index 5d753f3..23847c9 100644
--- a/db/migrations.go
+++ b/db/migrations.go
@@ -26,7 +26,7 @@ var migrations []Migration = []Migration{
26 config jsonb 26 config jsonb
27 )`, 27 )`,
28 `CREATE UNIQUE INDEX IF NOT EXISTS market_name_user_id_idx ON public.market_configs (user_id, market_name)`, 28 `CREATE UNIQUE INDEX IF NOT EXISTS market_name_user_id_idx ON public.market_configs (user_id, market_name)`,
29 `CREATE INDEX IF NOT EXISTS market_configs_user_id ON market_configs (user_id)`, 29 `CREATE INDEX IF NOT EXISTS market_configs_user_id ON market_configs (user_id)`,
30 `CREATE TABLE reports ( 30 `CREATE TABLE reports (
31 id BIGSERIAL PRIMARY KEY, 31 id BIGSERIAL PRIMARY KEY,
32 date timestamp with time zone NOT NULL, 32 date timestamp with time zone NOT NULL,
@@ -60,21 +60,21 @@ var migrations []Migration = []Migration{
60 Down: []string{"DROP VIEW view_report_lines_by_user", "DROP TABLE report_lines", "DROP TABLE reports", "DROP TABLE market_configs", "DROP TABLE users"}, 60 Down: []string{"DROP VIEW view_report_lines_by_user", "DROP TABLE report_lines", "DROP TABLE reports", "DROP TABLE market_configs", "DROP TABLE users"},
61 }, 61 },
62 { 62 {
63 Version: 2, 63 Version: 201805061000,
64 Up: []string{ 64 Up: []string{
65 `CREATE VIEW "view_balances" AS 65 `CREATE VIEW "view_balances" AS
66 SELECT report_lines.id, 66 SELECT report_lines.id,
67 reports.id AS report_id, 67 reports.id AS report_id,
68 market_configs.market_name, 68 market_configs.market_name,
69 market_configs.id AS market_id, 69 market_configs.id AS market_id,
70 reports.date AS report_date, 70 reports.date AS report_date,
71 report_lines.date, 71 report_lines.date,
72 report_lines.payload 72 report_lines.payload
73 FROM report_lines 73 FROM report_lines
74 JOIN reports ON reports.id = report_lines.report_id 74 JOIN reports ON reports.id = report_lines.report_id
75 JOIN market_configs ON reports.market_config_id = market_configs.id 75 JOIN market_configs ON reports.market_config_id = market_configs.id
76 WHERE report_lines.payload::jsonb->'checkpoint' IS NOT NULL`, 76 WHERE report_lines.payload::jsonb->'checkpoint' IS NOT NULL`,
77 `CREATE INDEX checkpoints_idx ON report_lines ((payload->>'checkpoint'))`, 77 `CREATE INDEX checkpoints_idx ON report_lines ((payload->>'checkpoint'))`,
78 }, 78 },
79 Down: []string{"DROP VIEW view_balances", "DROP INDEX checkpoints_idx"}, 79 Down: []string{"DROP VIEW view_balances", "DROP INDEX checkpoints_idx"},
80 }, 80 },