Skip to content
Permalink
Browse files

speed up host & pathname migration by using UNION. perform VACUUM for…

… SQLite migrations.
  • Loading branch information...
dannyvankooten committed Nov 14, 2018
1 parent 00d2657 commit da6ffde2eabb50433aa48000d1eee459b360930f
@@ -1,6 +1,5 @@
-- +migrate Up
INSERT IGNORE INTO hostnames(name) SELECT DISTINCT(hostname) FROM daily_page_stats;
INSERT IGNORE INTO hostnames(name) SELECT DISTINCT(hostname) FROM daily_referrer_stats;
INSERT INTO hostnames(name) SELECT hostname FROM daily_page_stats UNION SELECT hostname FROM daily_referrer_stats;

-- +migrate Down

@@ -1,6 +1,5 @@
-- +migrate Up
INSERT IGNORE INTO pathnames(name) SELECT DISTINCT(pathname) FROM daily_page_stats;
INSERT IGNORE INTO pathnames(name) SELECT DISTINCT(pathname) FROM daily_referrer_stats;
INSERT INTO pathnames(name) SELECT pathname FROM daily_page_stats UNION SELECT pathname FROM daily_referrer_stats;

-- +migrate Down

@@ -1,6 +1,5 @@
-- +migrate Up
INSERT INTO hostnames(name) SELECT DISTINCT(hostname) FROM daily_page_stats;
INSERT INTO hostnames(name) SELECT DISTINCT(hostname) FROM daily_referrer_stats ON CONFLICT(name) DO NOTHING;
INSERT INTO hostnames(name) SELECT hostname FROM daily_page_stats UNION SELECT hostname FROM daily_referrer_stats;

-- +migrate Down

@@ -1,6 +1,5 @@
-- +migrate Up
INSERT INTO pathnames(name) SELECT DISTINCT(pathname) FROM daily_page_stats ON CONFLICT(name) DO NOTHING; ;
INSERT INTO pathnames(name) SELECT DISTINCT(pathname) FROM daily_referrer_stats ON CONFLICT(name) DO NOTHING; ;
INSERT INTO pathnames(name) SELECT pathname FROM daily_page_stats UNION SELECT pathname FROM daily_referrer_stats;

-- +migrate Down

@@ -0,0 +1,4 @@
-- +migrate Up notransaction
VACUUM;

-- +migrate Down
@@ -1,6 +1,5 @@
-- +migrate Up
INSERT OR IGNORE INTO hostnames(name) SELECT DISTINCT(hostname) FROM daily_page_stats;
INSERT OR IGNORE INTO hostnames(name) SELECT DISTINCT(hostname) FROM daily_referrer_stats;
-- +migrate Up
INSERT INTO hostnames(name) SELECT hostname FROM daily_page_stats UNION SELECT hostname FROM daily_referrer_stats;

-- +migrate Down

@@ -1,6 +1,5 @@
-- +migrate Up
INSERT OR IGNORE INTO pathnames(name) SELECT DISTINCT(pathname) FROM daily_page_stats;
INSERT OR IGNORE INTO pathnames(name) SELECT DISTINCT(pathname) FROM daily_referrer_stats;
INSERT INTO pathnames(name) SELECT pathname FROM daily_page_stats UNION SELECT pathname FROM daily_referrer_stats;

-- +migrate Down

@@ -0,0 +1,4 @@
-- +migrate Up notransaction
VACUUM;

-- +migrate Down
@@ -48,7 +48,7 @@ func New(c *Config) *sqlstore {
log.Printf("Connected to %s database: %s on %s", c.Driver, c.Dbname(), c.Host)
}

// run migrations
// apply database migrations (if any)
db.Migrate()

return db

0 comments on commit da6ffde

Please sign in to comment.
You can’t perform that action at this time.