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

Postgres: inspect: for foreign key deferrable initially deferred #2367

Closed
alexisvisco opened this issue Dec 13, 2023 · 2 comments
Closed

Postgres: inspect: for foreign key deferrable initially deferred #2367

alexisvisco opened this issue Dec 13, 2023 · 2 comments

Comments

@alexisvisco
Copy link

alexisvisco commented Dec 13, 2023

Hello, seeing that a diff is generating this (using postgres)

ALTER TABLE "public"."order_items" ADD
 CONSTRAINT "fk_order_items_order_id" FOREIGN KEY ("order_id") REFERENCES "public"."orders" ("id") ON UPDATE NO ACTION ON DELETE NO ACTION;

While I have set this in the schema .sql :

constraint fk_order_items_order_id foreign key (order_id) references orders (id) deferrable initially deferred

I would like to contribute opening a PR :

Seems like this codes need to be impacted :

Could you give me some hint so that I can open a pull request ?

Thanks you :)

@C-Deck
Copy link

C-Deck commented Jun 13, 2024

This commit adds the inspect/diff pieces you may need. I'm not familiar with the tooling functionality that atlas does since I use this package like Ent does. If support in the tooling is needed to merge this, someone else will have to take over.

C-Deck pushed a commit to C-Deck/atlas that referenced this issue Jun 21, 2024
Adds an attribute for postgres to make a foreign key constraint deferrable and initially deferred.

Fixes ariga#2367
@a8m
Copy link
Member

a8m commented Sep 24, 2024

The issue was resolved with latest Atlas build, and it will be officially released in next version. You can define the deferrable attribute on the following blocks: foreign_key, primary_key, unique, and exclude. For example:

table "users" {
  // ...
  foreign_key "constraint_name" {
    columns     = [...]
    ref_columns = [...]
    deferrable  = INITIALLY_IMMEDIATE // Or: INITIALLY_DEFERRED
  }
}

See the HCL docs for more info: https://atlasgo.io/hcl/postgres#table.foreign_key-attributes

@a8m a8m closed this as completed Sep 24, 2024
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 a pull request may close this issue.

3 participants