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: Comments on check doesn't work. If the check expression has AND, even if they are exactly the same, atlas still will delete and recreate the constraints #3242

Open
Huliiiiii opened this issue Dec 5, 2024 · 8 comments

Comments

@Huliiiiii
Copy link

Huliiiiii commented Dec 5, 2024

Atlas version: 0.29.0
Postgres version: 17

Example hcl:

schema "public" {
  comment = "standard public schema"
}

table "test_table" {
	schema = schema.public

	column "id" {
		type = int
	}
	primary_key {
		columns = [column.id]
	}

	column "value" {
		type = int
	}

	check "value_check" {
		comment = "This is a comment"
		expr = "value > 0 AND value < 1000"
	}
}

What I saw after running atlas schema apply:

Planning migration statements (1 in total):

  -- modify "test_table" table:
    -> ALTER TABLE "public"."test_table" DROP CONSTRAINT "value_check", ADD CONSTRAINT "value_check" CHECK (value > 0 AND value < 1000);
@a8m
Copy link
Member

a8m commented Dec 5, 2024

Hey! Do you use a dev-database in your commands? See: https://atlasgo.io/concepts/dev-database

@Huliiiiii
Copy link
Author

Huliiiiii commented Dec 5, 2024

Ok, this fix issue of check expression.
But comment still not work.

@Huliiiiii Huliiiiii reopened this Dec 5, 2024
@Huliiiiii
Copy link
Author

And if i change the name of the check, will still show the message: "Schema is synced, no changes to be made"

@Huliiiiii
Copy link
Author

I think some better info is needed here:
For example: ”If the dev database is not set, Atlas cannot validate the check constraints, which causes Atlas to drop and recreate them.“

@a8m
Copy link
Member

a8m commented Dec 5, 2024

What command do you use?

@Huliiiiii
Copy link
Author

atlas schema apply -u $env:DATABASE_URL --to=file://schema.pg.hcl --dev-url $env:DEV_DATABASE_URL

@Huliiiiii
Copy link
Author

Digging a little deeper, Atlas only detects changes if I change the check expression.

@a8m
Copy link
Member

a8m commented Dec 5, 2024

Yes, this was intentional some time ago (before the dev-database was added to Atlas). We will change this in the upcoming release.

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