Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions common/persistence/sql/sqlplugin/mysql/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,32 @@ import (
)

const (
readSchemaVersionQuery = `SELECT curr_version from schema_version where db_name=?`
readSchemaVersionQuery = `SELECT curr_version from schema_version where version_partition=0 and db_name=?`

writeSchemaVersionQuery = `REPLACE into schema_version(db_name, creation_time, curr_version, min_compatible_version) VALUES (?,?,?,?)`
writeSchemaVersionQuery = `INSERT into schema_version(version_partition, db_name, creation_time, curr_version, min_compatible_version) ` +
`VALUES (0,?,?,?,?) ` +
`ON DUPLICATE KEY UPDATE ` +
`creation_time=VALUES(creation_time), curr_version=VALUES(curr_version), min_compatible_version=VALUES(min_compatible_version)`

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

createSchemaVersionTableQuery = `CREATE TABLE schema_version(db_name VARCHAR(255) not null PRIMARY KEY, ` +
createSchemaVersionTableQuery = `CREATE TABLE schema_version(version_partition INT not null, ` +
`db_name VARCHAR(255) not null, ` +
`creation_time DATETIME(6), ` +
`curr_version VARCHAR(64), ` +
`min_compatible_version VARCHAR(64));`
`min_compatible_version VARCHAR(64), ` +
`PRIMARY KEY (version_partition, db_name));`

createSchemaUpdateHistoryTableQuery = `CREATE TABLE schema_update_history(` +
`version_partition INT not null, ` +
`year int not null, ` +
`month int not null, ` +
`update_time DATETIME(6) not null, ` +
`description VARCHAR(255), ` +
`manifest_md5 VARCHAR(64), ` +
`new_version VARCHAR(64), ` +
`old_version VARCHAR(64), ` +
`PRIMARY KEY (year, month, update_time));`
`PRIMARY KEY (version_partition, year, month, update_time));`

//NOTE we have to use %v because somehow mysql doesn't work with ? here
createDatabaseQuery = "CREATE database %v CHARACTER SET UTF8"
Expand Down
18 changes: 11 additions & 7 deletions common/persistence/sql/sqlplugin/postgres/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,34 @@ import (
)

const (
readSchemaVersionQuery = `SELECT curr_version from schema_version where db_name=$1`
readSchemaVersionQuery = `SELECT curr_version from schema_version where version_partition=0 and db_name=$1`

writeSchemaVersionQuery = `INSERT into schema_version(db_name, creation_time, curr_version, min_compatible_version) VALUES ($1,$2,$3,$4)
ON CONFLICT (db_name) DO UPDATE
writeSchemaVersionQuery = `INSERT into schema_version(version_partition, db_name, creation_time, curr_version, min_compatible_version) VALUES (0,$1,$2,$3,$4)
ON CONFLICT (version_partition, db_name) DO UPDATE
SET creation_time = excluded.creation_time,
curr_version = excluded.curr_version,
min_compatible_version = excluded.min_compatible_version;`

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)`
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)`

createSchemaVersionTableQuery = `CREATE TABLE schema_version(db_name VARCHAR(255) not null PRIMARY KEY, ` +
createSchemaVersionTableQuery = `CREATE TABLE schema_version(` +
`version_partition INT not null, ` +
`db_name VARCHAR(255) not null, ` +
`creation_time TIMESTAMP, ` +
`curr_version VARCHAR(64), ` +
`min_compatible_version VARCHAR(64));`
`min_compatible_version VARCHAR(64), `+
`PRIMARY KEY (version_partition, db_name));`

createSchemaUpdateHistoryTableQuery = `CREATE TABLE schema_update_history(` +
`version_partition INT not null, ` +
`year int not null, ` +
`month int not null, ` +
`update_time TIMESTAMP not null, ` +
`description VARCHAR(255), ` +
`manifest_md5 VARCHAR(64), ` +
`new_version VARCHAR(64), ` +
`old_version VARCHAR(64), ` +
`PRIMARY KEY (year, month, update_time));`
`PRIMARY KEY (version_partition, year, month, update_time));`

// NOTE we have to use %v because somehow postgres doesn't work with ? here
// It's a small bug in sqlx library
Expand Down