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

globalid is not supported by this command. Use 'migrate diff' instead #3307

Open
advdv opened this issue Jan 14, 2025 · 4 comments
Open

globalid is not supported by this command. Use 'migrate diff' instead #3307

advdv opened this issue Jan 14, 2025 · 4 comments
Assignees

Comments

@advdv
Copy link

advdv commented Jan 14, 2025

I have a pretty elaborate setup with a composite schema. The relevant parts of my atlas.hcl look like this:

# The tables and relations are defined in Ent. But other postgres items are defined separately
# in SQL and combines in a composite schema.
data "composite_schema" "main" {
  schema {
    url = "file://schema/domains.sql"
  }
  schema {
    url = "file://schema/functions.sql"
  }

  schema {
    url = "ent://schema?globalid=1"
  }

  schema {
    url = "file://schema/policies.sql"
  }
}

# for our migrations to succeed the dev database also needs to include our two user groups. Atlas doesn't
# support this right now we we do it by hand. This mimicks what is recommendd for PostgREST.
docker "postgres" "dev" {
  image    = "postgres:17.2-alpine"
  baseline = file("baseline.sql")
}

# We allow the migrations to have template variables.
data "template_dir" "main" {
  path = "migrations"
  vars = {}
}

# the local env is used for local development and testing.
env "local" {
  src = data.composite_schema.main.url
  dev = docker.postgres.dev.url
  url = "postgresql://postgres:postgres@localhost:5444/postgres?sslmode=disable"
  migration {
    dir = data.template_dir.main.url
  }
}

But when i then run the diff command, like so: atlas migrate diff initial --env=local It gives me the following error:

Error: data.composite_schema.main: globalid is not supported by this command. Use 'migrate diff' instead

This seems to be a design decision but i don't really understand why, and I can't find documentation about it. Also the instructions to solve it are weird because i'm running the migrate diff command.

It works without the ?globalid=1 part, but i'm trying to generate globally unique id columns.

@a8m
Copy link
Member

a8m commented Jan 14, 2025

Hey @advdv,

The reason you are facing this issue is that the ent_types table (and its state) is managed by Ent. @masseelch is actively working on refactoring this implementation and migrating this logic to Atlas (e.g., see ent/ent#4293 from yesterday). I expect this change to be completed in the coming days.

@advdv
Copy link
Author

advdv commented Jan 14, 2025

Wow, great timing. Thank you, eagerly looking for forward!

@masseelch
Copy link
Member

@advdv I have not created the docs for this yet, but here is a small example of how to use the new ent schema loader:

data "external_schema" "trigger" {
  program = [
    "go", "run","-mod=mod", "entgo.io/ent/cmd/ent@master",
    "schema", "./ent/schema",
    "--dialect", "mysql",
    "--version", "8",
    "--feature", "sql/globalid"
  ]
}

data "composite_schema" "ent" {
  schema "dev" {
    url = data.external_schema.trigger.url
  }
  schema "dev" {
    url = "file://trigger.sql"
  }
}

env "local" {
  url = data.composite_schema.ent.url
  dev = "docker://mysql/8/dev"
}

Note, that in order for the unique global id to work, you need to enable the feature in ent (it is called sql/globalid).

I will have the docs done end of today or tomorrow.

@advdv
Copy link
Author

advdv commented Jan 20, 2025

@masseelch Very cool. I actually started experimenting with it already since i saw the commit ;). We dump the ent schema in sql as part of go generate but nice to know this can also be triggered from Atlas.

The only thing that didn't work is the multi-schema setup with annoations as described here: https://entgo.io/docs/multischema-migrations. I adde the schema annotations but the dump didn't use them. All of our Ent sql is in the same schema so this didn't matter but maybe it is something you are not aware of.

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

3 participants