Initial import
This commit is contained in:
37
migrations/env.py
Normal file
37
migrations/env.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from logging.config import fileConfig
|
||||
from sqlalchemy import engine_from_config
|
||||
from sqlalchemy import pool
|
||||
from alembic import context
|
||||
|
||||
config = context.config
|
||||
if config.config_file_name is not None:
|
||||
fileConfig(config.config_file_name, disable_existing_loggers=False)
|
||||
|
||||
target_metadata = None
|
||||
|
||||
def run_migrations_offline() -> None:
|
||||
url = config.get_main_option("sqlalchemy.url")
|
||||
context.configure(
|
||||
url=url,
|
||||
target_metadata=target_metadata,
|
||||
literal_binds=True,
|
||||
dialect_opts={"paramstyle": "named"},
|
||||
)
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
def run_migrations_online() -> None:
|
||||
connectable = engine_from_config(
|
||||
config.get_section(config.config_ini_section, {}),
|
||||
prefix="sqlalchemy.",
|
||||
poolclass=pool.NullPool,
|
||||
)
|
||||
with connectable.connect() as connection:
|
||||
context.configure(connection=connection, target_metadata=target_metadata)
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
if context.is_offline_mode():
|
||||
run_migrations_offline()
|
||||
else:
|
||||
run_migrations_online()
|
||||
28
migrations/script.py.mako
Normal file
28
migrations/script.py.mako
Normal file
@@ -0,0 +1,28 @@
|
||||
"""${message}
|
||||
|
||||
Revision ID: ${up_revision}
|
||||
Revises: ${down_revision | comma,n}
|
||||
Create Date: ${create_date}
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
${imports if imports else ""}
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = ${repr(up_revision)}
|
||||
down_revision: Union[str, Sequence[str], None] = ${repr(down_revision)}
|
||||
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
|
||||
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
${upgrades if upgrades else "pass"}
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
${downgrades if downgrades else "pass"}
|
||||
63
migrations/versions/20260405181328_initial_.py
Normal file
63
migrations/versions/20260405181328_initial_.py
Normal file
@@ -0,0 +1,63 @@
|
||||
"""initial version
|
||||
|
||||
Revision ID: 4ee21f978e6c
|
||||
Revises:
|
||||
Create Date: 2026-04-05 18:13:28.735859
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import ForeignKeyConstraint
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '4ee21f978e6c'
|
||||
down_revision: Union[str, Sequence[str], None] = None
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"counters",
|
||||
sa.Column('id', sa.Integer, primary_key=True, autoincrement=True),
|
||||
sa.Column('name', sa.String(20), nullable=False, unique=True),
|
||||
sa.Column('type', sa.Integer(), nullable=False, server_default=sa.text("1")),
|
||||
sa.Column('color', sa.String(6), nullable=False)
|
||||
)
|
||||
|
||||
op.create_table(
|
||||
"entries",
|
||||
sa.Column('id', sa.Integer, primary_key=True, autoincrement=True),
|
||||
sa.Column('timestamp', sa.DateTime, nullable=False, server_default=sa.func.now()),
|
||||
sa.Column('counter_id', sa.Integer, nullable=False,),
|
||||
sa.Column('increment', sa.Integer, nullable=False, server_default=sa.text("1")),
|
||||
ForeignKeyConstraint(["counter_id"], ["counters.id"], onupdate="CASCADE", ondelete="CASCADE")
|
||||
)
|
||||
|
||||
table = op.create_table(
|
||||
"color_palettes",
|
||||
sa.Column('id', sa.Integer, primary_key=True, autoincrement=True),
|
||||
sa.Column('color1', sa.String(6), nullable=False),
|
||||
sa.Column('color2', sa.String(6), nullable=False),
|
||||
sa.Column('color3', sa.String(6), nullable=False),
|
||||
sa.Column('color4', sa.String(6), nullable=False),
|
||||
sa.Column('color5', sa.String(6), nullable=False),
|
||||
)
|
||||
|
||||
op.bulk_insert(table, [
|
||||
{"color1": "F2F3AE", "color2": "EDD382", "color3": "FC9E4F", "color4": "FF521B", "color5": "020122"},
|
||||
{"color1": "2B4141", "color2": "0EB1D2", "color3": "34E4EA", "color4": "8AB9B5", "color5": "C8C2AE"},
|
||||
{"color1": "181F1C", "color2": "274029", "color3": "315C2B", "color4": "60712F", "color5": "9EA93F"},
|
||||
{"color1": "A3A380", "color2": "D6CE93", "color3": "EFEBCE", "color4": "D8A48F", "color5": "BB8588"},
|
||||
{"color1": "32292F", "color2": "99E1D9", "color3": "F0F7F4", "color4": "70ABAF", "color5": "705D56"}
|
||||
])
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_table("color_palettes")
|
||||
op.drop_table("entries")
|
||||
op.drop_table("counters")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user