From 70895636a30a09ac9a1523808d9526b619a4b8c9 Mon Sep 17 00:00:00 2001
From: kaiyou <pierre@jaury.eu>
Date: Wed, 13 Nov 2019 17:54:41 +0100
Subject: [PATCH] Repair Alembic automatic generation

---
 migrations/README                    |  1 -
 migrations/alembic.ini               | 10 ---
 migrations/env.py                    | 39 +-----------
 migrations/script.py.mako            |  2 +
 migrations/versions/5271f611b98b_.py | 36 -----------
 migrations/versions/cfb466a78348_.py | 92 ----------------------------
 6 files changed, 3 insertions(+), 177 deletions(-)
 delete mode 100644 migrations/README
 delete mode 100644 migrations/versions/5271f611b98b_.py
 delete mode 100644 migrations/versions/cfb466a78348_.py

diff --git a/migrations/README b/migrations/README
deleted file mode 100644
index 98e4f9c4..00000000
--- a/migrations/README
+++ /dev/null
@@ -1 +0,0 @@
-Generic single-database configuration.
\ No newline at end of file
diff --git a/migrations/alembic.ini b/migrations/alembic.ini
index f8ed4801..d7e49f3d 100644
--- a/migrations/alembic.ini
+++ b/migrations/alembic.ini
@@ -1,15 +1,5 @@
-# A generic, single database configuration.
-
 [alembic]
-# template used to generate migration files
-# file_template = %%(rev)s_%%(slug)s
-
-# set to 'true' to run the environment during
-# the 'revision' command, regardless of autogenerate
-# revision_environment = false
-
 
-# Logging configuration
 [loggers]
 keys = root,sqlalchemy,alembic
 
diff --git a/migrations/env.py b/migrations/env.py
index 79b8174b..47cc50e3 100644
--- a/migrations/env.py
+++ b/migrations/env.py
@@ -8,43 +8,19 @@ from sqlalchemy import pool
 
 from alembic import context
 
-# 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)
 logger = logging.getLogger('alembic.env')
 
-# add your model's MetaData object here
-# for 'autogenerate' support
-# from myapp import mymodel
-# target_metadata = mymodel.Base.metadata
+
 from flask import current_app
 config.set_main_option(
     'sqlalchemy.url', current_app.config.get(
         'SQLALCHEMY_DATABASE_URI').replace('%', '%%'))
 target_metadata = current_app.extensions['migrate'].db.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 = config.get_main_option("sqlalchemy.url")
     context.configure(
         url=url, target_metadata=target_metadata, literal_binds=True
@@ -55,29 +31,17 @@ def run_migrations_offline():
 
 
 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.
-
-    """
-
-    # this callback is used to prevent an auto-migration from being generated
-    # when there are no changes to the schema
-    # reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
     def process_revision_directives(context, revision, directives):
         if getattr(config.cmd_opts, 'autogenerate', False):
             script = directives[0]
             if script.upgrade_ops.is_empty():
                 directives[:] = []
                 logger.info('No changes in schema detected.')
-
     connectable = engine_from_config(
         config.get_section(config.config_ini_section),
         prefix='sqlalchemy.',
         poolclass=pool.NullPool,
     )
-
     with connectable.connect() as connection:
         context.configure(
             connection=connection,
@@ -85,7 +49,6 @@ def run_migrations_online():
             process_revision_directives=process_revision_directives,
             **current_app.extensions['migrate'].configure_args
         )
-
         with context.begin_transaction():
             context.run_migrations()
 
diff --git a/migrations/script.py.mako b/migrations/script.py.mako
index a78eb7db..100bad5a 100644
--- a/migrations/script.py.mako
+++ b/migrations/script.py.mako
@@ -4,8 +4,10 @@ Revision ID: ${up_revision}
 Revises: ${down_revision | comma,n}
 Create Date: ${create_date}
 """
+
 from alembic import op
 import sqlalchemy as sa
+import hiboo
 ${imports if imports else ""}
 
 revision = ${repr(up_revision)}
diff --git a/migrations/versions/5271f611b98b_.py b/migrations/versions/5271f611b98b_.py
deleted file mode 100644
index 2afd9143..00000000
--- a/migrations/versions/5271f611b98b_.py
+++ /dev/null
@@ -1,36 +0,0 @@
-""" Add authorization codes in the database
-
-Revision ID: 5271f611b98b
-Revises: cfb466a78348
-Create Date: 2019-11-03 17:57:55.989647
-"""
-from alembic import op
-import sqlalchemy as sa
-
-
-revision = '5271f611b98b'
-down_revision = 'cfb466a78348'
-branch_labels = None
-depends_on = None
-
-
-def upgrade():
-    op.create_table('oidc_authorization_code',
-    sa.Column('code', sa.String(length=120), nullable=False),
-    sa.Column('client_id', sa.String(length=48), nullable=True),
-    sa.Column('redirect_uri', sa.Text(), nullable=True),
-    sa.Column('response_type', sa.Text(), nullable=True),
-    sa.Column('scope', sa.Text(), nullable=True),
-    sa.Column('auth_time', sa.Integer(), nullable=False),
-    sa.Column('nonce', sa.Text(), nullable=True),
-    sa.Column('user_id', sa.Text(), nullable=True),
-    sa.Column('uuid', sa.String(length=36), nullable=False),
-    sa.Column('created_at', sa.DateTime(), nullable=False),
-    sa.Column('updated_at', sa.DateTime(), nullable=True),
-    sa.Column('comment', sa.String(length=255), nullable=True),
-    sa.PrimaryKeyConstraint('uuid'),
-    sa.UniqueConstraint('code')
-    )
-
-def downgrade():
-    op.drop_table('oidc_authorization_code')
diff --git a/migrations/versions/cfb466a78348_.py b/migrations/versions/cfb466a78348_.py
deleted file mode 100644
index 129c0f12..00000000
--- a/migrations/versions/cfb466a78348_.py
+++ /dev/null
@@ -1,92 +0,0 @@
-""" empty message
-
-Revision ID: cfb466a78348
-Revises:
-Create Date: 2019-10-05 17:05:31.015711
-"""
-from alembic import op
-import sqlalchemy as sa
-
-
-revision = 'cfb466a78348'
-down_revision = None
-branch_labels = None
-depends_on = None
-
-
-def upgrade():
-    op.create_table('service',
-    sa.Column('protocol', sa.String(length=25), nullable=True),
-    sa.Column('name', sa.String(length=255), nullable=True),
-    sa.Column('provider', sa.String(length=255), nullable=True),
-    sa.Column('application', sa.String(length=255), nullable=True),
-    sa.Column('description', sa.String(), nullable=True),
-    sa.Column('policy', sa.String(length=255), nullable=True),
-    sa.Column('max_profiles', sa.Integer(), nullable=False),
-    sa.Column('config', sa.String(), nullable=True),
-    sa.Column('uuid', sa.String(length=36), nullable=False),
-    sa.Column('created_at', sa.DateTime(), nullable=False),
-    sa.Column('updated_at', sa.DateTime(), nullable=True),
-    sa.Column('comment', sa.String(length=255), nullable=True),
-    sa.PrimaryKeyConstraint('uuid')
-    )
-    op.create_table('user',
-    sa.Column('username', sa.String(length=255), nullable=False),
-    sa.Column('is_admin', sa.Boolean(), nullable=False),
-    sa.Column('uuid', sa.String(length=36), nullable=False),
-    sa.Column('created_at', sa.DateTime(), nullable=False),
-    sa.Column('updated_at', sa.DateTime(), nullable=True),
-    sa.Column('comment', sa.String(length=255), nullable=True),
-    sa.PrimaryKeyConstraint('uuid'),
-    sa.UniqueConstraint('username')
-    )
-    op.create_table('auth',
-    sa.Column('user_uuid', sa.String(length=36), nullable=True),
-    sa.Column('value', sa.String(), nullable=True),
-    sa.Column('extra', sa.String(), nullable=True),
-    sa.Column('uuid', sa.String(length=36), nullable=False),
-    sa.Column('created_at', sa.DateTime(), nullable=False),
-    sa.Column('updated_at', sa.DateTime(), nullable=True),
-    sa.Column('comment', sa.String(length=255), nullable=True),
-    sa.ForeignKeyConstraint(['user_uuid'], ['user.uuid'], ),
-    sa.PrimaryKeyConstraint('uuid')
-    )
-    op.create_table('identity',
-    sa.Column('user_uuid', sa.String(length=36), nullable=True),
-    sa.Column('service_uuid', sa.String(length=36), nullable=True),
-    sa.Column('username', sa.String(length=255), nullable=False),
-    sa.Column('status', sa.String(length=25), nullable=False),
-    sa.Column('extra', sa.String(), nullable=True),
-    sa.Column('uuid', sa.String(length=36), nullable=False),
-    sa.Column('created_at', sa.DateTime(), nullable=False),
-    sa.Column('updated_at', sa.DateTime(), nullable=True),
-    sa.Column('comment', sa.String(length=255), nullable=True),
-    sa.ForeignKeyConstraint(['service_uuid'], ['service.uuid'], ),
-    sa.ForeignKeyConstraint(['user_uuid'], ['user.uuid'], ),
-    sa.PrimaryKeyConstraint('uuid')
-    )
-    op.create_table('history',
-    sa.Column('user_uuid', sa.String(length=36), nullable=True),
-    sa.Column('identity_uuid', sa.String(length=36), nullable=True),
-    sa.Column('service_uuid', sa.String(length=36), nullable=True),
-    sa.Column('actor_uuid', sa.String(length=36), nullable=True),
-    sa.Column('category', sa.String(length=25), nullable=True),
-    sa.Column('value', sa.String(), nullable=True),
-    sa.Column('uuid', sa.String(length=36), nullable=False),
-    sa.Column('created_at', sa.DateTime(), nullable=False),
-    sa.Column('updated_at', sa.DateTime(), nullable=True),
-    sa.Column('comment', sa.String(length=255), nullable=True),
-    sa.ForeignKeyConstraint(['actor_uuid'], ['user.uuid'], ),
-    sa.ForeignKeyConstraint(['identity_uuid'], ['identity.uuid'], ),
-    sa.ForeignKeyConstraint(['service_uuid'], ['service.uuid'], ),
-    sa.ForeignKeyConstraint(['user_uuid'], ['user.uuid'], ),
-    sa.PrimaryKeyConstraint('uuid')
-    )
-
-
-def downgrade():
-    op.drop_table('history')
-    op.drop_table('identity')
-    op.drop_table('auth')
-    op.drop_table('user')
-    op.drop_table('service')
-- 
GitLab