generated from coulomb/repo-seed
Start Core Hub FastAPI replacement foundation
This commit is contained in:
44
migrations/env.py
Normal file
44
migrations/env.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from logging.config import fileConfig
|
||||
|
||||
from alembic import context
|
||||
from sqlalchemy import engine_from_config, pool
|
||||
|
||||
from core_hub import models # noqa: F401
|
||||
from core_hub.config import get_settings
|
||||
from core_hub.db import Base
|
||||
|
||||
config = context.config
|
||||
|
||||
if config.config_file_name is not None:
|
||||
fileConfig(config.config_file_name)
|
||||
|
||||
config.set_main_option("sqlalchemy.url", get_settings().database_url.replace("+asyncpg", ""))
|
||||
target_metadata = Base.metadata
|
||||
|
||||
|
||||
def run_migrations_offline() -> None:
|
||||
url = config.get_main_option("sqlalchemy.url")
|
||||
context.configure(url=url, target_metadata=target_metadata, literal_binds=True)
|
||||
|
||||
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()
|
||||
65
migrations/versions/20260627_0001_initial_core_hub.py
Normal file
65
migrations/versions/20260627_0001_initial_core_hub.py
Normal file
@@ -0,0 +1,65 @@
|
||||
"""initial core hub tables
|
||||
|
||||
Revision ID: 20260627_0001
|
||||
Revises:
|
||||
Create Date: 2026-06-27
|
||||
"""
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "20260627_0001"
|
||||
down_revision: str | None = None
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"hubs",
|
||||
sa.Column("id", sa.String(length=36), primary_key=True),
|
||||
sa.Column("slug", sa.String(length=120), nullable=False),
|
||||
sa.Column("name", sa.String(length=240), nullable=False),
|
||||
sa.Column("status", sa.String(length=40), nullable=False),
|
||||
sa.Column("description", sa.Text(), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
|
||||
)
|
||||
op.create_index("ix_hubs_slug", "hubs", ["slug"], unique=True)
|
||||
|
||||
op.create_table(
|
||||
"hub_capability_manifests",
|
||||
sa.Column("id", sa.String(length=36), primary_key=True),
|
||||
sa.Column("hub_slug", sa.String(length=120), nullable=False),
|
||||
sa.Column("manifest_version", sa.String(length=40), nullable=False),
|
||||
sa.Column("body_json", sa.Text(), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
|
||||
)
|
||||
op.create_index(
|
||||
"ix_hub_capability_manifests_hub_slug",
|
||||
"hub_capability_manifests",
|
||||
["hub_slug"],
|
||||
)
|
||||
|
||||
op.create_table(
|
||||
"api_consumers",
|
||||
sa.Column("id", sa.String(length=36), primary_key=True),
|
||||
sa.Column("slug", sa.String(length=120), nullable=False),
|
||||
sa.Column("name", sa.String(length=240), nullable=False),
|
||||
sa.Column("key_prefix", sa.String(length=32), nullable=True),
|
||||
sa.Column("key_hash", sa.String(length=255), nullable=True),
|
||||
sa.Column("status", sa.String(length=40), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
|
||||
)
|
||||
op.create_index("ix_api_consumers_slug", "api_consumers", ["slug"], unique=True)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index("ix_api_consumers_slug", table_name="api_consumers")
|
||||
op.drop_table("api_consumers")
|
||||
op.drop_index("ix_hub_capability_manifests_hub_slug", table_name="hub_capability_manifests")
|
||||
op.drop_table("hub_capability_manifests")
|
||||
op.drop_index("ix_hubs_slug", table_name="hubs")
|
||||
op.drop_table("hubs")
|
||||
Reference in New Issue
Block a user