How to manage schema migration for a single table in a large schema
Given a large database schema, how can I manage schema migration for a single table without affecting the rest of the schema?
Answer
Atlas supports the --include
flag (or the env.include
attribute) to scope operations to specific resources.
If you need to manage the lifecycle of a single table (or a set of tables), use this flag to avoid changes to the rest
of the schema.
For example, to manage the products
table in a MySQL database:
atlas schema apply \
--url "mysql://root:pass@:3308/db" \
--to "file://schema.sql" \
--dev-url "docker://mysql/8/dev" \
--include "products"
If the connection URL is not bound to a schema, specify the schema name in the pattern:
atlas schema apply \
--url "mysql://root:pass@:3308/" \
--to "file://schema.sql" \
--dev-url "docker://mysql/8" \
--include "db.products"
This command will only apply changes related to the products
table, leaving other tables untouched.
Wildcard Support
If the table exists in multiple schemas (tenants), you can use wildcards to include it across all schemas. For example:
atlas schema apply \
--url "mysql://root:pass@:3308/" \
--to "file://schema.sql" \
--dev-url "docker://mysql/8" \
--include "*.products"
Read more: