Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Link objects to reservation occurrences
- Loading branch information
Showing
18 changed files
with
232 additions
and
139 deletions.
There are no files selected for viewing
121 changes: 121 additions & 0 deletions
121
.../migrations/versions/20231222_1408_b37cbc4bb129_link_events_to_reservation_occurrences.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
"""Link events to reservation occurrences. | ||
Revision ID: b37cbc4bb129 | ||
Revises: e2b69fe5155d | ||
Create Date: 2023-12-22 14:08:45.669303 | ||
""" | ||
|
||
from enum import Enum | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
from indico.core.db.sqlalchemy import PyIntEnum | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'b37cbc4bb129' | ||
down_revision = 'e2b69fe5155d' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
class _LinkType(int, Enum): | ||
category = 1 | ||
event = 2 | ||
contribution = 3 | ||
subcontribution = 4 | ||
session = 5 | ||
session_block = 6 | ||
|
||
|
||
excluded_link_types = {_LinkType.category, _LinkType.subcontribution, _LinkType.session} | ||
|
||
|
||
def upgrade(): | ||
# Create reservation occurrence links | ||
op.create_table( | ||
'reservation_occurrence_links', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('link_type', PyIntEnum(_LinkType, exclude_values=excluded_link_types), nullable=False), | ||
sa.Column('event_id', sa.Integer(), nullable=True), | ||
sa.Column('linked_event_id', sa.Integer(), nullable=True), | ||
sa.Column('session_block_id', sa.Integer(), nullable=True), | ||
sa.Column('contribution_id', sa.Integer(), nullable=True), | ||
sa.PrimaryKeyConstraint('id'), | ||
sa.ForeignKeyConstraint(['contribution_id'], ['events.contributions.id']), | ||
sa.ForeignKeyConstraint(['event_id'], ['events.events.id']), | ||
sa.ForeignKeyConstraint(['linked_event_id'], ['events.events.id']), | ||
sa.ForeignKeyConstraint(['session_block_id'], ['events.session_blocks.id']), | ||
sa.CheckConstraint('(event_id IS NULL) = (link_type = 1)', name='valid_event_id'), | ||
sa.CheckConstraint('link_type != 2 ' | ||
'OR (contribution_id IS NULL AND session_block_id IS NULL AND linked_event_id IS NOT NULL)', | ||
name='valid_event_link'), | ||
sa.CheckConstraint('link_type != 3 ' | ||
'OR (linked_event_id IS NULL AND session_block_id IS NULL AND contribution_id IS NOT NULL)', | ||
name='valid_contribution_link'), | ||
sa.CheckConstraint('link_type != 6 ' | ||
'OR (contribution_id IS NULL AND linked_event_id IS NULL AND session_block_id IS NOT NULL)', | ||
name='valid_session_block_link'), | ||
schema='roombooking' | ||
) | ||
op.add_column('reservation_occurrences', sa.Column('link_id', sa.Integer(), nullable=True), schema='roombooking') | ||
op.create_foreign_key(None, 'reservation_occurrences', 'reservation_occurrence_links', ['link_id'], ['id'], | ||
source_schema='roombooking', referent_schema='roombooking') | ||
op.create_index(None, 'reservation_occurrence_links', ['contribution_id'], unique=False, schema='roombooking') | ||
op.create_index(None, 'reservation_occurrence_links', ['event_id'], unique=False, schema='roombooking') | ||
op.create_index(None, 'reservation_occurrence_links', ['linked_event_id'], unique=False, schema='roombooking') | ||
op.create_index(None, 'reservation_occurrence_links', ['session_block_id'], unique=False, schema='roombooking') | ||
op.create_index(None, 'reservation_occurrences', ['link_id'], unique=False, schema='roombooking') | ||
|
||
# Migrate data | ||
# TODO | ||
|
||
# Drop reservation links | ||
op.drop_index('ix_reservations_link_id', table_name='reservations', schema='roombooking') | ||
op.drop_constraint('fk_reservations_link_id_reservation_links', 'reservations', schema='roombooking') | ||
op.drop_table('reservation_links', schema='roombooking') | ||
op.drop_column('reservations', 'link_id', schema='roombooking') | ||
|
||
|
||
def downgrade(): | ||
# Recreate reservation links | ||
op.add_column('reservations', sa.Column('link_id', sa.INTEGER(), nullable=True), | ||
schema='roombooking') | ||
op.create_foreign_key(None, 'reservations', 'reservation_links', ['link_id'], ['id'], | ||
source_schema='roombooking', referent_schema='roombooking') | ||
op.create_table( | ||
'reservation_links', | ||
sa.Column('id', sa.INTEGER(), nullable=False), | ||
sa.Column('link_type', sa.SMALLINT(), nullable=False), | ||
sa.Column('event_id', sa.INTEGER(), nullable=True), | ||
sa.Column('linked_event_id', sa.INTEGER(), nullable=True), | ||
sa.Column('session_block_id', sa.INTEGER(), nullable=True), | ||
sa.Column('contribution_id', sa.INTEGER(), nullable=True), | ||
sa.PrimaryKeyConstraint('id'), | ||
sa.ForeignKeyConstraint(['contribution_id'], ['events.contributions.id']), | ||
sa.ForeignKeyConstraint(['event_id'], ['events.events.id']), | ||
sa.ForeignKeyConstraint(['linked_event_id'], ['events.events.id']), | ||
sa.ForeignKeyConstraint(['session_block_id'], ['events.session_blocks.id']), | ||
sa.CheckConstraint('(event_id IS NULL) = (link_type = 1)', name='valid_event_id'), | ||
sa.CheckConstraint('(link_type <> 2) ' | ||
'OR (contribution_id IS NULL AND session_block_id IS NULL AND linked_event_id IS NOT NULL)', | ||
name='valid_event_link'), | ||
sa.CheckConstraint('(link_type <> 3) ' | ||
'OR (linked_event_id IS NULL AND session_block_id IS NULL AND contribution_id IS NOT NULL)', | ||
name='valid_contribution_link'), | ||
sa.CheckConstraint('(link_type <> 6) ' | ||
'OR (contribution_id IS NULL AND linked_event_id IS NULL AND session_block_id IS NOT NULL)', | ||
name='valid_session_block_link'), | ||
schema='roombooking' | ||
) | ||
|
||
# Migrate data | ||
# TODO | ||
|
||
# Drop reservation occurrence links | ||
op.drop_index('ix_reservation_occurrences_link_id', table_name='reservation_occurrences', schema='roombooking') | ||
op.drop_constraint('fk_reservation_occurrences_link_id_reservation_occurrence_links', 'reservation_occurrences', | ||
schema='roombooking') | ||
op.drop_column('reservation_occurrences', 'link_id', schema='roombooking') | ||
op.drop_table('reservation_occurrence_links', schema='roombooking') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.