Create Relay Bot MVP
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from alembic import context
|
||||
from sqlalchemy.ext.asyncio import async_engine_from_config
|
||||
from sqlalchemy.pool import NullPool
|
||||
|
||||
from app.database.models import Base
|
||||
|
||||
config = context.config
|
||||
target_metadata = Base.metadata
|
||||
database_url = os.environ.get("DATABASE_URL", config.get_main_option("sqlalchemy.url"))
|
||||
config.set_main_option("sqlalchemy.url", database_url)
|
||||
|
||||
|
||||
def run_migrations_offline() -> None:
|
||||
context.configure(
|
||||
url=config.get_main_option("sqlalchemy.url"),
|
||||
target_metadata=target_metadata,
|
||||
literal_binds=True,
|
||||
)
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
def do_run_migrations(connection) -> None:
|
||||
context.configure(connection=connection, target_metadata=target_metadata)
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
async def run_migrations_online() -> None:
|
||||
connectable = async_engine_from_config(
|
||||
config.get_section(config.config_ini_section, {}),
|
||||
prefix="sqlalchemy.",
|
||||
poolclass=NullPool,
|
||||
)
|
||||
async with connectable.connect() as connection:
|
||||
await connection.run_sync(do_run_migrations)
|
||||
await connectable.dispose()
|
||||
|
||||
|
||||
if context.is_offline_mode():
|
||||
run_migrations_offline()
|
||||
else:
|
||||
asyncio.run(run_migrations_online())
|
||||
@@ -0,0 +1,14 @@
|
||||
"""${message}"""
|
||||
revision = ${repr(up_revision)}
|
||||
down_revision = ${repr(down_revision)}
|
||||
branch_labels = ${repr(branch_labels)}
|
||||
depends_on = ${repr(depends_on)}
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
def upgrade():
|
||||
${upgrades if upgrades else "pass"}
|
||||
|
||||
def downgrade():
|
||||
${downgrades if downgrades else "pass"}
|
||||
@@ -0,0 +1,24 @@
|
||||
"""initial schema"""
|
||||
|
||||
from alembic import op
|
||||
|
||||
from app.database.models import Base
|
||||
|
||||
revision = "0001_initial"
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
bind = op.get_bind()
|
||||
Base.metadata.create_all(
|
||||
bind,
|
||||
tables=[
|
||||
table for table in Base.metadata.sorted_tables if table.name != "repository_bindings"
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
Base.metadata.drop_all(op.get_bind())
|
||||
@@ -0,0 +1,33 @@
|
||||
"""chat scoped repository bindings"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = "0002_repository_bindings"
|
||||
down_revision = "0001_initial"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"repository_bindings",
|
||||
sa.Column("id", sa.Integer(), primary_key=True),
|
||||
sa.Column("chat_id", sa.BigInteger(), nullable=False),
|
||||
sa.Column("thread_id", sa.BigInteger(), nullable=True),
|
||||
sa.Column("url", sa.String(length=2000), nullable=False),
|
||||
sa.Column("branch", sa.String(length=255), nullable=False, server_default="HEAD"),
|
||||
sa.Column("cache_path", sa.String(length=2000), nullable=False, unique=True),
|
||||
sa.Column("commit", sa.String(length=64), nullable=False),
|
||||
sa.Column("attached_by", sa.BigInteger(), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
|
||||
sa.Column("synced_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
|
||||
)
|
||||
op.create_index("ix_repository_bindings_chat_id", "repository_bindings", ["chat_id"])
|
||||
op.create_index("ix_repository_bindings_thread_id", "repository_bindings", ["thread_id"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index("ix_repository_bindings_thread_id", table_name="repository_bindings")
|
||||
op.drop_index("ix_repository_bindings_chat_id", table_name="repository_bindings")
|
||||
op.drop_table("repository_bindings")
|
||||
Reference in New Issue
Block a user