Initial commit: Базовая структура сайта

This commit is contained in:
2026-02-11 12:06:30 +05:00
parent b41f161e8f
commit d9a2ad7f15
62 changed files with 3901 additions and 0 deletions

79
backend/alembic/env.py Executable file
View File

@@ -0,0 +1,79 @@
from logging.config import fileConfig
from sqlalchemy import engine_from_config
from sqlalchemy import pool
from alembic import context
import os
import sys
# Добавляем путь к приложению
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
from app.core.database import Base, service_engine
from app.models.service_db import * # Импортируем все модели
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
if config.config_file_name is not None:
fileConfig(config.config_file_name)
# add your model's MetaData object here
# for 'autogenerate' support
target_metadata = Base.metadata
# other values from the config, defined by the Alembic env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.
def run_migrations_offline() -> None:
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
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:
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
connectable = service_engine
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()

25
backend/alembic/script.py.mako Executable file
View File

@@ -0,0 +1,25 @@
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}
# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
branch_labels = ${repr(branch_labels)}
depends_on = ${repr(depends_on)}
def upgrade() -> None:
${upgrades if upgrades else "pass"}
def downgrade() -> None:
${downgrades if downgrades else "pass"}

View File

@@ -0,0 +1,86 @@
"""Initial migration
Revision ID: 001
Revises:
Create Date: 2024-01-01 00:00:00.000000
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = '001'
down_revision = None
branch_labels = None
depends_on = None
def upgrade() -> None:
# Создание таблицы app_roles
op.create_table(
'app_roles',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('role_name', sa.String(length=50), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('role_name')
)
# Создание таблицы app_users
op.create_table(
'app_users',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('login', sa.String(length=100), nullable=False),
sa.Column('hashed_password', sa.String(length=255), nullable=False),
sa.Column('role_id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.Column('is_active', sa.Boolean(), nullable=True, server_default='true'),
sa.ForeignKeyConstraint(['role_id'], ['app_roles.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('login')
)
op.create_index(op.f('ix_app_users_id'), 'app_users', ['id'], unique=False)
op.create_index(op.f('ix_app_users_login'), 'app_users', ['login'], unique=True)
# Создание таблицы leave_events
op.create_table(
'leave_events',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('start_date', sa.Date(), nullable=False),
sa.Column('end_date', sa.Date(), nullable=False),
sa.Column('leave_type', sa.String(length=50), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.ForeignKeyConstraint(['user_id'], ['app_users.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_leave_events_id'), 'leave_events', ['id'], unique=False)
# Создание таблицы app_configuration
op.create_table(
'app_configuration',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('key', sa.String(length=100), nullable=False),
sa.Column('value', sa.String(length=500), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('key')
)
op.create_index(op.f('ix_app_configuration_id'), 'app_configuration', ['id'], unique=False)
op.create_index(op.f('ix_app_configuration_key'), 'app_configuration', ['key'], unique=True)
# Добавление начальных ролей
op.execute("INSERT INTO app_roles (role_name) VALUES ('Admin'), ('User')")
def downgrade() -> None:
op.drop_index(op.f('ix_app_configuration_key'), table_name='app_configuration')
op.drop_index(op.f('ix_app_configuration_id'), table_name='app_configuration')
op.drop_table('app_configuration')
op.drop_index(op.f('ix_leave_events_id'), table_name='leave_events')
op.drop_table('leave_events')
op.drop_index(op.f('ix_app_users_login'), table_name='app_users')
op.drop_index(op.f('ix_app_users_id'), table_name='app_users')
op.drop_table('app_users')
op.drop_table('app_roles')