Skip to content
Snippets Groups Projects
Commit d0446499 authored by Syrine Neifar's avatar Syrine Neifar
Browse files

Fixes new migration

parent eda4ac1e
No related branches found
No related tags found
No related merge requests found
...@@ -31,20 +31,6 @@ def upgrade(): ...@@ -31,20 +31,6 @@ def upgrade():
sa.Column("url", sa.String(length=128), nullable=True), sa.Column("url", sa.String(length=128), nullable=True),
sa.PrimaryKeyConstraint("id"), sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("slug"), sa.UniqueConstraint("slug"),
keep_existing= True
)
if "app_role" not in tables:
op.create_table(
"app_role",
sa.Column("user_id", sa.String(length=64), nullable=False),
sa.Column("app_id", sa.Integer(), nullable=False),
sa.Column("role_id", sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(
["app_id"],
["app.id"],
),
sa.PrimaryKeyConstraint("user_id", "app_id"),
) )
if "role" not in tables: if "role" not in tables:
...@@ -52,26 +38,35 @@ def upgrade(): ...@@ -52,26 +38,35 @@ def upgrade():
"role", "role",
sa.Column("id", sa.Integer(), nullable=False), sa.Column("id", sa.Integer(), nullable=False),
sa.Column("name", sa.String(length=64), nullable=True), sa.Column("name", sa.String(length=64), nullable=True),
sa.PrimaryKeyConstraint("id"), sa.PrimaryKeyConstraint("id")
) )
op.execute("INSERT INTO `role` (id, `name`) VALUES (1, 'admin')") op.execute("INSERT INTO `role` (id, `name`) VALUES (1, 'admin')")
op.execute("INSERT INTO `role` (id, `name`) VALUES (2, 'user')") op.execute("INSERT INTO `role` (id, `name`) VALUES (2, 'user')")
op.execute("INSERT INTO `role` (id, `name`) VALUES (3, 'no access')") op.execute("INSERT INTO `role` (id, `name`) VALUES (3, 'no access')")
op.create_foreign_key(None, "app_role", "role", ["role_id"], ["id"]) if "app_role" not in tables:
op.create_table(
"app_role",
sa.Column("user_id", sa.String(length=64), nullable=False),
sa.Column("app_id", sa.Integer(), nullable=False),
sa.Column("role_id", sa.Integer(), nullable=True),
sa.PrimaryKeyConstraint("user_id", "app_id"),
sa.ForeignKeyConstraint(["app_id"],["app.id"]),
sa.ForeignKeyConstraint(["role_id"],["role.id"])
)
if "oauthclient_app" not in tables: if "oauthclient_app" not in tables:
op.create_table('oauthclient_app', op.create_table('oauthclient_app',
sa.Column('oauthclient_id', mysql.VARCHAR(length=64), nullable=False), sa.Column('oauthclient_id', mysql.VARCHAR(length=64), nullable=False),
sa.Column('app_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=False), sa.Column('app_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=False),
sa.ForeignKeyConstraint(['app_id'], ['app.id'], name='oauthclient_app_fk_app_id'),
sa.PrimaryKeyConstraint('oauthclient_id'), sa.PrimaryKeyConstraint('oauthclient_id'),
sa.ForeignKeyConstraint(['app_id'], ['app.id'], name='oauthclient_app_fk_app_id'),
mysql_default_charset='utf8mb3', mysql_default_charset='utf8mb3',
mysql_engine='InnoDB' mysql_engine='InnoDB'
) )
def downgrade(): def downgrade():
op.drop_table("oauthclient_app")
op.drop_table("role") op.drop_table("role")
op.drop_table("app_role") op.drop_table("app_role")
op.drop_table("app") op.drop_table("app")
op.drop_table("oauthclient_app") \ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment