Spaces:
Runtime error
Runtime error
Upload env.py
Browse files
env.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from logging.config import fileConfig
|
| 2 |
+
from sqlalchemy import engine_from_config
|
| 3 |
+
from sqlalchemy import pool
|
| 4 |
+
from alembic import context
|
| 5 |
+
import os
|
| 6 |
+
from database.models import Base
|
| 7 |
+
|
| 8 |
+
config = context.config
|
| 9 |
+
|
| 10 |
+
if config.config_file_name is not None:
|
| 11 |
+
fileConfig(config.config_file_name)
|
| 12 |
+
|
| 13 |
+
target_metadata = Base.metadata
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def run_migrations_offline() -> None:
|
| 17 |
+
sqlalchemy_url = os.getenv('DATABASE_URL', 'postgresql://user:password@localhost:5432/para_ai')
|
| 18 |
+
|
| 19 |
+
context.configure(
|
| 20 |
+
url=sqlalchemy_url,
|
| 21 |
+
target_metadata=target_metadata,
|
| 22 |
+
literal_binds=True,
|
| 23 |
+
dialect_opts={"paramstyle": "named"},
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
with context.begin_transaction():
|
| 27 |
+
context.run_migrations()
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def run_migrations_online() -> None:
|
| 31 |
+
configuration = config.get_section(config.config_ini_section)
|
| 32 |
+
configuration["sqlalchemy.url"] = os.getenv('DATABASE_URL', 'postgresql://user:password@localhost:5432/para_ai')
|
| 33 |
+
|
| 34 |
+
connectable = engine_from_config(
|
| 35 |
+
configuration,
|
| 36 |
+
prefix="sqlalchemy.",
|
| 37 |
+
poolclass=pool.NullPool,
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
with connectable.connect() as connection:
|
| 41 |
+
context.configure(
|
| 42 |
+
connection=connection, target_metadata=target_metadata
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
with context.begin_transaction():
|
| 46 |
+
context.run_migrations()
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
if context.is_offline_mode():
|
| 50 |
+
run_migrations_offline()
|
| 51 |
+
else:
|
| 52 |
+
run_migrations_online()
|