Skip to content

Commit

Permalink
Strip schema from index names in internal schema representation (#278)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
andrew-farries committed Feb 7, 2024
1 parent 5686ddc commit e906da7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,14 @@ BEGIN
AND indisprimary
),
'indexes', (
SELECT COALESCE(json_object_agg(ix_details.indexrelid::regclass, json_build_object(
'name', ix_details.indexrelid::regclass,
SELECT COALESCE(json_object_agg(ix_details.name, json_build_object(
'name', ix_details.name,
'unique', ix_details.indisunique,
'columns', ix_details.columns
)), '{}'::json)
FROM (
SELECT
pi.indexrelid,
reverse(split_part(reverse(pi.indexrelid::regclass::text), '.', 1)) as name,
pi.indisunique,
array_agg(a.attname) AS columns
FROM pg_index pi
Expand Down

0 comments on commit e906da7

Please sign in to comment.