Implement BaseModel class, TimestampMixin, TzDateTime type; cleanup Task model

This commit is contained in:
Lexi / Zoe 2022-04-15 21:45:10 +02:00
parent 7ce43a2bfe
commit 252c15acbd
Signed by: binaryDiv
GPG key ID: F8D4956E224DA232
15 changed files with 223 additions and 42 deletions

View file

@ -26,16 +26,22 @@ def process_revision_directives(_context, _revision, directives):
directives[:] = []
context_parameters = {
'target_metadata': BaseModel.metadata,
'process_revision_directives': process_revision_directives,
'user_module_prefix': 'tofu_types.',
}
def run_migrations_offline():
"""
Run migrations in 'offline' mode, which does not require an actual database engine and can be used to generate SQL scripts.
"""
context.configure(
url=app.config.sqlalchemy_database_uri,
target_metadata=BaseModel.metadata,
process_revision_directives=process_revision_directives,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
**context_parameters,
)
with context.begin_transaction():
@ -49,8 +55,7 @@ def run_migrations_online():
with db.engine.connect() as connection:
context.configure(
connection=connection,
target_metadata=BaseModel.metadata,
process_revision_directives=process_revision_directives,
**context_parameters,
)
with context.begin_transaction():

View file

@ -8,6 +8,8 @@ Create Date: ${create_date}
from alembic import op
import sqlalchemy as sa
import tofu_api.common.database.types as tofu_types
${imports if imports else ""}
# Revision identifiers, used by Alembic.

View file

@ -1,16 +1,18 @@
"""
Initial revision
Revision ID: 716726b4a1fe
Revision ID: 044f3afd19b0
Revises:
Create Date: 2022-04-15 16:05:29.358429+02:00
Create Date: 2022-04-15 21:41:39.962542+02:00
"""
from alembic import op
import sqlalchemy as sa
import tofu_api.common.database.types as tofu_types
# Revision identifiers, used by Alembic.
revision = '716726b4a1fe'
revision = '044f3afd19b0'
down_revision = None
branch_labels = None
depends_on = None
@ -19,16 +21,18 @@ depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
'tasks',
'task',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', tofu_types.TzDateTime(), server_default=sa.text('now()'), nullable=False),
sa.Column('modified_at', tofu_types.TzDateTime(), server_default=sa.text('now()'), nullable=False),
sa.Column('title', sa.String(length=255), nullable=False),
sa.Column('description', sa.Text(), nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('pk_tasks'))
sa.PrimaryKeyConstraint('id', name=op.f('pk_task'))
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('tasks')
op.drop_table('task')
# ### end Alembic commands ###