1
0
mirror of https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git synced 2025-08-14 00:25:46 +02:00

фикс авторизации7

This commit is contained in:
MoonTestUse1
2025-01-03 22:54:26 +06:00
parent 2cfbf48004
commit e524612f80
2 changed files with 37 additions and 17 deletions

View File

@@ -1,32 +1,45 @@
from logging.config import fileConfig
import os
from sqlalchemy import engine_from_config
from sqlalchemy import pool
from alembic import context
import os
import sys
from pathlib import Path
# Add the parent directory to sys.path
sys.path.append(str(Path(__file__).resolve().parents[1]))
# Import your models
from app.models.employee import Employee
from app.models.request import Request
from app.database import Base
# this is the Alembic Config object
# 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
# 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
from app.models.base import Base
target_metadata = Base.metadata
# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.
def get_url():
return os.getenv("DATABASE_URL", "postgresql://postgres:postgres123@postgres:5432/support_db")
return os.getenv("DATABASE_URL")
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 = get_url()
context.configure(
url=url,
@@ -38,7 +51,14 @@ def run_migrations_offline() -> None:
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.
"""
configuration = config.get_section(config.config_ini_section)
configuration["sqlalchemy.url"] = get_url()
connectable = engine_from_config(
@@ -49,14 +69,13 @@ def run_migrations_online() -> None:
with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=target_metadata,
compare_type=True
connection=connection, target_metadata=target_metadata
)
with context.begin_transaction():
context.run_migrations()
if context.is_offline_mode():
run_migrations_offline()
else:

View File

@@ -11,6 +11,7 @@ echo "Database is ready!"
# Применяем миграции
echo "Applying database migrations..."
cd /app
export DATABASE_URL="postgresql://postgres:postgres123@db:5432/support_db"
alembic upgrade head
echo "Migrations completed!"