ariga / atlas

Manage your database schema as code
https://atlasgo.io
Apache License 2.0
6.01k stars 268 forks source link

CockroachDB support for `migrate diff` and `dev-url` #2453

Open saurori opened 10 months ago

saurori commented 10 months ago

I'm using atlas with ent and CockroachDB. It's been working fine so far using a postgis image as --dev-url when generating migrations like such:

atlas migrate diff $(name) \
    --dir "file://ent/migrate/migrations" \
    --to "ent://ent/schema" \
    --dev-url "docker://postgis/postgis/15-3.4/app?search_path=public"

However, I need to use a feature that is only supported by CRDB: Row-Level TTL.

I generated a custom migration that looks like:

ALTER TABLE my_table SET (ttl_expiration_expression = 'expires_at');

This obviously can't be handled by postgres, and as far as I can tell docker://cockroachdb/cockroach isn't supported in --dev-url. I attempted to set up and run a local image to generate the diff like so:

atlas migrate diff $(name) \
        --dir "file://ent/migrate/migrations" \
        --to "ent://ent/schema" \
        --dev-url "postgres://dev@127.0.0.1:26257/app?search_path=public&sslmode=disable"

However, when running the above I hit an error (the database is clean to start with and then all existing schema is loaded before erroring):

Error: sql/migrate: taking database snapshot: sql/migrate: connected database is not clean: found table "my_table" in connected schema

Versions

$ atlas version
atlas version v0.18.1-0068cdd-canary
https://github.com/ariga/atlas/releases/latest
Server version: CockroachDB CCL v23.1.13 (aarch64-unknown-linux-gnu, built 2023/12/01 22:21:24, go1.19.13) (same version as client)
LuizWeitz commented 2 weeks ago

Hi, you have new update? I have a some problem. I used this Solution you need use --dev-url "docker://postgres/[VERSION POSTGRESQL]/dev?search_path=public", please check this https://atlasgo.io/concepts/dev-database