Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test cases for functional indexes #146

Merged
merged 2 commits into from
Jul 18, 2024
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
29 changes: 27 additions & 2 deletions internal/migration_acceptance_tests/index_cases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,31 @@ var indexAcceptanceTestCases = []acceptanceTestCase{
diff.MigrationHazardTypeIndexBuild,
},
},
{
name: "Add a functional index",
oldSchemaDDL: []string{
`
CREATE SCHEMA schema_1;
CREATE TABLE schema_1.foobar(
id INT PRIMARY KEY,
foo VARCHAR(255)
);
`,
},
newSchemaDDL: []string{
`
CREATE SCHEMA schema_1;
CREATE TABLE schema_1.foobar(
id INT PRIMARY KEY,
foo VARCHAR(255)
);
CREATE INDEX some_idx ON schema_1.foobar(lower(foo));
`,
},
expectedHazardTypes: []diff.MigrationHazardType{
diff.MigrationHazardTypeIndexBuild,
},
},
{
name: "Add a unique index",
oldSchemaDDL: []string{
Expand Down Expand Up @@ -478,7 +503,7 @@ var indexAcceptanceTestCases = []acceptanceTestCase{
foo VARCHAR(255) NOT NULL
);
CREATE INDEX some_idx ON schema_1.foobar(id, foo);

CREATE SCHEMA schema_2;
CREATE TABLE schema_2.foobar(
id INT PRIMARY KEY,
Expand All @@ -493,7 +518,7 @@ var indexAcceptanceTestCases = []acceptanceTestCase{
id INT PRIMARY KEY,
foo VARCHAR(255) NOT NULL
);

CREATE SCHEMA schema_2;
CREATE TABLE schema_2.foobar(
id INT PRIMARY KEY,
Expand Down
64 changes: 49 additions & 15 deletions internal/migration_acceptance_tests/partitioned_index_cases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,40 @@ var partitionedIndexAcceptanceTestCases = []acceptanceTestCase{
diff.MigrationHazardTypeIndexBuild,
},
},
{
name: "Add a functional partitioned index",
oldSchemaDDL: []string{
`
CREATE SCHEMA schema_1;
CREATE TABLE schema_1.foobar(
id INT,
foo VARCHAR(255)
) PARTITION BY LIST (foo);
CREATE schema schema_2;
CREATE TABLE schema_2.foobar_1 PARTITION OF schema_1.foobar FOR VALUES IN ('foo_1');
CREATE TABLE schema_2.foobar_2 PARTITION OF schema_1.foobar FOR VALUES IN ('foo_2');
CREATE TABLE schema_2.foobar_3 PARTITION OF schema_1.foobar FOR VALUES IN ('foo_3');
`,
},
newSchemaDDL: []string{
`
CREATE SCHEMA schema_1;
CREATE TABLE schema_1.foobar(
id INT,
foo VARCHAR(255)
) PARTITION BY LIST (foo);
CREATE schema schema_2;
CREATE TABLE schema_2.foobar_1 PARTITION OF schema_1.foobar FOR VALUES IN ('foo_1');
CREATE TABLE schema_2.foobar_2 PARTITION OF schema_1.foobar FOR VALUES IN ('foo_2');
CREATE TABLE schema_2.foobar_3 PARTITION OF schema_1.foobar FOR VALUES IN ('foo_3');

CREATE INDEX some_idx ON schema_1.foobar(lower(foo));
`,
},
expectedHazardTypes: []diff.MigrationHazardType{
diff.MigrationHazardTypeIndexBuild,
},
},
{
name: "Add a primary key",
oldSchemaDDL: []string{
Expand Down Expand Up @@ -330,11 +364,11 @@ var partitionedIndexAcceptanceTestCases = []acceptanceTestCase{
CREATE TABLE schema_2.foobar(
id INT,
foo VARCHAR(255)
);
);
CREATE TABLE schema_2.foobar_1(
id INT,
foo VARCHAR(255)
);
);
`,
},
expectedHazardTypes: []diff.MigrationHazardType{
Expand Down Expand Up @@ -376,11 +410,11 @@ var partitionedIndexAcceptanceTestCases = []acceptanceTestCase{
CREATE TABLE schema_2.foobar(
id INT,
foo VARCHAR(255)
);
);
CREATE TABLE schema_2.foobar_1(
id INT,
foo VARCHAR(255)
);
);
`,
},
expectedHazardTypes: []diff.MigrationHazardType{
Expand Down Expand Up @@ -423,11 +457,11 @@ var partitionedIndexAcceptanceTestCases = []acceptanceTestCase{
CREATE TABLE schema_2.foobar(
id INT,
foo VARCHAR(255)
);
);
CREATE TABLE schema_2.foobar_1(
id INT,
foo VARCHAR(255)
);
);
`,
},
expectedHazardTypes: []diff.MigrationHazardType{
Expand Down Expand Up @@ -570,12 +604,12 @@ var partitionedIndexAcceptanceTestCases = []acceptanceTestCase{
bar INT,
foo VARCHAR(255)
) PARTITION BY LIST (foo);

CREATE TABLE foobar_1 PARTITION OF foobar FOR VALUES IN ('foo_1');

CREATE INDEX some_idx ON foobar(foo, id);
CREATE INDEX foobar_1_some_local_idx ON foobar_1(foo, bar, id);

-- Create a table in a different schema to ensure that dependencies are correctly set
CREATE schema schema_1;
CREATE TABLE schema_1.foobar(
Expand All @@ -590,7 +624,7 @@ var partitionedIndexAcceptanceTestCases = []acceptanceTestCase{
bar INT,
foo VARCHAR(255)
) PARTITION BY LIST (foo);

CREATE TABLE foobar_1 PARTITION OF foobar FOR VALUES IN ('foo_1');
`},
expectedHazardTypes: []diff.MigrationHazardType{
Expand All @@ -614,7 +648,7 @@ var partitionedIndexAcceptanceTestCases = []acceptanceTestCase{
bar INT,
foo VARCHAR(255)
) PARTITION BY LIST (foo);

CREATE TABLE foobar_1 PARTITION OF foobar FOR VALUES IN ('foo_1');
CREATE TABLE foobar_2 PARTITION OF foobar FOR VALUES IN ('foo_2');

Expand All @@ -629,7 +663,7 @@ var partitionedIndexAcceptanceTestCases = []acceptanceTestCase{
bar INT,
foo VARCHAR(255)
) PARTITION BY LIST (foo);

CREATE TABLE foobar_1 PARTITION OF foobar FOR VALUES IN ('foo_1');
CREATE TABLE foobar_2 PARTITION OF foobar FOR VALUES IN ('foo_2');

Expand Down Expand Up @@ -675,7 +709,7 @@ var partitionedIndexAcceptanceTestCases = []acceptanceTestCase{
bar INT,
foo VARCHAR(255)
) PARTITION BY LIST (foo);

CREATE TABLE foobar_1 PARTITION OF foobar FOR VALUES IN ('foo_1');
CREATE TABLE foobar_2 PARTITION OF foobar FOR VALUES IN ('foo_2');

Expand All @@ -691,7 +725,7 @@ var partitionedIndexAcceptanceTestCases = []acceptanceTestCase{
bar VARCHAR(255),
foo INT
) PARTITION BY LIST (foo);

CREATE TABLE schema_1.foobar_1 PARTITION OF schema_1.foobar FOR VALUES IN (1);
CREATE TABLE schema_1.foobar_2 PARTITION OF schema_1.foobar FOR VALUES IN (2);

Expand All @@ -706,7 +740,7 @@ var partitionedIndexAcceptanceTestCases = []acceptanceTestCase{
bar INT,
foo VARCHAR(255)
) PARTITION BY LIST (foo);

CREATE TABLE foobar_1 PARTITION OF foobar FOR VALUES IN ('foo_1');
CREATE TABLE foobar_2 PARTITION OF foobar FOR VALUES IN ('foo_2');

Expand All @@ -721,7 +755,7 @@ var partitionedIndexAcceptanceTestCases = []acceptanceTestCase{
bar VARCHAR(255),
foo INT
) PARTITION BY LIST (foo);

CREATE TABLE schema_1.foobar_1 PARTITION OF schema_1.foobar FOR VALUES IN (1);
CREATE TABLE schema_1.foobar_2 PARTITION OF schema_1.foobar FOR VALUES IN (2);

Expand Down
Loading