@@ -30,30 +30,34 @@ import (
3030)
3131
3232const (
33- readSchemaVersionQuery = `SELECT curr_version from schema_version where db_name=$1`
33+ readSchemaVersionQuery = `SELECT curr_version from schema_version where version_partition=0 and db_name=$1`
3434
35- writeSchemaVersionQuery = `INSERT into schema_version(db_name, creation_time, curr_version, min_compatible_version) VALUES ($1,$2,$3,$4)
36- ON CONFLICT (db_name) DO UPDATE
35+ writeSchemaVersionQuery = `INSERT into schema_version(version_partition, db_name, creation_time, curr_version, min_compatible_version) VALUES (0, $1,$2,$3,$4)
36+ ON CONFLICT (version_partition, db_name) DO UPDATE
3737 SET creation_time = excluded.creation_time,
3838 curr_version = excluded.curr_version,
3939 min_compatible_version = excluded.min_compatible_version;`
4040
41- writeSchemaUpdateHistoryQuery = `INSERT into schema_update_history(year, month, update_time, old_version, new_version, manifest_md5, description) VALUES($1,$2,$3,$4,$5,$6,$7)`
41+ writeSchemaUpdateHistoryQuery = `INSERT into schema_update_history(version_partition, year, month, update_time, old_version, new_version, manifest_md5, description) VALUES(0, $1,$2,$3,$4,$5,$6,$7)`
4242
43- createSchemaVersionTableQuery = `CREATE TABLE schema_version(db_name VARCHAR(255) not null PRIMARY KEY, ` +
43+ createSchemaVersionTableQuery = `CREATE TABLE schema_version(` +
44+ `version_partition INT not null, ` +
45+ `db_name VARCHAR(255) not null, ` +
4446 `creation_time TIMESTAMP, ` +
4547 `curr_version VARCHAR(64), ` +
46- `min_compatible_version VARCHAR(64));`
48+ `min_compatible_version VARCHAR(64), ` +
49+ `PRIMARY KEY (version_partition, db_name));`
4750
4851 createSchemaUpdateHistoryTableQuery = `CREATE TABLE schema_update_history(` +
52+ `version_partition INT not null, ` +
4953 `year int not null, ` +
5054 `month int not null, ` +
5155 `update_time TIMESTAMP not null, ` +
5256 `description VARCHAR(255), ` +
5357 `manifest_md5 VARCHAR(64), ` +
5458 `new_version VARCHAR(64), ` +
5559 `old_version VARCHAR(64), ` +
56- `PRIMARY KEY (year, month, update_time));`
60+ `PRIMARY KEY (version_partition, year, month, update_time));`
5761
5862 // NOTE we have to use %v because somehow postgres doesn't work with ? here
5963 // It's a small bug in sqlx library
0 commit comments