Load sqlalchemy models into an Atlas project.
Maintained. Last release 4 weeks ago, commits in 2 of the last 26 weeks. Weaker on commit activity.
pip install atlas-provider-sqlalchemyatlas-provider-sqlalchemy
Use Atlas with SQLAlchemy to manage your database schema as code. By connecting your SQLAlchemy models to Atlas, you can define and edit your schema directly in Python, and Atlas will automatically plan and apply database schema migrations for you, eliminating the need to write migrations manually.
Atlas brings automated CI/CD workflows to your database, along with built-in support for testing, linting, schema drift detection, and schema monitoring. It also allows you to extend SQLAlchemy with advanced database objects such as triggers, row-level security, and custom functions that are not supported natively.
Use-cases
- Declarative migrations - Use the Terraform-like
atlas schema apply --env sqlalchemycommand to apply your SQLAlchemy schema to the database. - Automatic migration planning - Use
atlas migrate diff --env sqlalchemyto automatically plan database schema changes and generate a migration from the current database version to the desired version defined by your SQLAlchemy schema.
Installation
Install Atlas from macOS or Linux by running:
curl -sSf https://atlasgo.sh | sh
See atlasgo.io for more installation options.
Install the provider by running:
# The Provider works by importing your SQLAlchemy models and extracting the schema from them.
# Therefore, you will need to run the provider from within your project's Python environment.
pip install atlas-provider-sqlalchemy
Standalone
If all of your SQLAlchemy models exist in a single package, you can use the provider directly to load your SQLAlchemy schema into Atlas.
In your project directory, create a new file named atlas.hcl with the following contents:
data "external_schema" "sqlalchemy" {
program = [
"atlas-provider-sqlalchemy",
"--path", "./path/to/models",
"--dialect", "mysql" // mariadb | postgresql | sqlite | mssql
]
}
env "sqlalchemy" {
src = data.external_schema.sqlalchemy.url
dev = "docker://mysql/8/dev"
migration {
dir = "file://migrations"
}
format {
migrate {
diff = "{{ sql . \" \" }}"
}
}
}