Settings working now. Everything working now.

Time for docker and beta test
This commit is contained in:
2020-05-30 23:39:02 +05:30
parent 95e92fc2bd
commit 013fce2e96
16 changed files with 73 additions and 214 deletions

View File

@ -1,22 +1,20 @@
import os
from logging.config import fileConfig
import logging
from sqlalchemy import engine_from_config
from sqlalchemy import create_engine
from sqlalchemy import pool
from alembic import context
from brewman.core.config import settings
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
logging.basicConfig()
logging.getLogger('sqlalchemy.engine').setLevel(settings.ALEMBIC_LOG_LEVEL)
logging.getLogger('alembic').setLevel(settings.ALEMBIC_LOG_LEVEL)
# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)
from brewman.models.auth import User # noqa
target_metadata = User.metadata
print(target_metadata)
# other values from the config, defined by the needs of env.py,
# can be acquired:
@ -24,14 +22,6 @@ print(target_metadata)
# ... etc.
def get_url():
user = os.getenv("POSTGRES_USER", "postgres")
password = os.getenv("POSTGRES_PASSWORD", "123456")
server = os.getenv("POSTGRES_SERVER", "localhost")
db = os.getenv("POSTGRES_DB", "hops")
return f"postgresql://{user}:{password}@{server}/{db}"
def run_migrations_offline():
"""Run migrations in 'offline' mode.
@ -44,7 +34,7 @@ def run_migrations_offline():
script output.
"""
url = get_url()
url = settings.SQLALCHEMY_DATABASE_URI
context.configure(
url=url,
target_metadata=target_metadata,
@ -64,13 +54,7 @@ def run_migrations_online():
and associate a connection with the context.
"""
configuration = config.get_section(config.config_ini_section)
configuration["sqlalchemy.url"] = get_url()
connectable = engine_from_config(
config.get_section(config.config_ini_section),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
connectable = create_engine(settings.SQLALCHEMY_DATABASE_URI, poolclass=pool.NullPool, )
with connectable.connect() as connection:
context.configure(

View File

@ -1,24 +0,0 @@
"""${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():
${upgrades if upgrades else "pass"}
def downgrade():
${downgrades if downgrades else "pass"}