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

Unable to take snapshot for schema having table "atlas_schema_revisions"? #17

Open
prasetyaputraa opened this issue Oct 9, 2023 · 1 comment

Comments

@prasetyaputraa
Copy link

Hi I have the following hcl configuration file:

data "external_schema" "gorm" {
  program = [
    "go",
    "run",
    "-mod=mod",
    "ariga.io/atlas-provider-gorm",
    "load",
    "--path", "./databases/pg/models",
    "--dialect", "postgres", // | mysql | sqlite
  ]
}

env "gorm" {
  src = data.external_schema.gorm.url
  dev = getenv("PG_CONNECTION_STRING_DB_USER")
  excludes = "atlas_schema_revisions"
  migration {
    dir = "file://migrations"
    format = golang-migrate
  }
  format {
    migrate {
      diff = "{{ sql . \"  \" }}"
    }
  }
}

after the first time I did migrate diff, added some IF EXISTS clauses to the generated .down.sql, and applied the migrations, I can't do the second migrate diff. It's resulting an error Error: sql/migrate: taking database snapshot: sql/migrate: connected database is not clean: found table "atlas_schema_revisions" in connected schema. What do I miss?

@rotemtam
Copy link
Member

rotemtam commented Oct 10, 2023

You need to use a clean database for your dev URL which atlas uses for normalization and various calculations.

Read more about dev databases here: https://atlasgo.io/concepts/dev-database

I recommend use docker://postgres/15/dev?search_path=public which will spin a docker container for you so you don't have to manage it. Also, no need to exclude the schema revision table in the gorm env block

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