diff --git a/amanuensis/database.py b/amanuensis/database.py index af00d45..b49bbaa 100644 --- a/amanuensis/database.py +++ b/amanuensis/database.py @@ -1,4 +1,4 @@ -from sqlalchemy import create_engine +from sqlalchemy import create_engine, MetaData from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import scoped_session from sqlalchemy.orm import sessionmaker @@ -6,8 +6,17 @@ from sqlalchemy.orm import sessionmaker engine = create_engine('sqlite:///:memory:') +# Define naming conventions for generated constraints +metadata = MetaData(bind=engine, naming_convention={ + "ix": "ix_%(column_0_label)s", + "uq": "uq_%(table_name)s_%(column_0_name)s", + "ck": "ck_%(table_name)s_%(constraint_name)s", + "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s", + "pk": "pk_%(table_name)s" +}) + # Thread-safe db session session = scoped_session(sessionmaker(bind=engine)) # Base class for ORM models -ModelBase = declarative_base(engine) +ModelBase = declarative_base(metadata=metadata)