Skip to content

Commit e906da7

Browse files
Strip schema from index names in internal schema representation (#278)
Remove the schema component from index names in the internal schema representation. A `pgroll` migration is always run in the context of a a specific schema so the extra qualification is redundant. Removing the schema component from the index names makes it easy to identify duplicated indexes by name when temporary columns and associated attributes are renamed on migration completion. Tests for this change are already in place (#276, #277). As of this PR, migration tests run in a non-public schema will pass: ```bash PGROLL_TEST_SCHEMA=foo go test ./... ``` Part of #273
1 parent 5686ddc commit e906da7

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pkg/state/state.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,14 @@ BEGIN
167167
AND indisprimary
168168
),
169169
'indexes', (
170-
SELECT COALESCE(json_object_agg(ix_details.indexrelid::regclass, json_build_object(
171-
'name', ix_details.indexrelid::regclass,
170+
SELECT COALESCE(json_object_agg(ix_details.name, json_build_object(
171+
'name', ix_details.name,
172172
'unique', ix_details.indisunique,
173173
'columns', ix_details.columns
174174
)), '{}'::json)
175175
FROM (
176176
SELECT
177-
pi.indexrelid,
177+
reverse(split_part(reverse(pi.indexrelid::regclass::text), '.', 1)) as name,
178178
pi.indisunique,
179179
array_agg(a.attname) AS columns
180180
FROM pg_index pi

0 commit comments

Comments
 (0)