Skip to content

Commit 9865b53

Browse files
Add pinned version_partition column to schema version tables (SQL) (#602)
1 parent 4ee2031 commit 9865b53

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

common/persistence/sql/sqlplugin/mysql/admin.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,32 @@ import (
3030
)
3131

3232
const (
33-
readSchemaVersionQuery = `SELECT curr_version from schema_version where db_name=?`
33+
readSchemaVersionQuery = `SELECT curr_version from schema_version where version_partition=0 and db_name=?`
3434

35-
writeSchemaVersionQuery = `REPLACE into schema_version(db_name, creation_time, curr_version, min_compatible_version) VALUES (?,?,?,?)`
35+
writeSchemaVersionQuery = `INSERT into schema_version(version_partition, db_name, creation_time, curr_version, min_compatible_version) ` +
36+
`VALUES (0,?,?,?,?) ` +
37+
`ON DUPLICATE KEY UPDATE ` +
38+
`creation_time=VALUES(creation_time), curr_version=VALUES(curr_version), min_compatible_version=VALUES(min_compatible_version)`
3639

37-
writeSchemaUpdateHistoryQuery = `INSERT into schema_update_history(year, month, update_time, old_version, new_version, manifest_md5, description) VALUES(?,?,?,?,?,?,?)`
40+
writeSchemaUpdateHistoryQuery = `INSERT into schema_update_history(version_partition, year, month, update_time, old_version, new_version, manifest_md5, description) VALUES(0,?,?,?,?,?,?,?)`
3841

39-
createSchemaVersionTableQuery = `CREATE TABLE schema_version(db_name VARCHAR(255) not null PRIMARY KEY, ` +
42+
createSchemaVersionTableQuery = `CREATE TABLE schema_version(version_partition INT not null, ` +
43+
`db_name VARCHAR(255) not null, ` +
4044
`creation_time DATETIME(6), ` +
4145
`curr_version VARCHAR(64), ` +
42-
`min_compatible_version VARCHAR(64));`
46+
`min_compatible_version VARCHAR(64), ` +
47+
`PRIMARY KEY (version_partition, db_name));`
4348

4449
createSchemaUpdateHistoryTableQuery = `CREATE TABLE schema_update_history(` +
50+
`version_partition INT not null, ` +
4551
`year int not null, ` +
4652
`month int not null, ` +
4753
`update_time DATETIME(6) not null, ` +
4854
`description VARCHAR(255), ` +
4955
`manifest_md5 VARCHAR(64), ` +
5056
`new_version VARCHAR(64), ` +
5157
`old_version VARCHAR(64), ` +
52-
`PRIMARY KEY (year, month, update_time));`
58+
`PRIMARY KEY (version_partition, year, month, update_time));`
5359

5460
//NOTE we have to use %v because somehow mysql doesn't work with ? here
5561
createDatabaseQuery = "CREATE database %v CHARACTER SET UTF8"

common/persistence/sql/sqlplugin/postgres/admin.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,34 @@ import (
3030
)
3131

3232
const (
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

Comments
 (0)