-
I've been looking for the doc for days to study atlas features. And there are quite a lot. But, because of that, I'm a little bit confused about what should I do with this. I'm trying to establish versioned migration with atlas. We already have existing database, and we also have SQL script to initialize which can generate same schema as existing database. And, It seems even when I use versioned migration (https://atlasgo.io/versioned/diff), So, these are my concerns, 1. With existing databaseFirst of all, when we start from an existing database, how can I generate a "declarative schema" from this? But, how can we generate the declarative schema hcl file? Is there any method to generate a schema ddl file (HCL) from the migration directory? OR, should I use So, this is what I thought for the initial setup of atlas migration with an existing database.
But, in this case, 2 seem to be missing. 2. Who is responsible for generating the migration script?Because doc mentioned about When I make a change on DDL file, who is responsible for generating the corresponding migration script?
It seems 1, but in that case, if the developer accidentally misses the migration script for that, we need to compare ddl and migration directory to check the migration directory is properly set. But, when I see this section (https://atlasgo.io/declarative/diff), the only impossible comparison is between migration directory vs. ddl schema. So, this is what I thought for the sequence of migration handling,
But I'm not sure this is the right direction when I use atlas. 3. How can we synchronize declarative schema with manual migration script?I saw this section (https://atlasgo.io/versioned/new), and it seems So, what I thought was,
but yes, I can't find a function to generate ddl schema from migration directory. 4. Difference between
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
Hey @wangmir Thanks for the great questions! I'll try to answer them this evening. |
Beta Was this translation helpful? Give feedback.
-
The best way is to use
As this is a one time operation, I think both are good options.
At our company, the developer is responsible for generating migrations as part of the PR for the change their making. atlas migrate diff check \
--dir "file://${{ inputs.migration-dir }}" \
--to "ent://${{ inputs.ent-schema }}" \
--dev-url "${{ inputs.dev-database }}"
status=$(git status --porcelain)
if [ -n "$status" ]; then
echo "missing migrations."
echo "you need to run 'atlas migrate diff' and commit the changes"
echo "$status"
git --no-pager diff
exit 1
fi
there is no automatic way of updating your desired state based on new scripts in the migration dir - the process is designed to work the other way around. however, this can be easily achieved by spinning up an empty database container, running notice that manual migrations are mostly useful for features not yet supported by Atlas (e.g views, data migrations etc).
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the detailed answer!! Now I feel I understand atlas much more evident. |
Beta Was this translation helpful? Give feedback.
-
So, because I need to use |
Beta Was this translation helpful? Give feedback.
-
And it seems, But, in case of https://gh.atlasgo.cloud/explore there are multiple syntax error around that with PostgreSQL script. (e.g. OWNER) |
Beta Was this translation helpful? Give feedback.
The best way is to use
atlas schema inspect -u <URL>
to get the HCL representation.If you prefer using a UI for this, you can use https://gh.atlasgo.cloud/explore:
As this is a one time operation, I think both are good options.
Btw, you can also use an SQL file as the desired state of your database, if you prefer.
At our company, the develop…