Skip to content

Commit

Permalink
Cleanup DB schema (#1130)
Browse files Browse the repository at this point in the history
  • Loading branch information
wxing1292 authored Jan 28, 2021
1 parent b69cf76 commit 532b318
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 45 deletions.
20 changes: 3 additions & 17 deletions common/persistence/sql/sqlplugin/mysql/cluster_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ const constMetadataPartition = 0
const constMembershipPartition = 0
const (
// ****** CLUSTER_METADATA TABLE ******
insertClusterMetadataQryOld = `INSERT INTO cluster_metadata (metadata_partition, data, data_encoding, immutable_data, immutable_data_encoding, version) VALUES(?, ?, ?, ?, ?, ?)`
insertClusterMetadataQry = `INSERT INTO cluster_metadata (metadata_partition, data, data_encoding, version) VALUES(?, ?, ?, ?)`
insertClusterMetadataQry = `INSERT INTO cluster_metadata (metadata_partition, data, data_encoding, version) VALUES(?, ?, ?, ?)`

updateClusterMetadataQry = `UPDATE cluster_metadata SET data = ?, data_encoding = ?, version = ? WHERE metadata_partition = ?`

Expand Down Expand Up @@ -79,26 +78,13 @@ func (mdb *db) SaveClusterMetadata(
row *sqlplugin.ClusterMetadataRow,
) (sql.Result, error) {
if row.Version == 0 {
result, err := mdb.conn.ExecContext(ctx,
insertClusterMetadataQryOld,
return mdb.conn.ExecContext(ctx,
insertClusterMetadataQry,
constMetadataPartition,
row.Data,
row.DataEncoding,
[]byte{}, // TODO beginning 1.6.x, remove this line
"", // TODO beginning 1.6.x, remove this line
1,
)
if err != nil {
// in case schema is upgraded
result, err = mdb.conn.ExecContext(ctx,
insertClusterMetadataQry,
constMetadataPartition,
row.Data,
row.DataEncoding,
1,
)
}
return result, err
}
return mdb.conn.ExecContext(ctx,
updateClusterMetadataQry,
Expand Down
20 changes: 3 additions & 17 deletions common/persistence/sql/sqlplugin/postgresql/cluster_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ const constMetadataPartition = 0
const constMembershipPartition = 0
const (
// ****** CLUSTER_METADATA TABLE ******
insertClusterMetadataQryOld = `INSERT INTO cluster_metadata (metadata_partition, data, data_encoding, immutable_data, immutable_data_encoding, version) VALUES($1, $2, $3, $4, $5, $6)`
insertClusterMetadataQry = `INSERT INTO cluster_metadata (metadata_partition, data, data_encoding, version) VALUES($1, $2, $3, $4)`
insertClusterMetadataQry = `INSERT INTO cluster_metadata (metadata_partition, data, data_encoding, version) VALUES($1, $2, $3, $4)`

updateClusterMetadataQry = `UPDATE cluster_metadata SET data = $1, data_encoding = $2, version = $3 WHERE metadata_partition = $4`

Expand Down Expand Up @@ -83,26 +82,13 @@ func (pdb *db) SaveClusterMetadata(
row *sqlplugin.ClusterMetadataRow,
) (sql.Result, error) {
if row.Version == 0 {
result, err := pdb.conn.ExecContext(ctx,
insertClusterMetadataQryOld,
return pdb.conn.ExecContext(ctx,
insertClusterMetadataQry,
constMetadataPartition,
row.Data,
row.DataEncoding,
[]byte{}, // TODO beginning 1.6.x, remove this line
"", // TODO beginning 1.6.x, remove this line
1,
)
if err != nil {
// in case schema is upgraded
result, err = pdb.conn.ExecContext(ctx,
insertClusterMetadataQry,
constMetadataPartition,
row.Data,
row.DataEncoding,
1,
)
}
return result, err
}
return pdb.conn.ExecContext(ctx,
updateClusterMetadataQry,
Expand Down
4 changes: 0 additions & 4 deletions schema/cassandra/temporal/schema.cql
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ CREATE TABLE executions (
signal_map_encoding text,
signal_requested set<uuid>,
buffered_events_list list<frozen<serialized_event_batch>>,
replication_metadata blob, -- Contains versions for replicationState
replication_metadata_encoding text,
workflow_last_write_version bigint,
workflow_state int,
checksum blob,
Expand Down Expand Up @@ -140,8 +138,6 @@ CREATE TABLE cluster_metadata (
metadata_partition int,
data blob,
data_encoding text,
immutable_data blob,
immutable_data_encoding text,
version bigint,
PRIMARY KEY (metadata_partition)
) WITH COMPACTION = {
Expand Down
2 changes: 2 additions & 0 deletions schema/cassandra/temporal/versioned/v1.4/cluster_metadata.cql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE cluster_metadata DROP immutable_data;
ALTER TABLE cluster_metadata DROP immutable_data_encoding;
2 changes: 2 additions & 0 deletions schema/cassandra/temporal/versioned/v1.4/executions.cql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE executions DROP replication_metadata;
ALTER TABLE executions DROP replication_metadata_encoding;
9 changes: 9 additions & 0 deletions schema/cassandra/temporal/versioned/v1.4/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"CurrVersion": "1.4",
"MinCompatibleVersion": "1.0",
"Description": "schema update for cluster metadata cleanup",
"SchemaUpdateCqlFiles": [
"executions.cql",
"cluster_metadata.cql"
]
}
2 changes: 1 addition & 1 deletion schema/cassandra/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ package cassandra
// NOTE: whenever there is a new data base schema update, plz update the following versions

// Version is the Cassandra database release version
const Version = "1.3"
const Version = "1.4"

// VisibilityVersion is the Cassandra visibility database release version
const VisibilityVersion = "1.0"
2 changes: 0 additions & 2 deletions schema/mysql/v57/temporal/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,6 @@ CREATE TABLE cluster_metadata (
metadata_partition INT NOT NULL,
data MEDIUMBLOB NOT NULL,
data_encoding VARCHAR(16) NOT NULL,
immutable_data MEDIUMBLOB NOT NULL,
immutable_data_encoding VARCHAR(16) NOT NULL,
version BIGINT NOT NULL,
PRIMARY KEY(metadata_partition)
);
Expand Down
2 changes: 2 additions & 0 deletions schema/mysql/v57/temporal/versioned/v1.4/cluster_metadata.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE cluster_metadata DROP immutable_data;
ALTER TABLE cluster_metadata DROP immutable_data_encoding;
8 changes: 8 additions & 0 deletions schema/mysql/v57/temporal/versioned/v1.4/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"CurrVersion": "1.4",
"MinCompatibleVersion": "1.0",
"Description": "schema update for cluster metadata cleanup",
"SchemaUpdateCqlFiles": [
"cluster_metadata.sql"
]
}
2 changes: 1 addition & 1 deletion schema/mysql/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ package mysql
// NOTE: whenever there is a new data base schema update, plz update the following versions

// Version is the MySQL database release version
const Version = "1.3"
const Version = "1.4"

// VisibilityVersion is the MySQL visibility database release version
const VisibilityVersion = "1.1"
2 changes: 0 additions & 2 deletions schema/postgresql/v96/temporal/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,6 @@ CREATE TABLE cluster_metadata (
metadata_partition INTEGER NOT NULL,
data BYTEA NOT NULL,
data_encoding VARCHAR(16) NOT NULL,
immutable_data BYTEA NOT NULL,
immutable_data_encoding VARCHAR(16) NOT NULL,
version BIGINT NOT NULL,
PRIMARY KEY(metadata_partition)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE cluster_metadata DROP immutable_data;
ALTER TABLE cluster_metadata DROP immutable_data_encoding;
8 changes: 8 additions & 0 deletions schema/postgresql/v96/temporal/versioned/v1.4/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"CurrVersion": "1.4",
"MinCompatibleVersion": "1.0",
"Description": "schema update for cluster metadata cleanup",
"SchemaUpdateCqlFiles": [
"cluster_metadata.sql"
]
}
2 changes: 1 addition & 1 deletion schema/postgresql/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ package postgresql

// Version is the Postgres database release version
// Temporal supports both MySQL and Postgres officially, so upgrade should be perform for both MySQL and Postgres
const Version = "1.3"
const Version = "1.4"

// VisibilityVersion is the Postgres visibility database release version
// Temporal supports both MySQL and Postgres officially, so upgrade should be perform for both MySQL and Postgres
Expand Down

0 comments on commit 532b318

Please sign in to comment.