init commit
This commit is contained in:
39
services/bot/alembic/env.py
Normal file
39
services/bot/alembic/env.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from __future__ import annotations
|
||||
import os
|
||||
from logging.config import fileConfig
|
||||
from sqlalchemy import engine_from_config, pool
|
||||
from alembic import context
|
||||
|
||||
config = context.config
|
||||
# Подменяем URL из переменных окружения контейнера
|
||||
if os.getenv("DATABASE_URL"):
|
||||
config.set_main_option("sqlalchemy.url", os.getenv("DATABASE_URL"))
|
||||
|
||||
fileConfig(config.config_file_name)
|
||||
|
||||
# Метаданные моделей
|
||||
from app.models.base import Base # noqa: E402
|
||||
target_metadata = Base.metadata
|
||||
|
||||
def run_migrations_offline():
|
||||
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():
|
||||
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()
|
||||
59
services/bot/alembic/versions/0001_init.py
Normal file
59
services/bot/alembic/versions/0001_init.py
Normal file
@@ -0,0 +1,59 @@
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
revision = '0001_init'
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
def upgrade():
|
||||
op.create_table(
|
||||
'admins',
|
||||
sa.Column('id', sa.Integer(), primary_key=True, autoincrement=True),
|
||||
sa.Column('telegram_id', sa.Integer(), unique=True, index=True),
|
||||
sa.Column('full_name', sa.String(length=120), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=False, server_default=sa.text('CURRENT_TIMESTAMP')),
|
||||
)
|
||||
|
||||
op.create_table(
|
||||
'candidates',
|
||||
sa.Column('id', sa.Integer(), primary_key=True, autoincrement=True),
|
||||
sa.Column('telegram_id', sa.Integer(), unique=True, index=True),
|
||||
sa.Column('username', sa.String(length=100), nullable=True),
|
||||
sa.Column('full_name', sa.String(length=120), nullable=True),
|
||||
sa.Column('gender', sa.String(length=20), nullable=True),
|
||||
sa.Column('birth_date', sa.Date(), nullable=True),
|
||||
sa.Column('height_cm', sa.Float(), nullable=True),
|
||||
sa.Column('weight_kg', sa.Float(), nullable=True),
|
||||
sa.Column('country', sa.String(length=80), nullable=True),
|
||||
sa.Column('city', sa.String(length=120), nullable=True),
|
||||
sa.Column('citizenship', sa.String(length=80), nullable=True),
|
||||
sa.Column('visa_status', sa.String(length=60), nullable=True),
|
||||
sa.Column('languages', sa.String(length=200), nullable=True),
|
||||
sa.Column('education', sa.String(length=120), nullable=True),
|
||||
sa.Column('occupation', sa.String(length=120), nullable=True),
|
||||
sa.Column('income_range', sa.String(length=60), nullable=True),
|
||||
sa.Column('religion', sa.String(length=80), nullable=True),
|
||||
sa.Column('marital_status', sa.String(length=60), nullable=True),
|
||||
sa.Column('has_children', sa.Boolean(), nullable=True),
|
||||
sa.Column('children_notes', sa.String(length=200), nullable=True),
|
||||
sa.Column('smoking', sa.String(length=20), nullable=True),
|
||||
sa.Column('alcohol', sa.String(length=20), nullable=True),
|
||||
sa.Column('health_notes', sa.String(length=300), nullable=True),
|
||||
sa.Column('hobbies_tags', sa.String(length=300), nullable=True),
|
||||
sa.Column('hobbies_free', sa.Text(), nullable=True),
|
||||
sa.Column('goal', sa.String(length=120), nullable=True),
|
||||
sa.Column('partner_prefs', sa.Text(), nullable=True),
|
||||
sa.Column('avatar_file_id', sa.String(length=200), nullable=True),
|
||||
sa.Column('gallery_file_ids', sa.Text(), nullable=True),
|
||||
sa.Column('consent_personal', sa.Boolean(), nullable=False, server_default=sa.text('0')),
|
||||
sa.Column('consent_policy', sa.Boolean(), nullable=False, server_default=sa.text('0')),
|
||||
sa.Column('is_verified', sa.Boolean(), nullable=False, server_default=sa.text('0')),
|
||||
sa.Column('is_active', sa.Boolean(), nullable=False, server_default=sa.text('1')),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=False, server_default=sa.text('CURRENT_TIMESTAMP')),
|
||||
sa.Column('updated_at', sa.DateTime(), nullable=False, server_default=sa.text('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP')),
|
||||
)
|
||||
|
||||
def downgrade():
|
||||
op.drop_table('candidates')
|
||||
op.drop_table('admins')
|
||||
Reference in New Issue
Block a user