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

fix: get length attribute of postgres array columns #7239

Merged
merged 1 commit into from
Jan 4, 2021

Conversation

edcolvin
Copy link
Contributor

@edcolvin edcolvin commented Jan 2, 2021

Description of change

Fixes #6990.

PostgresQueryRunner method loadTables is used to determine if the database is in sync with the entity definitions. This change updates how loadTables determines the length value of array columns. It uses the postgres-specific pg_catalog.pg_attribute table and the pg_catalog.format_type function to find the data type name, which includes the length for types that have a length attribute. Previously, loadTables relied solely on character_maximum_length in information_schema.columns, which is null for array columns. Because of this, array columns with a length attribute were always dropped.

This also includes a test that confirms the issues is resolved by this fix.

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • npm run lint passes with this change
  • npm run test passes with this change
  • This pull request links relevant issues as Fixes #0000
  • There are new or updated unit tests validating the change
  • Documentation has been updated to reflect this change N/A
  • The new commits follow conventions explained in [CONTRIBUTING.md]

Change loadTables in PostgresQueryRunner to use pg_catalog to find length attribute of array columns. Previously, it relied on information_schema.columns character_maximum_length, which is null for array columns. This caused synchronize to always drop and recreate array columns.

Closes: typeorm#6990
@pleerock
Copy link
Member

pleerock commented Jan 4, 2021

Thank you for the contribution!

It's super hard for me to review this kind of PRs because it's not possible to predict how these changes will actually work. Let's merge it and keep watching if it won't arise new issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Postgres array column dropped and re-added during synchronization when no change is made.
2 participants