Skip to content

Commit cb28ae1

Browse files
committed
Refactor database schemas and update related tests
- Refactor database schema by renaming `t1_2` to `col_1` across multiple tables. - Update foreign key constraints to ensure integrity with the new column name. - Adjust test cases to verify the correctness of the updated SQL statements. Signed-off-by: katsumata <12413150+winor30@users.noreply.github.com>
1 parent 4bca6aa commit cb28ae1

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

internal/hammer/diff_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ CREATE TABLE t2 (
10451045
from: `
10461046
CREATE TABLE t1 (
10471047
t1_1 INT64 NOT NULL,
1048-
t1_2 INT64,
1048+
col_1 INT64,
10491049
) PRIMARY KEY(t1_1);
10501050
10511051
CREATE TABLE t2 (
@@ -1054,8 +1054,8 @@ CREATE TABLE t2 (
10541054
10551055
CREATE TABLE t3 (
10561056
t3_1 INT64 NOT NULL,
1057-
t1_2 INT64,
1058-
CONSTRAINT FK_t3 FOREIGN KEY (t1_2) REFERENCES t2 (t2_1),
1057+
col_1 INT64,
1058+
CONSTRAINT FK_t3 FOREIGN KEY (col_1) REFERENCES t2 (t2_1),
10591059
) PRIMARY KEY(t3_1);
10601060
`,
10611061
to: `
@@ -1069,30 +1069,30 @@ CREATE TABLE t2 (
10691069
10701070
CREATE TABLE t3 (
10711071
t3_1 INT64 NOT NULL,
1072-
t1_2 INT64,
1073-
CONSTRAINT FK_t3 FOREIGN KEY (t1_2) REFERENCES t2 (t2_1),
1072+
col_1 INT64,
1073+
CONSTRAINT FK_t3 FOREIGN KEY (col_1) REFERENCES t2 (t2_1),
10741074
) PRIMARY KEY(t3_1);
10751075
`,
10761076
expected: []string{
1077-
`ALTER TABLE t1 DROP COLUMN t1_2`,
1077+
`ALTER TABLE t1 DROP COLUMN col_1`,
10781078
},
10791079
},
10801080
{
10811081
name: "Do not drop unrelated constraint (same referenced column name)",
10821082
from: `
10831083
CREATE TABLE t1 (
10841084
t1_1 INT64 NOT NULL,
1085-
t1_2 INT64,
1085+
col_1 INT64,
10861086
) PRIMARY KEY(t1_1);
10871087
10881088
CREATE TABLE t2 (
1089-
t1_2 INT64 NOT NULL,
1090-
) PRIMARY KEY(t1_2);
1089+
col_1 INT64 NOT NULL,
1090+
) PRIMARY KEY(col_1);
10911091
10921092
CREATE TABLE t3 (
10931093
t3_1 INT64 NOT NULL,
1094-
t1_2 INT64,
1095-
CONSTRAINT FK_t3 FOREIGN KEY (t1_2) REFERENCES t2 (t1_2),
1094+
t3_2 INT64,
1095+
CONSTRAINT FK_t3 FOREIGN KEY (t3_2) REFERENCES t2 (col_1),
10961096
) PRIMARY KEY(t3_1);
10971097
`,
10981098
to: `
@@ -1101,17 +1101,17 @@ CREATE TABLE t1 (
11011101
) PRIMARY KEY(t1_1);
11021102
11031103
CREATE TABLE t2 (
1104-
t1_2 INT64 NOT NULL,
1105-
) PRIMARY KEY(t1_2);
1104+
col_1 INT64 NOT NULL,
1105+
) PRIMARY KEY(col_1);
11061106
11071107
CREATE TABLE t3 (
11081108
t3_1 INT64 NOT NULL,
1109-
t1_2 INT64,
1110-
CONSTRAINT FK_t3 FOREIGN KEY (t1_2) REFERENCES t2 (t1_2),
1109+
t3_2 INT64,
1110+
CONSTRAINT FK_t3 FOREIGN KEY (t3_2) REFERENCES t2 (col_1),
11111111
) PRIMARY KEY(t3_1);
11121112
`,
11131113
expected: []string{
1114-
`ALTER TABLE t1 DROP COLUMN t1_2`,
1114+
`ALTER TABLE t1 DROP COLUMN col_1`,
11151115
},
11161116
},
11171117
{

0 commit comments

Comments
 (0)