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

tables with same name and different schemas breaks migration generator logic #193

Closed
sezaru opened this issue Jan 13, 2024 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@sezaru
Copy link
Contributor

sezaru commented Jan 13, 2024

Describe the bug
In my system, I have two schemas, public and raw. And inside both schemas, I have a table called records.

They have the same name, but they are very different tables

Seems like the resource_snapshots store both tables json file in the same resources directory and that seems to create some conflicts.

For example, I first added the raw.records table and created a migration for it, then, I created the public.records table and its migration.

Now I'm adding an index to the raw.records table, but when I run mix ash_postgres.generate_migrations, Ash will try to recreate the full raw.records table:

create table(:records, primary_key: false, prefix: "raw") do
...
end

To Reproduce
Create two resources (A and B) with the same table name but with distinct schemas.
First generate a migration for the resource A, then to B.
Now try to create an index for the A resource and try to generate a migration for that change.
AshPostgres will add the A resource table creation to the migration file.

Expected behavior
AshPostgres should not be confused by resources that share the same name but distinct schemas.

** Runtime

  • Elixir version 1.16.0
  • Erlang version 26.2.1
  • OS Fedora Silverblue 39
  • Ash version 2.17
  • any related extension versions AshPostgres main
@sezaru sezaru added bug Something isn't working needs review labels Jan 13, 2024
@zachdaniel
Copy link
Contributor

The solution here is to include the prefix in the file name when there is a statically configured prefix on the resource. I will address this early next week, but if anyone wants to take a stab at it before then they are more than welcome. The fix will be in the file name determination logic in migration_generator.ex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants