Skip to content

Commit 4884f73

Browse files
authored
[BW-1398] Migrate PKs to BIGINT (#6907)
1 parent 664de52 commit 4884f73

File tree

11 files changed

+186
-9
lines changed

11 files changed

+186
-9
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Cromwell Change Log
22

3+
## 85 Release Notes
4+
5+
### Migration of PKs to BIGINT
6+
7+
The PK of below tables will be migrated from INT to BIGINT. Also, since `ROOT_WORKFLOW_ID` in `SUB_WORKFLOW_STORE_ENTRY` is a FK to `WORKFLOW_STORE_ENTRY_ID` in `WORKFLOW_STORE_ENTRY`
8+
it is also being migrated from INT to BIGINT.
9+
* DOCKER_HASH_STORE_ENTRY
10+
* WORKFLOW_STORE_ENTRY
11+
* SUB_WORKFLOW_STORE_ENTRY
12+
313
## 84 Release Notes
414

515
### CromIAM enabled user checks

database/migration/src/main/resources/changelog.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@
8787
<include file="changesets/enlarge_call_caching_detritus_entry_id.xml" relativeToChangelogFile="true" />
8888
<include file="changesets/enlarge_call_caching_simpleton_entry_id.xml" relativeToChangelogFile="true" />
8989
<include file="changesets/reset_call_caching_hash_entry_id_autoincrement.xml" relativeToChangelogFile="true" />
90+
<include file="changesets/enlarge_docker_hash_store_entry_id.xml" relativeToChangelogFile="true" />
91+
<include file="changesets/enlarge_workflow_store_entry_id.xml" relativeToChangelogFile="true" />
92+
<include file="changesets/enlarge_sub_workflow_store_entry_id.xml" relativeToChangelogFile="true" />
9093
<!-- REMINDER!
9194
Before appending here, did you remember to include the 'objectQuotingStrategy="QUOTE_ALL_OBJECTS"' line in your changeset/xyz.xml...?
9295
-->
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<databaseChangeLog objectQuotingStrategy="QUOTE_ALL_OBJECTS"
3+
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.3.xsd">
6+
7+
<!-- BEGIN DOCKER_HASH_STORE_ENTRY_ID PK widening -->
8+
<!-- For Postgresql there are 2 changesets: one for modifying the table column type, and another one for altering the autoincrementing sequence.
9+
The other DBs can be refactored similarly with a single addAutoIncrement changeset. -->
10+
<changeSet author="sshah" id="enlarge_docker_hash_store_entry_id" dbms="mysql,hsqldb,mariadb">
11+
<addAutoIncrement
12+
columnName="DOCKER_HASH_STORE_ENTRY_ID"
13+
columnDataType="BIGINT"
14+
incrementBy="1"
15+
tableName="DOCKER_HASH_STORE_ENTRY"
16+
/>
17+
</changeSet>
18+
19+
<changeSet author="sshah" id="postgresql_enlarge_docker_hash_store_entry_id" dbms="postgresql">
20+
<modifyDataType
21+
columnName="DOCKER_HASH_STORE_ENTRY_ID"
22+
tableName="DOCKER_HASH_STORE_ENTRY"
23+
newDataType="BIGINT"
24+
/>
25+
</changeSet>
26+
27+
<changeSet author="sshah" id="postgresql_enlarge_docker_hash_store_entry_id_seq" dbms="postgresql">
28+
<preConditions onFail="MARK_RAN">
29+
<!-- idempotency check (noop if the sequence is present and already consistent what the alter would do) -->
30+
<sqlCheck expectedResult="0">
31+
SELECT count(*)
32+
FROM information_schema.sequences
33+
WHERE sequence_name = 'DOCKER_HASH_STORE_ENTRY_DOCKER_HASH_STORE_ENTRY_ID_seq'
34+
AND data_type = 'bigint';
35+
</sqlCheck>
36+
</preConditions>
37+
<sql>alter sequence "DOCKER_HASH_STORE_ENTRY_DOCKER_HASH_STORE_ENTRY_ID_seq" as bigint;</sql>
38+
</changeSet>
39+
<!-- END DOCKER_HASH_STORE_ENTRY_ID PK widening -->
40+
41+
</databaseChangeLog>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<databaseChangeLog objectQuotingStrategy="QUOTE_ALL_OBJECTS"
3+
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.3.xsd">
6+
7+
<!-- BEGIN SUB_WORKFLOW_STORE_ENTRY_ID PK widening -->
8+
<!-- For Postgresql there are 2 changesets: one for modifying the table column type, and another one for altering the autoincrementing sequence.
9+
The other DBs can be refactored similarly with a single addAutoIncrement changeset. -->
10+
<changeSet author="sshah" id="enlarge_sub_workflow_store_entry_id" dbms="mysql,hsqldb,mariadb">
11+
<addAutoIncrement
12+
columnName="SUB_WORKFLOW_STORE_ENTRY_ID"
13+
columnDataType="BIGINT"
14+
incrementBy="1"
15+
tableName="SUB_WORKFLOW_STORE_ENTRY"
16+
/>
17+
</changeSet>
18+
19+
<changeSet author="sshah" id="postgresql_enlarge_sub_workflow_store_entry_id" dbms="postgresql">
20+
<modifyDataType
21+
columnName="SUB_WORKFLOW_STORE_ENTRY_ID"
22+
tableName="SUB_WORKFLOW_STORE_ENTRY"
23+
newDataType="BIGINT"
24+
/>
25+
</changeSet>
26+
27+
<changeSet author="sshah" id="postgresql_enlarge_sub_workflow_store_entry_id_seq" dbms="postgresql">
28+
<preConditions onFail="MARK_RAN">
29+
<!-- idempotency check (noop if the sequence is present and already consistent what the alter would do) -->
30+
<sqlCheck expectedResult="0">
31+
SELECT count(*)
32+
FROM information_schema.sequences
33+
WHERE sequence_name = 'SUB_WORKFLOW_STORE_ENTRY_SUB_WORKFLOW_STORE_ENTRY_ID_seq'
34+
AND data_type = 'bigint';
35+
</sqlCheck>
36+
</preConditions>
37+
<sql>alter sequence "SUB_WORKFLOW_STORE_ENTRY_SUB_WORKFLOW_STORE_ENTRY_ID_seq" as bigint;</sql>
38+
</changeSet>
39+
<!-- END SUB_WORKFLOW_STORE_ENTRY_ID PK widening -->
40+
41+
</databaseChangeLog>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<databaseChangeLog objectQuotingStrategy="QUOTE_ALL_OBJECTS"
3+
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.3.xsd">
6+
7+
<!-- Drop the foreign key constraint from SUB_WORKFLOW_STORE_ENTRY to WORKFLOW_STORE_ENTRY to allow for the latter's PK to be widened. -->
8+
<changeSet author="sshah" id="drop_sub_workflow_store_entry_root_workflow_id_fk" dbms="mysql,hsqldb,postgresql,mariadb">
9+
<dropForeignKeyConstraint
10+
baseTableName="SUB_WORKFLOW_STORE_ENTRY"
11+
constraintName="FK_SUB_WORKFLOW_STORE_ENTRY_ROOT_WORKFLOW_ID"
12+
/>
13+
</changeSet>
14+
15+
<!-- BEGIN WORKFLOW_STORE_ENTRY_ID PK widening -->
16+
<!-- For Postgresql there are 2 changesets: one for modifying the table column type, and another one for altering the autoincrementing sequence.
17+
The other DBs can be refactored similarly with a single addAutoIncrement changeset. -->
18+
<changeSet author="sshah" id="enlarge_workflow_store_entry_id" dbms="mysql,hsqldb,mariadb">
19+
<addAutoIncrement
20+
columnName="WORKFLOW_STORE_ENTRY_ID"
21+
columnDataType="BIGINT"
22+
incrementBy="1"
23+
tableName="WORKFLOW_STORE_ENTRY"
24+
/>
25+
</changeSet>
26+
27+
<changeSet author="sshah" id="postgresql_enlarge_workflow_store_entry_id" dbms="postgresql">
28+
<modifyDataType
29+
columnName="WORKFLOW_STORE_ENTRY_ID"
30+
tableName="WORKFLOW_STORE_ENTRY"
31+
newDataType="BIGINT"
32+
/>
33+
</changeSet>
34+
35+
<changeSet author="sshah" id="postgresql_enlarge_workflow_store_entry_id_seq" dbms="postgresql">
36+
<preConditions onFail="MARK_RAN">
37+
<!-- idempotency check (noop if the sequence is present and already consistent what the alter would do) -->
38+
<sqlCheck expectedResult="0">
39+
SELECT count(*)
40+
FROM information_schema.sequences
41+
WHERE sequence_name = 'WORKFLOW_STORE_ENTRY_WORKFLOW_STORE_ENTRY_ID_seq'
42+
AND data_type = 'bigint';
43+
</sqlCheck>
44+
</preConditions>
45+
<sql>alter sequence "WORKFLOW_STORE_ENTRY_WORKFLOW_STORE_ENTRY_ID_seq" as bigint;</sql>
46+
</changeSet>
47+
<!-- END WORKFLOW_STORE_ENTRY_ID PK widening -->
48+
49+
<!-- BEGIN widening FK to match PK -->
50+
<changeSet author="sshah" id="enlarge_sub_workflow_store_entry_fk" dbms="mysql,hsqldb,postgresql,mariadb">
51+
<modifyDataType
52+
tableName="SUB_WORKFLOW_STORE_ENTRY"
53+
columnName="ROOT_WORKFLOW_ID"
54+
newDataType="BIGINT"
55+
/>
56+
</changeSet>
57+
<!-- END widening FK to match PK -->
58+
59+
<!-- MariaDB's FK NotNull constraint does not survive the widening above and must be recreated explicitly. -->
60+
<!-- BEGIN Restoring FK NotNull constraint -->
61+
<changeSet author="sshah" id="mariadb_not_null_constraint_sub_workflow_store_entry_fk" dbms="mariadb,mysql">
62+
<addNotNullConstraint
63+
tableName="SUB_WORKFLOW_STORE_ENTRY"
64+
columnName="ROOT_WORKFLOW_ID"
65+
columnDataType="BIGINT"
66+
/>
67+
</changeSet>
68+
<!-- END Restoring FK NotNull constraint -->
69+
70+
<!-- Restoring the FK -->
71+
<changeSet author="sshah" id="recreate_sub_workflow_store_entry_root_workflow_id_fk" dbms="mysql,hsqldb,postgresql,mariadb">
72+
<addForeignKeyConstraint
73+
constraintName="FK_SUB_WORKFLOW_STORE_ENTRY_ROOT_WORKFLOW_ID"
74+
baseColumnNames="ROOT_WORKFLOW_ID"
75+
baseTableName="SUB_WORKFLOW_STORE_ENTRY"
76+
referencedTableName="WORKFLOW_STORE_ENTRY"
77+
referencedColumnNames="WORKFLOW_STORE_ENTRY_ID"
78+
onDelete="CASCADE"
79+
/>
80+
</changeSet>
81+
82+
</databaseChangeLog>

database/sql/src/main/scala/cromwell/database/slick/tables/DockerHashStoreEntryComponent.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ trait DockerHashStoreEntryComponent {
99
import driver.api._
1010

1111
class DockerHashStoreEntries(tag: Tag) extends Table[DockerHashStoreEntry](tag, "DOCKER_HASH_STORE_ENTRY") {
12-
def dockerHashStoreEntryId = column[Int]("DOCKER_HASH_STORE_ENTRY_ID", O.PrimaryKey, O.AutoInc)
12+
def dockerHashStoreEntryId = column[Long]("DOCKER_HASH_STORE_ENTRY_ID", O.PrimaryKey, O.AutoInc)
1313

1414
def workflowExecutionUuid = column[String]("WORKFLOW_EXECUTION_UUID", O.Length(255))
1515

database/sql/src/main/scala/cromwell/database/slick/tables/SubWorkflowStoreEntryComponent.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ trait SubWorkflowStoreEntryComponent {
1010
import driver.api._
1111

1212
class SubWorkflowStoreEntries(tag: Tag) extends Table[SubWorkflowStoreEntry](tag, "SUB_WORKFLOW_STORE_ENTRY") {
13-
def subWorkflowStoreEntryId = column[Int]("SUB_WORKFLOW_STORE_ENTRY_ID", O.PrimaryKey, O.AutoInc)
13+
def subWorkflowStoreEntryId = column[Long]("SUB_WORKFLOW_STORE_ENTRY_ID", O.PrimaryKey, O.AutoInc)
1414

15-
def rootWorkflowId = column[Int]("ROOT_WORKFLOW_ID")
15+
def rootWorkflowId = column[Long]("ROOT_WORKFLOW_ID")
1616

1717
def parentWorkflowExecutionUuid = column[String]("PARENT_WORKFLOW_EXECUTION_UUID", O.Length(255))
1818

@@ -40,7 +40,7 @@ trait SubWorkflowStoreEntryComponent {
4040
val subWorkflowStoreEntryIdsAutoInc = subWorkflowStoreEntries returning subWorkflowStoreEntries.map(_.subWorkflowStoreEntryId)
4141

4242
val subWorkflowStoreEntriesForRootWorkflowId = Compiled(
43-
(rootWorkflowId: Rep[Int]) => for {
43+
(rootWorkflowId: Rep[Long]) => for {
4444
subWorkflowStoreEntry <- subWorkflowStoreEntries
4545
if subWorkflowStoreEntry.rootWorkflowId === rootWorkflowId
4646
} yield subWorkflowStoreEntry

database/sql/src/main/scala/cromwell/database/slick/tables/WorkflowStoreEntryComponent.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ trait WorkflowStoreEntryComponent {
1111
import driver.api._
1212

1313
class WorkflowStoreEntries(tag: Tag) extends Table[WorkflowStoreEntry](tag, "WORKFLOW_STORE_ENTRY") {
14-
def workflowStoreEntryId = column[Int]("WORKFLOW_STORE_ENTRY_ID", O.PrimaryKey, O.AutoInc)
14+
def workflowStoreEntryId = column[Long]("WORKFLOW_STORE_ENTRY_ID", O.PrimaryKey, O.AutoInc)
1515

1616
def workflowExecutionUuid = column[String]("WORKFLOW_EXECUTION_UUID", O.Length(255))
1717

database/sql/src/main/scala/cromwell/database/sql/tables/DockerHashStoreEntry.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ case class DockerHashStoreEntry
66
dockerTag: String,
77
dockerHash: String,
88
dockerSize: Option[Long],
9-
dockerHashStoreEntryId: Option[Int] = None
9+
dockerHashStoreEntryId: Option[Long] = None
1010
)

database/sql/src/main/scala/cromwell/database/sql/tables/SubWorkflowStoreEntry.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package cromwell.database.sql.tables
22

33
case class SubWorkflowStoreEntry
44
(
5-
rootWorkflowId: Option[Int],
5+
rootWorkflowId: Option[Long],
66
parentWorkflowExecutionUuid: String,
77
callFullyQualifiedName: String,
88
callIndex: Int,
99
callAttempt: Int,
1010
subWorkflowExecutionUuid: String,
11-
subWorkflowStoreEntryId: Option[Int] = None
11+
subWorkflowStoreEntryId: Option[Long] = None
1212
)

0 commit comments

Comments
 (0)