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

Missing Schema Prefix in DDL RENAME Statement #3006

Closed
mpyw opened this issue Jul 30, 2024 · 4 comments
Closed

Missing Schema Prefix in DDL RENAME Statement #3006

mpyw opened this issue Jul 30, 2024 · 4 comments

Comments

@mpyw
Copy link

mpyw commented Jul 30, 2024

Description

When using the Atlas HCL migration tool to rename an index from "a" to "b", the generated DDL statement for the RENAME operation lacks the schema name prefix. This causes a pq: relation not found error when working with schemas other than public in PostgreSQL.

Steps to Reproduce

  1. Create a schema other than public in PostgreSQL (e.g., custom_schema).
  2. Use Atlas HCL to define an index a in this custom schema.
  3. Use Atlas HCL to rename the index a to b.
  4. Observe the generated DDL statement for the RENAME operation.

Expected Behavior

The generated DDL statement should include the schema name prefix for the index being renamed. For example:

ALTER INDEX "custom_schema"."a" RENAME TO "b";

Actual Behavior

The generated DDL statement lacks the schema name prefix, resulting in an error:

ALTER INDEX "a" RENAME TO "b";
Error: pq: relation "a" not found

Environment

  • Atlas HCL Version: v0.24.1-6857ea8-canary
  • PostgreSQL Version: public.ecr.aws/docker/library/postgres:15.4

Additional Context

This issue appears when working with schemas other than public in PostgreSQL. The lack of a schema name prefix in the RENAME statement causes PostgreSQL to search for the index in the public schema, leading to a relation not found error if the index is in a different schema.

@a8m
Copy link
Member

a8m commented Jul 30, 2024

Hey @mpyw, what URL did you use? See: https://atlasgo.io/concepts/url#scope

Also, please upgrade to latest Atlas and check this.

@a8m
Copy link
Member

a8m commented Jul 30, 2024

From docs:

When the database URL is set to a specific schema (e.g., postgres://postgres:pass@host:port/db?search_path=public&sslmode=disable), the scope of the work done by Atlas (inspection, diffing, planning, applying, etc.) is limited to one schema. As a result, DDL statements printed during diffing or planning will be formatted without schema qualifiers and can be executed on any schema. e.g., table instead of schema.table

However, if the database URL does not specify a schema (i.e., without the search_path), Atlas operates on the selected schemas (defaulting to all), and the generated DDL statements include schema qualifiers. e.g., schema.table instead of table.

Closing, but feel free to reopen if you still need help with this.

@a8m a8m closed this as completed Jul 30, 2024
@mpyw
Copy link
Author

mpyw commented Jul 30, 2024

@a8m The database URL is postgresql://<USER>:<PW>@localhost:5432/<DBNAME>?sslmode=disable. And the most of other statements (execpt RENAME) qualify with the schema prefix. I believe this is the bug.

@mpyw
Copy link
Author

mpyw commented Jul 30, 2024

I'll reopen as a new issue.

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

No branches or pull requests

2 participants