DDL Generation¶
DDL generation is implemented by AltibaseDDLCompiler and coordinated with dialect table events.
CREATE TABLE generation¶
get_column_specification() composes each column definition.
- Non-autoincrement columns:
- use
AltibaseTypeCompileroutput - include
DEFAULT ...when server default exists - include
NOT NULLwhen column is not nullable - Autoincrement integer primary key columns (without explicit server default):
- force type
INTEGER - generate
DEFAULT <table>_<column>_SEQ.NEXTVAL
Example generated shape:
Comments¶
The compiler supports table and column comments:
visit_set_table_commentvisit_drop_table_commentvisit_set_column_commentpost_create_table(inline extra statement after CREATE TABLE)
Rendered forms:
COMMENT ON TABLE users IS 'table comment'
COMMENT ON COLUMN users.id IS 'identifier'
COMMENT ON TABLE users IS ''
Implicit sequence lifecycle¶
Autoincrement sequence management is done by table event listeners in dialect.py:
before_create: create implicit sequenceafter_drop: drop implicit sequence (errors ignored)
mermaid
flowchart TD
A[MetaData.create_all] --> B[before_create listener]
B --> C[CREATE SEQUENCE table_col_SEQ]
C --> D[AltibaseDDLCompiler CREATE TABLE]
D --> E[column DEFAULT table_col_SEQ.NEXTVAL]
F[MetaData.drop_all] --> G[after_drop listener]
G --> H[DROP SEQUENCE table_col_SEQ]
Event-driven sequence creation
If DDL is generated and executed outside SQLAlchemy table events, you must create/drop sequences yourself.
Example¶
from sqlalchemy import Column, Integer, MetaData, String, Table, create_engine
engine = create_engine("altibase://sys:password@localhost:20300/mydb")
m = MetaData()
users = Table(
"users",
m,
Column("id", Integer, primary_key=True, autoincrement=True),
Column("name", String(100), nullable=False, comment="user name"),
comment="application users",
)
m.create_all(engine)
Alembic Migration Support¶
This dialect ships with an Alembic DDLImpl registered via alembic.ddl entry point. After installing
sqlalchemy-pyaltibase, Alembic migrations work automatically.
Key behavior: transactional_ddl = False — Altibase auto-commits DDL statements, so Alembic will not
wrap migrations in a transaction.
Install Alembic extra
pip install "sqlalchemy-pyaltibase[alembic]" to pull in Alembic as a dependency.