Atlas Provider SQLAlchemy
raw JSON → 0.5.0 verified Mon Apr 27 auth: no python
Load SQLAlchemy models into an Atlas project for schema migration inspection and planning. Compatible with SQLAlchemy 1.4+ and 2.0+. Currently at version 0.5.0, released monthly.
pip install atlas-provider-sqlalchemy Common errors
error TypeError: get_provider() missing 1 required positional argument: 'metadata' ↓
cause Calling get_provider(engine) instead of get_provider(metadata) after version 0.4.0.
fix
Use
get_provider(Base.metadata). error ModuleNotFoundError: No module named 'atlas_provider_sqlalchemy.dsl' ↓
cause Importing from a submodule that no longer exists in newer versions.
fix
Use
from atlas_provider_sqlalchemy import get_provider. error sqlalchemy.exc.InvalidRequestError: When initializing mapper Mapper|User|users, expression 'Column' is not a valid attribute name ↓
cause Forgot to import Column and Integer from sqlalchemy in the model file.
fix
Add
from sqlalchemy import Column, Integer, String to your model definitions. Warnings
breaking In version 0.4.0, the function signature changed from `get_provider(engine)` to `get_provider(metadata)`. Directly passing an engine will raise a TypeError. ↓
fix Use `get_provider(Base.metadata)` instead of `get_provider(engine)`.
gotcha The provider only reflects tables defined in the passed metadata object. If you have models imported but not associated with a common Base, they will be missing. ↓
fix Ensure all model classes inherit from the same declarative base instance.
gotcha Atlas expects a single HCL schema file. Multiple providers or multiple metadata objects are not supported. Merge all models into one metadata. ↓
fix Use `Base.metadata` that includes all model classes.
deprecated The `atlas-provider-sqlalchemy` package was previously named `ariga-atlas-provider-sqlalchemy`. The old package is deprecated and will not receive updates. ↓
fix Uninstall the old package and install `atlas-provider-sqlalchemy`.
Imports
- get_provider wrong
from atlas_provider_sqlalchemy.dsl import get_providercorrectfrom atlas_provider_sqlalchemy import get_provider
Quickstart
import os
from sqlalchemy import create_engine
from sqlalchemy.orm import declarative_base
from atlas_provider_sqlalchemy import get_provider
Base = declarative_base()
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
name = Column(String(50))
# Use a sample URL; in production, set via environment variable
engine = create_engine(os.environ.get('DATABASE_URL', 'sqlite:///:memory:'))
Base.metadata.create_all(engine)
provider = get_provider(Base.metadata)
print(provider.schema) # Prints the schema as HCL for Atlas