From f1cc12bd91de835aa65dcdd8c50df7acd1c0a4c0 Mon Sep 17 00:00:00 2001 From: Ellen Date: Sat, 6 Feb 2021 16:28:04 +0200 Subject: [PATCH 1/9] feat: add alembic configuration --- alembic.ini | 86 ++++++++++++++++++++ alembic/README | 14 ++++ alembic/env.py | 81 ++++++++++++++++++ alembic/script.py.mako | 24 ++++++ alembic/versions/91b42971b0df_.py | 131 ++++++++++++++++++++++++++++++ 5 files changed, 336 insertions(+) create mode 100644 alembic.ini create mode 100644 alembic/README create mode 100644 alembic/env.py create mode 100644 alembic/script.py.mako create mode 100644 alembic/versions/91b42971b0df_.py diff --git a/alembic.ini b/alembic.ini new file mode 100644 index 00000000..85744540 --- /dev/null +++ b/alembic.ini @@ -0,0 +1,86 @@ +# A generic, single database configuration. + +[alembic] +# path to migration scripts +# script_location = alembic +script_location = alembic + +# template used to generate migration files +# file_template = %%(rev)s_%%(slug)s + +# timezone to use when rendering the date +# within the migration file as well as the filename. +# string value is passed to dateutil.tz.gettz() +# leave blank for localtime +# timezone = + +# max length of characters to apply to the +# "slug" field +# truncate_slug_length = 40 + +# set to 'true' to run the environment during +# the 'revision' command, regardless of autogenerate +# revision_environment = false + +# set to 'true' to allow .pyc and .pyo files without +# a source .py file to be detected as revisions in the +# versions/ directory +# sourceless = false + +# version location specification; this defaults +# to alembic/versions. When using multiple version +# directories, initial revisions must be specified with --version-path +# version_locations = %(here)s/bar %(here)s/bat alembic/versions + +# the output encoding used when revision files +# are written from script.py.mako +# output_encoding = utf-8 + +sqlalchemy.url = driver://user:pass@localhost/dbname + + +[post_write_hooks] +# post_write_hooks defines scripts or Python functions that are run +# on newly generated revision scripts. See the documentation for further +# detail and examples + +# format using "black" - use the console_scripts runner, against the "black" entrypoint +# hooks=black +# black.type=console_scripts +# black.entrypoint=black +# black.options=-l 79 + +# Logging configuration +[loggers] +keys = root,sqlalchemy,alembic + +[handlers] +keys = console + +[formatters] +keys = generic + +[logger_root] +level = WARN +handlers = console +qualname = + +[logger_sqlalchemy] +level = WARN +handlers = +qualname = sqlalchemy.engine + +[logger_alembic] +level = INFO +handlers = +qualname = alembic + +[handler_console] +class = StreamHandler +args = (sys.stderr,) +level = NOTSET +formatter = generic + +[formatter_generic] +format = %(levelname)-5.5s [%(name)s] %(message)s +datefmt = %H:%M:%S diff --git a/alembic/README b/alembic/README new file mode 100644 index 00000000..7239903d --- /dev/null +++ b/alembic/README @@ -0,0 +1,14 @@ +Generic single-database configuration. + +# following command will run all migration script and bring it to latest version +alembic upgrade head + +# If we like to incrementally upgrade and check for some errors +alembic upgrade +1 + +# To undo last migration +alembic downgrade -1 + +# To get more information +alembic current +alembic history - verbose \ No newline at end of file diff --git a/alembic/env.py b/alembic/env.py new file mode 100644 index 00000000..4eb1da7d --- /dev/null +++ b/alembic/env.py @@ -0,0 +1,81 @@ +from app.database.database import Base +# from app.database.models import * # This helps alembic autogeneration + +from logging.config import fileConfig + +from sqlalchemy import create_engine + +from alembic import context +import os +from app import config as app_config + + +SQLALCHEMY_DATABASE_URL = os.getenv( + "DATABASE_CONNECTION_STRING", app_config.DEVELOPMENT_DATABASE_STRING) + +# 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. +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 needs of env.py, +# can be acquired: +# my_important_option = config.get_main_option("my_important_option") +# ... etc. + + +def run_migrations_offline(): + """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 = SQLALCHEMY_DATABASE_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(): + """Run migrations in 'online' mode. + + In this scenario we need to create an Engine + and associate a connection with the context. + + """ + + connectable = create_engine(SQLALCHEMY_DATABASE_URL) + + 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() diff --git a/alembic/script.py.mako b/alembic/script.py.mako new file mode 100644 index 00000000..2c015630 --- /dev/null +++ b/alembic/script.py.mako @@ -0,0 +1,24 @@ +"""${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"} diff --git a/alembic/versions/91b42971b0df_.py b/alembic/versions/91b42971b0df_.py new file mode 100644 index 00000000..d5dd05c5 --- /dev/null +++ b/alembic/versions/91b42971b0df_.py @@ -0,0 +1,131 @@ +"""empty message + +Revision ID: 91b42971b0df +Revises: +Create Date: 2021-02-06 16:15:07.861957 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import sqlite + +# revision identifiers, used by Alembic. +revision = '91b42971b0df' +down_revision = None +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index('ix_categories_id', table_name='categories') + op.drop_table('categories') + op.drop_index('ix_invitations_id', table_name='invitations') + op.drop_table('invitations') + op.drop_index('ix_users_id', table_name='users') + op.drop_table('users') + op.drop_index('ix_quotes_id', table_name='quotes') + op.drop_table('quotes') + op.drop_index('ix_wikipedia_events_id', table_name='wikipedia_events') + op.drop_table('wikipedia_events') + op.drop_index('ix_zodiac-signs_id', table_name='zodiac-signs') + op.drop_table('zodiac-signs') + op.drop_index('ix_events_id', table_name='events') + op.drop_table('events') + op.drop_index('ix_user_event_id', table_name='user_event') + op.drop_table('user_event') + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('user_event', + sa.Column('id', sa.INTEGER(), nullable=False), + sa.Column('user_id', sa.INTEGER(), nullable=True), + sa.Column('event_id', sa.INTEGER(), nullable=True), + sa.ForeignKeyConstraint(['event_id'], ['events.id'], ), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_index('ix_user_event_id', 'user_event', ['id'], unique=False) + op.create_table('events', + sa.Column('id', sa.INTEGER(), nullable=False), + sa.Column('title', sa.VARCHAR(), nullable=False), + sa.Column('start', sa.DATETIME(), nullable=False), + sa.Column('end', sa.DATETIME(), nullable=False), + sa.Column('content', sa.VARCHAR(), nullable=True), + sa.Column('location', sa.VARCHAR(), nullable=True), + sa.Column('color', sa.VARCHAR(), nullable=True), + sa.Column('owner_id', sa.INTEGER(), nullable=True), + sa.Column('category_id', sa.INTEGER(), nullable=True), + sa.ForeignKeyConstraint(['category_id'], ['categories.id'], ), + sa.ForeignKeyConstraint(['owner_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_index('ix_events_id', 'events', ['id'], unique=False) + op.create_table('zodiac-signs', + sa.Column('id', sa.INTEGER(), nullable=False), + sa.Column('name', sa.VARCHAR(), nullable=False), + sa.Column('start_month', sa.INTEGER(), nullable=False), + sa.Column('start_day_in_month', sa.INTEGER(), nullable=False), + sa.Column('end_month', sa.INTEGER(), nullable=False), + sa.Column('end_day_in_month', sa.INTEGER(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) + op.create_index('ix_zodiac-signs_id', 'zodiac-signs', ['id'], unique=False) + op.create_table('wikipedia_events', + sa.Column('id', sa.INTEGER(), nullable=False), + sa.Column('date_', sa.VARCHAR(), nullable=False), + sa.Column('wikipedia', sa.VARCHAR(), nullable=False), + sa.Column('events', sqlite.JSON(), nullable=True), + sa.Column('date_inserted', sa.DATETIME(), nullable=True), + sa.PrimaryKeyConstraint('id') + ) + op.create_index('ix_wikipedia_events_id', 'wikipedia_events', ['id'], unique=False) + op.create_table('quotes', + sa.Column('id', sa.INTEGER(), nullable=False), + sa.Column('text', sa.VARCHAR(), nullable=False), + sa.Column('author', sa.VARCHAR(), nullable=True), + sa.PrimaryKeyConstraint('id') + ) + op.create_index('ix_quotes_id', 'quotes', ['id'], unique=False) + op.create_table('users', + sa.Column('id', sa.INTEGER(), nullable=False), + sa.Column('username', sa.VARCHAR(), nullable=False), + sa.Column('email', sa.VARCHAR(), nullable=False), + sa.Column('password', sa.VARCHAR(), nullable=False), + sa.Column('full_name', sa.VARCHAR(), nullable=True), + sa.Column('language', sa.VARCHAR(), nullable=True), + sa.Column('description', sa.VARCHAR(), nullable=True), + sa.Column('avatar', sa.VARCHAR(), nullable=True), + sa.Column('telegram_id', sa.VARCHAR(), nullable=True), + sa.Column('is_active', sa.BOOLEAN(), nullable=True), + sa.CheckConstraint('is_active IN (0, 1)'), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('email'), + sa.UniqueConstraint('telegram_id'), + sa.UniqueConstraint('username') + ) + op.create_index('ix_users_id', 'users', ['id'], unique=False) + op.create_table('invitations', + sa.Column('id', sa.INTEGER(), nullable=False), + sa.Column('status', sa.VARCHAR(), nullable=False), + sa.Column('recipient_id', sa.INTEGER(), nullable=True), + sa.Column('event_id', sa.INTEGER(), nullable=True), + sa.Column('creation', sa.DATETIME(), nullable=True), + sa.ForeignKeyConstraint(['event_id'], ['events.id'], ), + sa.ForeignKeyConstraint(['recipient_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_index('ix_invitations_id', 'invitations', ['id'], unique=False) + op.create_table('categories', + sa.Column('id', sa.INTEGER(), nullable=False), + sa.Column('name', sa.VARCHAR(), nullable=False), + sa.Column('color', sa.VARCHAR(), nullable=False), + sa.Column('user_id', sa.INTEGER(), nullable=False), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('user_id', 'name', 'color') + ) + op.create_index('ix_categories_id', 'categories', ['id'], unique=False) + # ### end Alembic commands ### From b3bbb06349ae408d4f5f0ccae33232e536dd37d4 Mon Sep 17 00:00:00 2001 From: Ellen Date: Sat, 6 Feb 2021 16:33:43 +0200 Subject: [PATCH 2/9] fix: test failed basuse lint i guess --- alembic/versions/91b42971b0df_.py | 152 +++++++++++++++--------------- 1 file changed, 78 insertions(+), 74 deletions(-) diff --git a/alembic/versions/91b42971b0df_.py b/alembic/versions/91b42971b0df_.py index d5dd05c5..312fa14a 100644 --- a/alembic/versions/91b42971b0df_.py +++ b/alembic/versions/91b42971b0df_.py @@ -40,92 +40,96 @@ def upgrade(): def downgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table('user_event', - sa.Column('id', sa.INTEGER(), nullable=False), - sa.Column('user_id', sa.INTEGER(), nullable=True), - sa.Column('event_id', sa.INTEGER(), nullable=True), - sa.ForeignKeyConstraint(['event_id'], ['events.id'], ), - sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), - sa.PrimaryKeyConstraint('id') - ) + sa.Column('id', sa.INTEGER(), nullable=False), + sa.Column('user_id', sa.INTEGER(), nullable=True), + sa.Column('event_id', sa.INTEGER(), nullable=True), + sa.ForeignKeyConstraint(['event_id'], ['events.id'], ), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id') + ) op.create_index('ix_user_event_id', 'user_event', ['id'], unique=False) op.create_table('events', - sa.Column('id', sa.INTEGER(), nullable=False), - sa.Column('title', sa.VARCHAR(), nullable=False), - sa.Column('start', sa.DATETIME(), nullable=False), - sa.Column('end', sa.DATETIME(), nullable=False), - sa.Column('content', sa.VARCHAR(), nullable=True), - sa.Column('location', sa.VARCHAR(), nullable=True), - sa.Column('color', sa.VARCHAR(), nullable=True), - sa.Column('owner_id', sa.INTEGER(), nullable=True), - sa.Column('category_id', sa.INTEGER(), nullable=True), - sa.ForeignKeyConstraint(['category_id'], ['categories.id'], ), - sa.ForeignKeyConstraint(['owner_id'], ['users.id'], ), - sa.PrimaryKeyConstraint('id') - ) + sa.Column('id', sa.INTEGER(), nullable=False), + sa.Column('title', sa.VARCHAR(), nullable=False), + sa.Column('start', sa.DATETIME(), nullable=False), + sa.Column('end', sa.DATETIME(), nullable=False), + sa.Column('content', sa.VARCHAR(), nullable=True), + sa.Column('location', sa.VARCHAR(), nullable=True), + sa.Column('color', sa.VARCHAR(), nullable=True), + sa.Column('owner_id', sa.INTEGER(), nullable=True), + sa.Column('category_id', sa.INTEGER(), nullable=True), + sa.ForeignKeyConstraint( + ['category_id'], ['categories.id'], ), + sa.ForeignKeyConstraint(['owner_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id') + ) op.create_index('ix_events_id', 'events', ['id'], unique=False) op.create_table('zodiac-signs', - sa.Column('id', sa.INTEGER(), nullable=False), - sa.Column('name', sa.VARCHAR(), nullable=False), - sa.Column('start_month', sa.INTEGER(), nullable=False), - sa.Column('start_day_in_month', sa.INTEGER(), nullable=False), - sa.Column('end_month', sa.INTEGER(), nullable=False), - sa.Column('end_day_in_month', sa.INTEGER(), nullable=False), - sa.PrimaryKeyConstraint('id') - ) + sa.Column('id', sa.INTEGER(), nullable=False), + sa.Column('name', sa.VARCHAR(), nullable=False), + sa.Column('start_month', sa.INTEGER(), nullable=False), + sa.Column('start_day_in_month', + sa.INTEGER(), nullable=False), + sa.Column('end_month', sa.INTEGER(), nullable=False), + sa.Column('end_day_in_month', + sa.INTEGER(), nullable=False), + sa.PrimaryKeyConstraint('id') + ) op.create_index('ix_zodiac-signs_id', 'zodiac-signs', ['id'], unique=False) op.create_table('wikipedia_events', - sa.Column('id', sa.INTEGER(), nullable=False), - sa.Column('date_', sa.VARCHAR(), nullable=False), - sa.Column('wikipedia', sa.VARCHAR(), nullable=False), - sa.Column('events', sqlite.JSON(), nullable=True), - sa.Column('date_inserted', sa.DATETIME(), nullable=True), - sa.PrimaryKeyConstraint('id') - ) - op.create_index('ix_wikipedia_events_id', 'wikipedia_events', ['id'], unique=False) + sa.Column('id', sa.INTEGER(), nullable=False), + sa.Column('date_', sa.VARCHAR(), nullable=False), + sa.Column('wikipedia', sa.VARCHAR(), nullable=False), + sa.Column('events', sqlite.JSON(), nullable=True), + sa.Column('date_inserted', sa.DATETIME(), nullable=True), + sa.PrimaryKeyConstraint('id') + ) + op.create_index('ix_wikipedia_events_id', + 'wikipedia_events', ['id'], unique=False) op.create_table('quotes', - sa.Column('id', sa.INTEGER(), nullable=False), - sa.Column('text', sa.VARCHAR(), nullable=False), - sa.Column('author', sa.VARCHAR(), nullable=True), - sa.PrimaryKeyConstraint('id') - ) + sa.Column('id', sa.INTEGER(), nullable=False), + sa.Column('text', sa.VARCHAR(), nullable=False), + sa.Column('author', sa.VARCHAR(), nullable=True), + sa.PrimaryKeyConstraint('id') + ) op.create_index('ix_quotes_id', 'quotes', ['id'], unique=False) op.create_table('users', - sa.Column('id', sa.INTEGER(), nullable=False), - sa.Column('username', sa.VARCHAR(), nullable=False), - sa.Column('email', sa.VARCHAR(), nullable=False), - sa.Column('password', sa.VARCHAR(), nullable=False), - sa.Column('full_name', sa.VARCHAR(), nullable=True), - sa.Column('language', sa.VARCHAR(), nullable=True), - sa.Column('description', sa.VARCHAR(), nullable=True), - sa.Column('avatar', sa.VARCHAR(), nullable=True), - sa.Column('telegram_id', sa.VARCHAR(), nullable=True), - sa.Column('is_active', sa.BOOLEAN(), nullable=True), - sa.CheckConstraint('is_active IN (0, 1)'), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('email'), - sa.UniqueConstraint('telegram_id'), - sa.UniqueConstraint('username') - ) + sa.Column('id', sa.INTEGER(), nullable=False), + sa.Column('username', sa.VARCHAR(), nullable=False), + sa.Column('email', sa.VARCHAR(), nullable=False), + sa.Column('password', sa.VARCHAR(), nullable=False), + sa.Column('full_name', sa.VARCHAR(), nullable=True), + sa.Column('language', sa.VARCHAR(), nullable=True), + sa.Column('description', sa.VARCHAR(), nullable=True), + sa.Column('avatar', sa.VARCHAR(), nullable=True), + sa.Column('telegram_id', sa.VARCHAR(), nullable=True), + sa.Column('is_active', sa.BOOLEAN(), nullable=True), + sa.CheckConstraint('is_active IN (0, 1)'), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('email'), + sa.UniqueConstraint('telegram_id'), + sa.UniqueConstraint('username') + ) op.create_index('ix_users_id', 'users', ['id'], unique=False) op.create_table('invitations', - sa.Column('id', sa.INTEGER(), nullable=False), - sa.Column('status', sa.VARCHAR(), nullable=False), - sa.Column('recipient_id', sa.INTEGER(), nullable=True), - sa.Column('event_id', sa.INTEGER(), nullable=True), - sa.Column('creation', sa.DATETIME(), nullable=True), - sa.ForeignKeyConstraint(['event_id'], ['events.id'], ), - sa.ForeignKeyConstraint(['recipient_id'], ['users.id'], ), - sa.PrimaryKeyConstraint('id') - ) + sa.Column('id', sa.INTEGER(), nullable=False), + sa.Column('status', sa.VARCHAR(), nullable=False), + sa.Column('recipient_id', sa.INTEGER(), nullable=True), + sa.Column('event_id', sa.INTEGER(), nullable=True), + sa.Column('creation', sa.DATETIME(), nullable=True), + sa.ForeignKeyConstraint(['event_id'], ['events.id'], ), + sa.ForeignKeyConstraint(['recipient_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id') + ) op.create_index('ix_invitations_id', 'invitations', ['id'], unique=False) op.create_table('categories', - sa.Column('id', sa.INTEGER(), nullable=False), - sa.Column('name', sa.VARCHAR(), nullable=False), - sa.Column('color', sa.VARCHAR(), nullable=False), - sa.Column('user_id', sa.INTEGER(), nullable=False), - sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('user_id', 'name', 'color') - ) + sa.Column('id', sa.INTEGER(), nullable=False), + sa.Column('name', sa.VARCHAR(), nullable=False), + sa.Column('color', sa.VARCHAR(), nullable=False), + sa.Column('user_id', sa.INTEGER(), nullable=False), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('user_id', 'name', 'color') + ) op.create_index('ix_categories_id', 'categories', ['id'], unique=False) # ### end Alembic commands ### From 22180af746d774cf2b886a0f86234f53a378e4bf Mon Sep 17 00:00:00 2001 From: Ellen Date: Sat, 6 Feb 2021 16:36:47 +0200 Subject: [PATCH 3/9] fix: why test failesss --- alembic/versions/91b42971b0df_.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alembic/versions/91b42971b0df_.py b/alembic/versions/91b42971b0df_.py index 312fa14a..18a5d836 100644 --- a/alembic/versions/91b42971b0df_.py +++ b/alembic/versions/91b42971b0df_.py @@ -1,7 +1,7 @@ """empty message Revision ID: 91b42971b0df -Revises: +Revises: Create Date: 2021-02-06 16:15:07.861957 """ From f662d5462a34af6f0511c189ef451a28a6e8b86e Mon Sep 17 00:00:00 2001 From: Ellen Date: Thu, 18 Feb 2021 08:34:14 +0200 Subject: [PATCH 4/9] feat: add date to alembic template --- alembic.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alembic.ini b/alembic.ini index 85744540..7236c1e5 100644 --- a/alembic.ini +++ b/alembic.ini @@ -6,7 +6,7 @@ script_location = alembic # template used to generate migration files -# file_template = %%(rev)s_%%(slug)s +file_template = %%(year)d-%%(month).2d-%%(day).2d_%%(rev)s_%%(slug)s # timezone to use when rendering the date # within the migration file as well as the filename. From 568844c1ea95cd8768e2c8bf19a51d941ac84d82 Mon Sep 17 00:00:00 2001 From: Ellen Date: Thu, 18 Feb 2021 08:48:13 +0200 Subject: [PATCH 5/9] fix import due to code update on upstream --- alembic/env.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alembic/env.py b/alembic/env.py index 4eb1da7d..298e5431 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -1,4 +1,4 @@ -from app.database.database import Base +from app.database.models import Base # from app.database.models import * # This helps alembic autogeneration from logging.config import fileConfig From 9865cbcd5833b58d40bbabb97a97fbfcaec39a62 Mon Sep 17 00:00:00 2001 From: Ellen Date: Thu, 18 Feb 2021 08:56:20 +0200 Subject: [PATCH 6/9] feat: use our logger --- alembic/env.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alembic/env.py b/alembic/env.py index 298e5431..2877860a 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -19,7 +19,7 @@ # Interpret the config file for Python logging. # This line sets up loggers basically. -fileConfig(config.config_file_name) +fileConfig(config.config_file_name, disable_existing_loggers=False) # add your model's MetaData object here # for 'autogenerate' support From e84219968031fe8e75c4d428a38b054b60f06a00 Mon Sep 17 00:00:00 2001 From: Ellen Date: Sun, 21 Feb 2021 19:19:13 +0200 Subject: [PATCH 7/9] fix : move module into database folder --- alembic.ini | 4 ++-- {alembic => app/database/alembic}/README | 0 app/database/alembic/__init__.py | 0 {alembic => app/database/alembic}/env.py | 0 {alembic => app/database/alembic}/script.py.mako | 0 {alembic => app/database/alembic}/versions/91b42971b0df_.py | 0 6 files changed, 2 insertions(+), 2 deletions(-) rename {alembic => app/database/alembic}/README (100%) create mode 100644 app/database/alembic/__init__.py rename {alembic => app/database/alembic}/env.py (100%) rename {alembic => app/database/alembic}/script.py.mako (100%) rename {alembic => app/database/alembic}/versions/91b42971b0df_.py (100%) diff --git a/alembic.ini b/alembic.ini index 7236c1e5..16e9fab7 100644 --- a/alembic.ini +++ b/alembic.ini @@ -3,7 +3,7 @@ [alembic] # path to migration scripts # script_location = alembic -script_location = alembic +script_location = app\\database\\alembic # template used to generate migration files file_template = %%(year)d-%%(month).2d-%%(day).2d_%%(rev)s_%%(slug)s @@ -36,7 +36,7 @@ file_template = %%(year)d-%%(month).2d-%%(day).2d_%%(rev)s_%%(slug)s # are written from script.py.mako # output_encoding = utf-8 -sqlalchemy.url = driver://user:pass@localhost/dbname +# sqlalchemy.url = driver://user:pass@localhost/dbname [post_write_hooks] diff --git a/alembic/README b/app/database/alembic/README similarity index 100% rename from alembic/README rename to app/database/alembic/README diff --git a/app/database/alembic/__init__.py b/app/database/alembic/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/alembic/env.py b/app/database/alembic/env.py similarity index 100% rename from alembic/env.py rename to app/database/alembic/env.py diff --git a/alembic/script.py.mako b/app/database/alembic/script.py.mako similarity index 100% rename from alembic/script.py.mako rename to app/database/alembic/script.py.mako diff --git a/alembic/versions/91b42971b0df_.py b/app/database/alembic/versions/91b42971b0df_.py similarity index 100% rename from alembic/versions/91b42971b0df_.py rename to app/database/alembic/versions/91b42971b0df_.py From 14ee318eb9eb747f2d04c1d47bfc1f2e7ec0ca13 Mon Sep 17 00:00:00 2001 From: Ellen Date: Sun, 21 Feb 2021 19:47:23 +0200 Subject: [PATCH 8/9] fix: reorder imports --- app/database/alembic/env.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/database/alembic/env.py b/app/database/alembic/env.py index 2877860a..c5f9c56b 100644 --- a/app/database/alembic/env.py +++ b/app/database/alembic/env.py @@ -1,13 +1,11 @@ -from app.database.models import Base -# from app.database.models import * # This helps alembic autogeneration - from logging.config import fileConfig +import os +from alembic import context from sqlalchemy import create_engine -from alembic import context -import os from app import config as app_config +from app.database.models import Base SQLALCHEMY_DATABASE_URL = os.getenv( From e6c4375931c88299e21b6286dde28d8d3333aa66 Mon Sep 17 00:00:00 2001 From: Ellen Date: Sun, 21 Feb 2021 19:50:20 +0200 Subject: [PATCH 9/9] fix: add comma --- app/database/alembic/env.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/database/alembic/env.py b/app/database/alembic/env.py index c5f9c56b..bca6fab9 100644 --- a/app/database/alembic/env.py +++ b/app/database/alembic/env.py @@ -66,7 +66,7 @@ def run_migrations_online(): with connectable.connect() as connection: context.configure( - connection=connection, target_metadata=target_metadata + connection=connection, target_metadata=target_metadata, ) with context.begin_transaction():