From 01ac6332b1bab2b92edd7168aaecfcb2a1e95ed3 Mon Sep 17 00:00:00 2001 From: Adrian Moennich Date: Fri, 30 Jun 2017 16:14:17 +0200 Subject: [PATCH] Combine/cleanup alembic revisions --- ...31_35badbd96474_apply_naming_convention.py | 48 ---------- ...5_16874c3e98a8_use_fk_for_created_by_id.py | 24 ----- ...505131439_30d94f9c21fc_use_acl_settings.py | 30 ------- ..._685f2016cd0_use_proper_fk_for_event_id.py | 27 ------ ...170630_1551_3888761f35f7_create_tables.py} | 38 ++++---- ...201410311223_1c2b0e17447d_create_tables.py | 57 ------------ ...51_5a9176bca07d_apply_naming_convention.py | 44 ---------- ..._2c9618a7a2ea_reference_the_new_objects.py | 87 ------------------- ...086da074_use_foreign_key_for_categories.py | 23 ----- ...640f6_add_session_to_livesyncqueueentry.py | 84 ------------------ ...0170630_1557_aa0dbc6c14aa_create_tables.py | 75 ++++++++++++++++ ...59_3520616f8ff7_apply_naming_convention.py | 39 --------- ...use_fk_for_owned_by_id_and_make_it_not_.py | 26 ------ ...505131422_4ad9ccfb3d32_use_acl_settings.py | 30 ------- ...170630_1611_6019621fea50_create_tables.py} | 24 ++--- 15 files changed, 106 insertions(+), 550 deletions(-) delete mode 100644 chat/indico_chat/migrations/201503101131_35badbd96474_apply_naming_convention.py delete mode 100644 chat/indico_chat/migrations/201505081445_16874c3e98a8_use_fk_for_created_by_id.py delete mode 100644 chat/indico_chat/migrations/201505131439_30d94f9c21fc_use_acl_settings.py delete mode 100644 chat/indico_chat/migrations/201509241201_685f2016cd0_use_proper_fk_for_event_id.py rename chat/indico_chat/migrations/{201409291524_1bd6c5129d29_create_tables.py => 20170630_1551_3888761f35f7_create_tables.py} (59%) delete mode 100644 livesync/indico_livesync/migrations/201410311223_1c2b0e17447d_create_tables.py delete mode 100644 livesync/indico_livesync/migrations/201503101351_5a9176bca07d_apply_naming_convention.py delete mode 100644 livesync/indico_livesync/migrations/201604081137_2c9618a7a2ea_reference_the_new_objects.py delete mode 100644 livesync/indico_livesync/migrations/201607131557_230c086da074_use_foreign_key_for_categories.py delete mode 100644 livesync/indico_livesync/migrations/201607151736_205f944640f6_add_session_to_livesyncqueueentry.py create mode 100644 livesync/indico_livesync/migrations/20170630_1557_aa0dbc6c14aa_create_tables.py delete mode 100644 vc_vidyo/indico_vc_vidyo/migrations/201503101359_3520616f8ff7_apply_naming_convention.py delete mode 100644 vc_vidyo/indico_vc_vidyo/migrations/201505081934_3f376d68efc8_use_fk_for_owned_by_id_and_make_it_not_.py delete mode 100644 vc_vidyo/indico_vc_vidyo/migrations/201505131422_4ad9ccfb3d32_use_acl_settings.py rename vc_vidyo/indico_vc_vidyo/migrations/{201502191158_a702ad0bcea_create_extensions_table.py => 20170630_1611_6019621fea50_create_tables.py} (57%) diff --git a/chat/indico_chat/migrations/201503101131_35badbd96474_apply_naming_convention.py b/chat/indico_chat/migrations/201503101131_35badbd96474_apply_naming_convention.py deleted file mode 100644 index 2e8aade..0000000 --- a/chat/indico_chat/migrations/201503101131_35badbd96474_apply_naming_convention.py +++ /dev/null @@ -1,48 +0,0 @@ -"""Apply naming convention - -Revision ID: 35badbd96474 -Revises: 1bd6c5129d29 -Create Date: 2015-03-10 11:31:42.850496 -""" - -from alembic import op - -from indico.core.db.sqlalchemy.util.bulk_rename import bulk_rename - - -# revision identifiers, used by Alembic. -revision = '35badbd96474' -down_revision = '1bd6c5129d29' - - -mapping = { - 'plugin_chat.chatroom_events': { - 'indexes': { - 'chatroom_events_pkey': 'pk_chatroom_events', - 'ix_plugin_chat_chatroom_events_chatroom_id': 'ix_chatroom_events_chatroom_id', - 'ix_plugin_chat_chatroom_events_event_id': 'ix_chatroom_events_event_id', - }, - 'constraints': { - 'chatroom_events_chatroom_id_fkey': 'fk_chatroom_events_chatroom_id_chatrooms', - } - }, - 'plugin_chat.chatrooms': { - 'indexes': { - 'chatrooms_pkey': 'pk_chatrooms', - 'ix_plugin_chat_chatrooms_created_by_id': 'ix_chatrooms_created_by_id', - }, - 'constraints': { - 'chatrooms_jid_node_custom_server_key': 'uq_chatrooms_jid_node_custom_server', - } - } -} - - -def upgrade(): - for stmt in bulk_rename(mapping): - op.execute(stmt) - - -def downgrade(): - for stmt in bulk_rename(mapping, True): - op.execute(stmt) diff --git a/chat/indico_chat/migrations/201505081445_16874c3e98a8_use_fk_for_created_by_id.py b/chat/indico_chat/migrations/201505081445_16874c3e98a8_use_fk_for_created_by_id.py deleted file mode 100644 index 20ca5d6..0000000 --- a/chat/indico_chat/migrations/201505081445_16874c3e98a8_use_fk_for_created_by_id.py +++ /dev/null @@ -1,24 +0,0 @@ -"""Use FK for created_by_id - -Revision ID: 16874c3e98a8 -Revises: 35badbd96474 -Create Date: 2015-05-08 14:45:51.811224 -""" - -from alembic import op - - -# revision identifiers, used by Alembic. -revision = '16874c3e98a8' -down_revision = '35badbd96474' - - -def upgrade(): - op.create_foreign_key(None, - 'chatrooms', 'users', - ['created_by_id'], ['id'], - source_schema='plugin_chat', referent_schema='users') - - -def downgrade(): - op.drop_constraint('fk_chatrooms_created_by_id_users', 'chatrooms', schema='plugin_chat') diff --git a/chat/indico_chat/migrations/201505131439_30d94f9c21fc_use_acl_settings.py b/chat/indico_chat/migrations/201505131439_30d94f9c21fc_use_acl_settings.py deleted file mode 100644 index feb5141..0000000 --- a/chat/indico_chat/migrations/201505131439_30d94f9c21fc_use_acl_settings.py +++ /dev/null @@ -1,30 +0,0 @@ -"""Use ACL settings - -Revision ID: 30d94f9c21fc -Revises: 16874c3e98a8 -Create Date: 2015-05-13 14:39:18.659784 -""" - -from alembic import context - -from indico.core.db.sqlalchemy.util.convert_acl_settings import json_to_acl, acl_to_json - - -# revision identifiers, used by Alembic. -revision = '30d94f9c21fc' -down_revision = '16874c3e98a8' - - -acl_settings = {'plugin_chat.admins'} - - -def upgrade(): - if context.is_offline_mode(): - raise Exception('This upgrade is only possible in online mode') - json_to_acl(acl_settings) - - -def downgrade(): - if context.is_offline_mode(): - raise Exception('This downgrade is only possible in online mode') - acl_to_json(acl_settings) diff --git a/chat/indico_chat/migrations/201509241201_685f2016cd0_use_proper_fk_for_event_id.py b/chat/indico_chat/migrations/201509241201_685f2016cd0_use_proper_fk_for_event_id.py deleted file mode 100644 index 357f56f..0000000 --- a/chat/indico_chat/migrations/201509241201_685f2016cd0_use_proper_fk_for_event_id.py +++ /dev/null @@ -1,27 +0,0 @@ -"""Use proper FK for event_id - -Revision ID: 685f2016cd0 -Revises: 30d94f9c21fc -Create Date: 2015-09-24 12:01:59.704121 -""" - -from alembic import op - - -# revision identifiers, used by Alembic. -revision = '685f2016cd0' -down_revision = '30d94f9c21fc' - - -def upgrade(): - # delete orphaned payment chatroom associations - op.execute("DELETE FROM plugin_chat.chatroom_events ce WHERE NOT EXISTS " - "(SELECT 1 FROM events.events e WHERE e.id = ce.event_id)") - op.create_foreign_key(None, - 'chatroom_events', 'events', - ['event_id'], ['id'], - source_schema='plugin_chat', referent_schema='events') - - -def downgrade(): - op.drop_constraint('fk_chatroom_events_event_id_events', 'chatroom_events', schema='plugin_chat') diff --git a/chat/indico_chat/migrations/201409291524_1bd6c5129d29_create_tables.py b/chat/indico_chat/migrations/20170630_1551_3888761f35f7_create_tables.py similarity index 59% rename from chat/indico_chat/migrations/201409291524_1bd6c5129d29_create_tables.py rename to chat/indico_chat/migrations/20170630_1551_3888761f35f7_create_tables.py index 92038f6..3ab5477 100644 --- a/chat/indico_chat/migrations/201409291524_1bd6c5129d29_create_tables.py +++ b/chat/indico_chat/migrations/20170630_1551_3888761f35f7_create_tables.py @@ -1,20 +1,22 @@ """Create tables -Revision ID: 1bd6c5129d29 -Revises: None -Create Date: 2014-09-29 15:24:03.369025 +Revision ID: 3888761f35f7 +Revises: +Create Date: 2017-06-30 15:51:54.477207 """ import sqlalchemy as sa from alembic import op -from sqlalchemy.sql.ddl import CreateSchema, DropSchema - from indico.core.db.sqlalchemy import UTCDateTime +from sqlalchemy.sql.ddl import CreateSchema, DropSchema + # revision identifiers, used by Alembic. -revision = '1bd6c5129d29' +revision = '3888761f35f7' down_revision = None +branch_labels = None +depends_on = None def upgrade(): @@ -26,23 +28,21 @@ def upgrade(): sa.Column('description', sa.Text(), nullable=False), sa.Column('password', sa.String(), nullable=False), sa.Column('custom_server', sa.String(), nullable=False), - sa.Column('created_by_id', sa.Integer(), nullable=False), - sa.Column('created_dt', UTCDateTime(), nullable=False), - sa.Column('modified_dt', UTCDateTime(), nullable=True), - sa.PrimaryKeyConstraint('id', name='chatrooms_pkey'), - sa.UniqueConstraint('jid_node', 'custom_server', name='chatrooms_jid_node_custom_server_key'), - sa.Index('ix_plugin_chat_chatrooms_created_by_id', 'created_by_id'), + sa.Column('created_by_id', sa.Integer(), nullable=False, index=True), + sa.Column('created_dt', UTCDateTime, nullable=False), + sa.Column('modified_dt', UTCDateTime, nullable=True), + sa.ForeignKeyConstraint(['created_by_id'], ['users.users.id']), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('jid_node', 'custom_server'), schema='plugin_chat') op.create_table('chatroom_events', - sa.Column('event_id', sa.Integer(), nullable=False, autoincrement=False), - sa.Column('chatroom_id', sa.Integer(), nullable=False), + sa.Column('event_id', sa.Integer(), autoincrement=False, nullable=False, index=True), + sa.Column('chatroom_id', sa.Integer(), autoincrement=False, nullable=False, index=True), sa.Column('hidden', sa.Boolean(), nullable=False), sa.Column('show_password', sa.Boolean(), nullable=False), - sa.ForeignKeyConstraint(['chatroom_id'], ['plugin_chat.chatrooms.id'], - name='chatroom_events_chatroom_id_fkey'), - sa.PrimaryKeyConstraint('event_id', 'chatroom_id', name='chatroom_events_pkey'), - sa.Index('ix_plugin_chat_chatroom_events_event_id', 'event_id'), - sa.Index('ix_plugin_chat_chatroom_events_chatroom_id', 'chatroom_id'), + sa.ForeignKeyConstraint(['chatroom_id'], ['plugin_chat.chatrooms.id']), + sa.ForeignKeyConstraint(['event_id'], ['events.events.id']), + sa.PrimaryKeyConstraint('event_id', 'chatroom_id'), schema='plugin_chat') diff --git a/livesync/indico_livesync/migrations/201410311223_1c2b0e17447d_create_tables.py b/livesync/indico_livesync/migrations/201410311223_1c2b0e17447d_create_tables.py deleted file mode 100644 index 01b0876..0000000 --- a/livesync/indico_livesync/migrations/201410311223_1c2b0e17447d_create_tables.py +++ /dev/null @@ -1,57 +0,0 @@ -"""Create tables - -Revision ID: 1c2b0e17447d -Revises: None -Create Date: 2014-10-31 12:23:21.956730 -""" - -import sqlalchemy as sa -from alembic import op -from sqlalchemy.dialects import postgresql -from sqlalchemy.sql.ddl import CreateSchema, DropSchema - -from indico.core.db.sqlalchemy import UTCDateTime, PyIntEnum -from indico.core.db.sqlalchemy.util.bulk_rename import _rename_constraint - -from indico_livesync.models.queue import ChangeType - - -# revision identifiers, used by Alembic. -revision = '1c2b0e17447d' -down_revision = None - - -def upgrade(): - op.execute(CreateSchema('plugin_livesync')) - op.create_table('agents', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('backend_name', sa.String(), nullable=False), - sa.Column('name', sa.String(), nullable=False), - sa.Column('initial_data_exported', sa.Boolean(), nullable=False), - sa.Column('last_run', UTCDateTime(), nullable=False), - sa.Column('settings', postgresql.JSON(), nullable=False), - sa.PrimaryKeyConstraint('id', name='agents_pkey'), - schema='plugin_livesync') - op.create_table('queues', - sa.Column('id', sa.Integer(), nullable=False), - sa.Column('agent_id', sa.Integer(), nullable=False), - sa.Column('timestamp', UTCDateTime(), nullable=False), - sa.Column('processed', sa.Boolean(), nullable=False), - sa.Column('change', PyIntEnum(ChangeType), nullable=False), - sa.Column('type', sa.String(), nullable=False), - sa.Column('category_id', sa.String()), - sa.Column('event_id', sa.String()), - sa.Column('contrib_id', sa.String()), - sa.Column('subcontrib_id', sa.String()), - sa.ForeignKeyConstraint(['agent_id'], ['plugin_livesync.agents.id'], name='queues_agent_id_fkey'), - sa.PrimaryKeyConstraint('id', name='queues_pkey'), - sa.Index('ix_plugin_livesync_queues_agent_id', 'agent_id'), - schema='plugin_livesync') - # later migrations expect the old name... - op.execute(_rename_constraint('plugin_livesync', 'queues', 'ck_queues_valid_enum_change', 'queues_change_check')) - - -def downgrade(): - op.drop_table('queues', schema='plugin_livesync') - op.drop_table('agents', schema='plugin_livesync') - op.execute(DropSchema('plugin_livesync')) diff --git a/livesync/indico_livesync/migrations/201503101351_5a9176bca07d_apply_naming_convention.py b/livesync/indico_livesync/migrations/201503101351_5a9176bca07d_apply_naming_convention.py deleted file mode 100644 index a3e4e9f..0000000 --- a/livesync/indico_livesync/migrations/201503101351_5a9176bca07d_apply_naming_convention.py +++ /dev/null @@ -1,44 +0,0 @@ -"""Apply naming convention - -Revision ID: 5a9176bca07d -Revises: 1c2b0e17447d -Create Date: 2015-03-10 13:51:26.353667 -""" - -from alembic import op - -from indico.core.db.sqlalchemy.util.bulk_rename import bulk_rename - - -# revision identifiers, used by Alembic. -revision = '5a9176bca07d' -down_revision = '1c2b0e17447d' - - -mapping = { - 'plugin_livesync.agents': { - 'indexes': { - 'agents_pkey': 'pk_agents', - } - }, - 'plugin_livesync.queues': { - 'indexes': { - 'queues_pkey': 'pk_queues', - 'ix_plugin_livesync_queues_agent_id': 'ix_queues_agent_id', - }, - 'constraints': { - 'queues_change_check': 'ck_queues_valid_enum_change', - 'queues_agent_id_fkey': 'fk_queues_agent_id_agents', - } - }, -} - - -def upgrade(): - for stmt in bulk_rename(mapping): - op.execute(stmt) - - -def downgrade(): - for stmt in bulk_rename(mapping, True): - op.execute(stmt) diff --git a/livesync/indico_livesync/migrations/201604081137_2c9618a7a2ea_reference_the_new_objects.py b/livesync/indico_livesync/migrations/201604081137_2c9618a7a2ea_reference_the_new_objects.py deleted file mode 100644 index 882f577..0000000 --- a/livesync/indico_livesync/migrations/201604081137_2c9618a7a2ea_reference_the_new_objects.py +++ /dev/null @@ -1,87 +0,0 @@ -"""Reference the new objects - -Revision ID: 2c9618a7a2ea -Revises: 5a9176bca07d -Create Date: 2016-04-08 11:37:44.632046 -""" - -import sqlalchemy as sa -from alembic import op - -from indico.core.db.sqlalchemy import PyIntEnum -from indico_livesync.models.queue import EntryType - - -# revision identifiers, used by Alembic. -revision = '2c9618a7a2ea' -down_revision = '5a9176bca07d' - - -def upgrade(): - op.drop_column('queues', 'type', schema='plugin_livesync') - op.drop_column('queues', 'category_id', schema='plugin_livesync') - op.drop_column('queues', 'event_id', schema='plugin_livesync') - op.drop_column('queues', 'contrib_id', schema='plugin_livesync') - op.drop_column('queues', 'subcontrib_id', schema='plugin_livesync') - op.add_column('queues', sa.Column('category_id', sa.Integer(), nullable=True), schema='plugin_livesync') - op.add_column('queues', sa.Column('event_id', sa.Integer(), nullable=True), schema='plugin_livesync') - op.add_column('queues', sa.Column('contribution_id', sa.Integer(), nullable=True), schema='plugin_livesync') - op.add_column('queues', sa.Column('subcontribution_id', sa.Integer(), nullable=True), schema='plugin_livesync') - op.add_column('queues', sa.Column('type', PyIntEnum(EntryType), nullable=False), schema='plugin_livesync') - op.create_index(None, 'queues', ['category_id'], schema='plugin_livesync') - op.create_index(None, 'queues', ['event_id'], schema='plugin_livesync') - op.create_index(None, 'queues', ['contribution_id'], schema='plugin_livesync') - op.create_index(None, 'queues', ['subcontribution_id'], schema='plugin_livesync') - op.create_foreign_key(None, - 'queues', 'events', - ['event_id'], ['id'], - source_schema='plugin_livesync', referent_schema='events') - op.create_foreign_key(None, - 'queues', 'contributions', - ['contribution_id'], ['id'], - source_schema='plugin_livesync', referent_schema='events') - op.create_foreign_key(None, - 'queues', 'subcontributions', - ['subcontribution_id'], ['id'], - source_schema='plugin_livesync', referent_schema='events') - op.create_check_constraint('valid_category_entry', 'queues', - 'type != 1 OR (contribution_id IS NULL AND event_id IS NULL AND ' - 'subcontribution_id IS NULL AND category_id IS NOT NULL)', - schema='plugin_livesync') - op.create_check_constraint('valid_event_entry', 'queues', - 'type != 2 OR (category_id IS NULL AND contribution_id IS NULL AND ' - 'subcontribution_id IS NULL AND event_id IS NOT NULL)', - schema='plugin_livesync') - op.create_check_constraint('valid_contribution_entry', 'queues', - 'type != 3 OR (category_id IS NULL AND event_id IS NULL AND ' - 'subcontribution_id IS NULL AND contribution_id IS NOT NULL)', - schema='plugin_livesync') - op.create_check_constraint('valid_subcontribution_entry', 'queues', - 'type != 4 OR (category_id IS NULL AND contribution_id IS NULL AND ' - 'event_id IS NULL AND subcontribution_id IS NOT NULL)', - schema='plugin_livesync') - op.drop_constraint('ck_queues_valid_enum_change', 'queues', schema='plugin_livesync') - op.create_check_constraint('valid_enum_change', 'queues', - 'change IN (1, 2, 3, 4, 5)', - schema='plugin_livesync') - - -def downgrade(): - op.drop_constraint('ck_queues_valid_enum_change', 'queues', schema='plugin_livesync') - op.create_check_constraint('valid_enum_change', 'queues', - 'change IN (1, 2, 3, 4, 5, 6)', - schema='plugin_livesync') - op.drop_constraint('ck_queues_valid_category_entry', 'queues', schema='plugin_livesync') - op.drop_constraint('ck_queues_valid_event_entry', 'queues', schema='plugin_livesync') - op.drop_constraint('ck_queues_valid_contribution_entry', 'queues', schema='plugin_livesync') - op.drop_constraint('ck_queues_valid_subcontribution_entry', 'queues', schema='plugin_livesync') - op.drop_column('queues', 'type', schema='plugin_livesync') - op.drop_column('queues', 'category_id', schema='plugin_livesync') - op.drop_column('queues', 'event_id', schema='plugin_livesync') - op.drop_column('queues', 'subcontribution_id', schema='plugin_livesync') - op.drop_column('queues', 'contribution_id', schema='plugin_livesync') - op.add_column('queues', sa.Column('type', sa.String(), nullable=False), schema='plugin_livesync') - op.add_column('queues', sa.Column('category_id', sa.String(), nullable=True), schema='plugin_livesync') - op.add_column('queues', sa.Column('event_id', sa.String(), nullable=True), schema='plugin_livesync') - op.add_column('queues', sa.Column('contrib_id', sa.String(), nullable=True), schema='plugin_livesync') - op.add_column('queues', sa.Column('subcontrib_id', sa.String(), nullable=True), schema='plugin_livesync') diff --git a/livesync/indico_livesync/migrations/201607131557_230c086da074_use_foreign_key_for_categories.py b/livesync/indico_livesync/migrations/201607131557_230c086da074_use_foreign_key_for_categories.py deleted file mode 100644 index 338854a..0000000 --- a/livesync/indico_livesync/migrations/201607131557_230c086da074_use_foreign_key_for_categories.py +++ /dev/null @@ -1,23 +0,0 @@ -"""Use foreign key for categories - -Revision ID: 230c086da074 -Revises: 2c9618a7a2ea -Create Date: 2016-07-13 15:57:49.911262 -""" - -from alembic import op - - -revision = '230c086da074' -down_revision = '2c9618a7a2ea' - - -def upgrade(): - op.create_foreign_key(None, - 'queues', 'categories', - ['category_id'], ['id'], - source_schema='plugin_livesync', referent_schema='categories') - - -def downgrade(): - op.drop_constraint('fk_queues_category_id_categories', 'queues', schema='plugin_livesync') diff --git a/livesync/indico_livesync/migrations/201607151736_205f944640f6_add_session_to_livesyncqueueentry.py b/livesync/indico_livesync/migrations/201607151736_205f944640f6_add_session_to_livesyncqueueentry.py deleted file mode 100644 index b078a32..0000000 --- a/livesync/indico_livesync/migrations/201607151736_205f944640f6_add_session_to_livesyncqueueentry.py +++ /dev/null @@ -1,84 +0,0 @@ -"""Add session to LiveSyncQueueEntry - -Revision ID: 205f944640f6 -Revises: 230c086da074 -Create Date: 2016-07-15 17:36:12.702497 -""" - -import sqlalchemy as sa -from alembic import op - - -revision = '205f944640f6' -down_revision = '230c086da074' - - -def upgrade(): - op.add_column('queues', sa.Column('session_id', sa.Integer(), nullable=True), schema='plugin_livesync') - op.create_foreign_key(None, - 'queues', 'sessions', - ['session_id'], ['id'], - source_schema='plugin_livesync', referent_schema='events') - op.create_index(None, 'queues', ['session_id'], unique=False, schema='plugin_livesync') - - op.drop_constraint('ck_queues_valid_enum_type', 'queues', schema='plugin_livesync') - op.drop_constraint('ck_queues_valid_category_entry', 'queues', schema='plugin_livesync') - op.drop_constraint('ck_queues_valid_event_entry', 'queues', schema='plugin_livesync') - op.drop_constraint('ck_queues_valid_contribution_entry', 'queues', schema='plugin_livesync') - op.drop_constraint('ck_queues_valid_subcontribution_entry', 'queues', schema='plugin_livesync') - - op.create_check_constraint('valid_enum_type', 'queues', - 'type IN (1, 2, 3, 4, 5)', - schema='plugin_livesync') - op.create_check_constraint('valid_category_entry', 'queues', - 'type != 1 OR (contribution_id IS NULL AND event_id IS NULL AND session_id IS NULL AND ' - 'subcontribution_id IS NULL AND category_id IS NOT NULL)', - schema='plugin_livesync') - op.create_check_constraint('valid_event_entry', 'queues', - 'type != 2 OR (category_id IS NULL AND contribution_id IS NULL AND session_id IS NULL ' - 'AND subcontribution_id IS NULL AND event_id IS NOT NULL)', - schema='plugin_livesync') - op.create_check_constraint('valid_session_entry', 'queues', - 'type != 5 OR (category_id IS NULL AND contribution_id IS NULL AND event_id IS NULL ' - 'AND subcontribution_id IS NULL AND session_id IS NOT NULL)', - schema='plugin_livesync') - op.create_check_constraint('valid_contribution_entry', 'queues', - 'type != 3 OR (category_id IS NULL AND event_id IS NULL AND session_id IS NULL AND ' - 'subcontribution_id IS NULL AND contribution_id IS NOT NULL)', - schema='plugin_livesync') - op.create_check_constraint('valid_subcontribution_entry', 'queues', - 'type != 4 OR (category_id IS NULL AND contribution_id IS NULL AND event_id IS NULL AND ' - 'session_id IS NULL AND subcontribution_id IS NOT NULL)', - schema='plugin_livesync') - - -def downgrade(): - op.drop_constraint('ck_queues_valid_category_entry', 'queues', schema='plugin_livesync') - op.drop_constraint('ck_queues_valid_event_entry', 'queues', schema='plugin_livesync') - op.drop_constraint('ck_queues_valid_session_entry', 'queues', schema='plugin_livesync') - op.drop_constraint('ck_queues_valid_contribution_entry', 'queues', schema='plugin_livesync') - op.drop_constraint('ck_queues_valid_subcontribution_entry', 'queues', schema='plugin_livesync') - - op.drop_column('queues', 'session_id', schema='plugin_livesync') - - op.create_check_constraint('valid_category_entry', 'queues', - 'type != 1 OR (contribution_id IS NULL AND event_id IS NULL AND ' - 'subcontribution_id IS NULL AND category_id IS NOT NULL)', - schema='plugin_livesync') - op.create_check_constraint('valid_event_entry', 'queues', - 'type != 2 OR (category_id IS NULL AND contribution_id IS NULL AND ' - 'subcontribution_id IS NULL AND event_id IS NOT NULL)', - schema='plugin_livesync') - op.create_check_constraint('valid_contribution_entry', 'queues', - 'type != 3 OR (category_id IS NULL AND event_id IS NULL AND ' - 'subcontribution_id IS NULL AND contribution_id IS NOT NULL)', - schema='plugin_livesync') - op.create_check_constraint('valid_subcontribution_entry', 'queues', - 'type != 4 OR (category_id IS NULL AND contribution_id IS NULL AND ' - 'event_id IS NULL AND subcontribution_id IS NOT NULL)', - schema='plugin_livesync') - - op.drop_constraint('ck_queues_valid_enum_type', 'queues', schema='plugin_livesync') - op.create_check_constraint('valid_enum_type', 'queues', - 'type IN (1, 2, 3, 4)', - schema='plugin_livesync') diff --git a/livesync/indico_livesync/migrations/20170630_1557_aa0dbc6c14aa_create_tables.py b/livesync/indico_livesync/migrations/20170630_1557_aa0dbc6c14aa_create_tables.py new file mode 100644 index 0000000..03e071c --- /dev/null +++ b/livesync/indico_livesync/migrations/20170630_1557_aa0dbc6c14aa_create_tables.py @@ -0,0 +1,75 @@ +"""Create tables + +Revision ID: aa0dbc6c14aa +Revises: +Create Date: 2017-06-30 15:57:09.132083 +""" + +import sqlalchemy as sa +from alembic import op +from sqlalchemy.dialects import postgresql +from sqlalchemy.sql.ddl import CreateSchema, DropSchema + +from indico.core.db.sqlalchemy import PyIntEnum, UTCDateTime +from indico_livesync.models.queue import ChangeType, EntryType + + +# revision identifiers, used by Alembic. +revision = 'aa0dbc6c14aa' +down_revision = None +branch_labels = None +depends_on = None + + +def upgrade(): + op.execute(CreateSchema('plugin_livesync')) + op.create_table('agents', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('backend_name', sa.String(), nullable=False), + sa.Column('name', sa.String(), nullable=False), + sa.Column('initial_data_exported', sa.Boolean(), nullable=False), + sa.Column('last_run', UTCDateTime, nullable=False), + sa.Column('settings', postgresql.JSON(astext_type=sa.Text()), nullable=False), + sa.PrimaryKeyConstraint('id'), + schema='plugin_livesync') + op.create_table('queues', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('agent_id', sa.Integer(), nullable=False, index=True), + sa.Column('timestamp', UTCDateTime, nullable=False), + sa.Column('processed', sa.Boolean(), nullable=False), + sa.Column('change', PyIntEnum(ChangeType), nullable=False), + sa.Column('type', PyIntEnum(EntryType), nullable=False), + sa.Column('category_id', sa.Integer(), nullable=True, index=True), + sa.Column('event_id', sa.Integer(), nullable=True, index=True), + sa.Column('contribution_id', sa.Integer(), nullable=True, index=True), + sa.Column('session_id', sa.Integer(), nullable=True, index=True), + sa.Column('subcontribution_id', sa.Integer(), nullable=True, index=True), + sa.CheckConstraint('type != 1 OR (contribution_id IS NULL AND event_id IS NULL AND session_id ' + 'IS NULL AND subcontribution_id IS NULL AND category_id IS NOT NULL)', + name='valid_category_entry'), + sa.CheckConstraint('type != 2 OR (category_id IS NULL AND contribution_id IS NULL AND session_id ' + 'IS NULL AND subcontribution_id IS NULL AND event_id IS NOT NULL)', + name='valid_event_entry'), + sa.CheckConstraint('type != 3 OR (category_id IS NULL AND event_id IS NULL AND session_id ' + 'IS NULL AND subcontribution_id IS NULL AND contribution_id IS NOT NULL)', + name='valid_contribution_entry'), + sa.CheckConstraint('type != 4 OR (category_id IS NULL AND contribution_id IS NULL AND event_id ' + 'IS NULL AND session_id IS NULL AND subcontribution_id IS NOT NULL)', + name='valid_subcontribution_entry'), + sa.CheckConstraint('type != 5 OR (category_id IS NULL AND contribution_id IS NULL AND event_id ' + 'IS NULL AND subcontribution_id IS NULL AND session_id IS NOT NULL)', + name='valid_session_entry'), + sa.ForeignKeyConstraint(['agent_id'], ['plugin_livesync.agents.id']), + sa.ForeignKeyConstraint(['category_id'], ['categories.categories.id']), + sa.ForeignKeyConstraint(['contribution_id'], ['events.contributions.id']), + sa.ForeignKeyConstraint(['event_id'], ['events.events.id']), + sa.ForeignKeyConstraint(['session_id'], ['events.sessions.id']), + sa.ForeignKeyConstraint(['subcontribution_id'], ['events.subcontributions.id']), + sa.PrimaryKeyConstraint('id', name=op.f('pk_queues')), + schema='plugin_livesync') + + +def downgrade(): + op.drop_table('queues', schema='plugin_livesync') + op.drop_table('agents', schema='plugin_livesync') + op.execute(DropSchema('plugin_livesync')) diff --git a/vc_vidyo/indico_vc_vidyo/migrations/201503101359_3520616f8ff7_apply_naming_convention.py b/vc_vidyo/indico_vc_vidyo/migrations/201503101359_3520616f8ff7_apply_naming_convention.py deleted file mode 100644 index 87c4c3a..0000000 --- a/vc_vidyo/indico_vc_vidyo/migrations/201503101359_3520616f8ff7_apply_naming_convention.py +++ /dev/null @@ -1,39 +0,0 @@ -"""Apply naming convention - -Revision ID: 3520616f8ff7 -Revises: a702ad0bcea -Create Date: 2015-03-10 13:59:53.955083 -""" - -from alembic import op - -from indico.core.db.sqlalchemy.util.bulk_rename import bulk_rename - - -# revision identifiers, used by Alembic. -revision = '3520616f8ff7' -down_revision = 'a702ad0bcea' - - -mapping = { - 'plugin_vc_vidyo.vidyo_extensions': { - 'indexes': { - 'vidyo_extensions_pkey': 'pk_vidyo_extensions', - 'ix_plugin_vc_vidyo_vidyo_extensions_extension': 'ix_vidyo_extensions_extension', - 'ix_plugin_vc_vidyo_vidyo_extensions_owned_by_id': 'ix_vidyo_extensions_owned_by_id', - }, - 'constraints': { - 'vidyo_extensions_vc_room_id_fkey': 'fk_vidyo_extensions_vc_room_id_vc_rooms', - } - } -} - - -def upgrade(): - for stmt in bulk_rename(mapping): - op.execute(stmt) - - -def downgrade(): - for stmt in bulk_rename(mapping, True): - op.execute(stmt) diff --git a/vc_vidyo/indico_vc_vidyo/migrations/201505081934_3f376d68efc8_use_fk_for_owned_by_id_and_make_it_not_.py b/vc_vidyo/indico_vc_vidyo/migrations/201505081934_3f376d68efc8_use_fk_for_owned_by_id_and_make_it_not_.py deleted file mode 100644 index ed7d33e..0000000 --- a/vc_vidyo/indico_vc_vidyo/migrations/201505081934_3f376d68efc8_use_fk_for_owned_by_id_and_make_it_not_.py +++ /dev/null @@ -1,26 +0,0 @@ -"""Use FK for owned_by_id and make it NOT NULL - -Revision ID: 3f376d68efc8 -Revises: 3520616f8ff7 -Create Date: 2015-05-08 19:34:25.491411 -""" - -from alembic import op - - -# revision identifiers, used by Alembic. -revision = '3f376d68efc8' -down_revision = '3520616f8ff7' - - -def upgrade(): - op.alter_column('vidyo_extensions', 'owned_by_id', nullable=False, schema='plugin_vc_vidyo') - op.create_foreign_key(None, - 'vidyo_extensions', 'users', - ['owned_by_id'], ['id'], - source_schema='plugin_vc_vidyo', referent_schema='users') - - -def downgrade(): - op.drop_constraint('fk_vidyo_extensions_owned_by_id_users', 'vidyo_extensions', schema='plugin_vc_vidyo') - op.alter_column('vidyo_extensions', 'owned_by_id', nullable=True, schema='plugin_vc_vidyo') diff --git a/vc_vidyo/indico_vc_vidyo/migrations/201505131422_4ad9ccfb3d32_use_acl_settings.py b/vc_vidyo/indico_vc_vidyo/migrations/201505131422_4ad9ccfb3d32_use_acl_settings.py deleted file mode 100644 index 9008f7b..0000000 --- a/vc_vidyo/indico_vc_vidyo/migrations/201505131422_4ad9ccfb3d32_use_acl_settings.py +++ /dev/null @@ -1,30 +0,0 @@ -"""Use ACL settings - -Revision ID: 4ad9ccfb3d32 -Revises: 3f376d68efc8 -Create Date: 2015-05-13 14:22:09.748726 -""" - -from alembic import context - -from indico.core.db.sqlalchemy.util.convert_acl_settings import json_to_acl, acl_to_json - - -# revision identifiers, used by Alembic. -revision = '4ad9ccfb3d32' -down_revision = '3f376d68efc8' - - -acl_settings = {'plugin_vc_vidyo.managers', 'plugin_vc_vidyo.acl'} - - -def upgrade(): - if context.is_offline_mode(): - raise Exception('This upgrade is only possible in online mode') - json_to_acl(acl_settings) - - -def downgrade(): - if context.is_offline_mode(): - raise Exception('This downgrade is only possible in online mode') - acl_to_json(acl_settings) diff --git a/vc_vidyo/indico_vc_vidyo/migrations/201502191158_a702ad0bcea_create_extensions_table.py b/vc_vidyo/indico_vc_vidyo/migrations/20170630_1611_6019621fea50_create_tables.py similarity index 57% rename from vc_vidyo/indico_vc_vidyo/migrations/201502191158_a702ad0bcea_create_extensions_table.py rename to vc_vidyo/indico_vc_vidyo/migrations/20170630_1611_6019621fea50_create_tables.py index de60f66..acd5d1e 100644 --- a/vc_vidyo/indico_vc_vidyo/migrations/201502191158_a702ad0bcea_create_extensions_table.py +++ b/vc_vidyo/indico_vc_vidyo/migrations/20170630_1611_6019621fea50_create_tables.py @@ -1,8 +1,8 @@ -"""Create extensions table +"""Create tables -Revision ID: a702ad0bcea -Revises: None -Create Date: 2015-02-19 11:58:11.756966 +Revision ID: 6019621fea50 +Revises: +Create Date: 2017-06-30 16:11:31.486845 """ import sqlalchemy as sa @@ -12,21 +12,21 @@ from sqlalchemy.sql.ddl import CreateSchema, DropSchema # revision identifiers, used by Alembic. -revision = 'a702ad0bcea' +revision = '6019621fea50' down_revision = None +branch_labels = None +depends_on = None def upgrade(): op.execute(CreateSchema('plugin_vc_vidyo')) op.create_table('vidyo_extensions', sa.Column('vc_room_id', sa.Integer(), nullable=False), - sa.Column('extension', sa.BigInteger(), nullable=True), - sa.Column('owned_by_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['vc_room_id'], ['events.vc_rooms.id'], - name='vidyo_extensions_vc_room_id_fkey'), - sa.PrimaryKeyConstraint('vc_room_id', name='vidyo_extensions_pkey'), - sa.Index('ix_plugin_vc_vidyo_vidyo_extensions_extension', 'extension'), - sa.Index('ix_plugin_vc_vidyo_vidyo_extensions_owned_by_id', 'owned_by_id'), + sa.Column('extension', sa.BigInteger(), nullable=True, index=True), + sa.Column('owned_by_id', sa.Integer(), nullable=False, index=True), + sa.ForeignKeyConstraint(['owned_by_id'], ['users.users.id']), + sa.ForeignKeyConstraint(['vc_room_id'], ['events.vc_rooms.id']), + sa.PrimaryKeyConstraint('vc_room_id'), schema='plugin_vc_vidyo')