def upgrade(): op.create_table('logs', sa.Column('id', sa.Integer(), nullable=False), sa.Column('logged_dt', UTCDateTime, nullable=False), sa.Column('kind', PyIntEnum(_LogKind), nullable=False), sa.Column('module', sa.String(), nullable=False), sa.Column('type', sa.String(), nullable=False), sa.Column('summary', sa.String(), nullable=False), sa.Column('data', postgresql.JSON(astext_type=sa.Text()), nullable=False), sa.Column('meta', postgresql.JSONB(astext_type=sa.Text()), nullable=False), sa.Column('category_id', sa.Integer(), nullable=False, index=True), sa.Column('realm', PyIntEnum(_CategoryLogRealm), nullable=False), sa.Column('user_id', sa.Integer(), nullable=True, index=True), sa.ForeignKeyConstraint(['category_id'], ['categories.categories.id']), sa.ForeignKeyConstraint(['user_id'], ['users.users.id']), sa.PrimaryKeyConstraint('id'), schema='categories') op.create_index(None, 'logs', ['meta'], unique=False, schema='categories', postgresql_using='gin')
def upgrade(): op.execute(CreateSchema('plugin_cern_access')) op.create_table( 'access_requests', sa.Column('registration_id', sa.Integer(), nullable=False), sa.Column('request_state', PyIntEnum(CERNAccessRequestState), nullable=False), sa.Column('reservation_code', sa.String(), nullable=False), sa.Column('birth_place', sa.String(), nullable=True), sa.Column('nationality', sa.String(), nullable=True), sa.Column('birth_date', sa.Date(), nullable=True), sa.ForeignKeyConstraint(['registration_id'], ['event_registration.registrations.id']), sa.PrimaryKeyConstraint('registration_id'), schema='plugin_cern_access') op.create_table('access_request_regforms', sa.Column('form_id', sa.Integer(), nullable=False), sa.Column('request_state', PyIntEnum(CERNAccessRequestState), nullable=False), sa.ForeignKeyConstraint(['form_id'], ['event_registration.forms.id']), sa.PrimaryKeyConstraint('form_id'), schema='plugin_cern_access')
def upgrade(): markdown_mode = str(RenderMode.markdown.value) print 'Adding render_mode column to (sub-)contributions - this may take some time!' op.add_column('contributions', sa.Column('render_mode', PyIntEnum(RenderMode), server_default=markdown_mode, nullable=False), schema='events') op.add_column('subcontributions', sa.Column('render_mode', PyIntEnum(RenderMode), server_default=markdown_mode, nullable=False), schema='events') op.alter_column('contributions', 'render_mode', server_default=None, schema='events') op.alter_column('subcontributions', 'render_mode', server_default=None, schema='events') # set legacy (sub-)contributions with a description to 'html' print 'Updating legacy (sub-)contributions - this may take some time!' op.execute(""" CREATE TEMP TABLE html_contribs ON COMMIT DROP AS ( SELECT id FROM events.contributions c WHERE description != '' AND EXISTS (SELECT 1 FROM events.legacy_contribution_id_map WHERE contribution_id = c.id) ); CREATE TEMP TABLE html_subcontribs ON COMMIT DROP AS ( SELECT id FROM events.subcontributions sc WHERE description != '' AND EXISTS (SELECT 1 FROM events.legacy_subcontribution_id_map WHERE subcontribution_id = sc.id) ); """) op.execute(""" UPDATE events.contributions c SET render_mode = {0:d} FROM html_contribs hc WHERE hc.id = c.id; UPDATE events.subcontributions sc SET render_mode = {0:d} FROM html_subcontribs hs WHERE hs.id = sc.id; """.format(RenderMode.html.value)) # support all render modes for notes op.drop_constraint('ck_note_revisions_valid_enum_render_mode', 'note_revisions', schema='events') op.create_check_constraint('valid_enum_render_mode', 'note_revisions', 'render_mode IN (1, 2, 3)', schema='events')
def upgrade(): op.rename_table('payment_transactions', 'payment_transactions_old', schema='events') op.execute( _rename_constraint('events', 'payment_transactions_old', 'pk_payment_transactions', 'pk_payment_transactions_old')) op.execute( "ALTER SEQUENCE events.payment_transactions_id_seq RENAME TO payment_transactions_old_id_seq" ) op.create_table( 'payment_transactions', sa.Column('id', sa.Integer(), nullable=False), sa.Column('registration_id', sa.Integer(), nullable=False, index=True), sa.Column('status', PyIntEnum(TransactionStatus), nullable=False), sa.Column('amount', sa.Numeric(precision=8, scale=2), nullable=False), sa.Column('currency', sa.String(), nullable=False), sa.Column('provider', sa.String(), nullable=False), sa.Column('timestamp', UTCDateTime, nullable=False), sa.Column('data', postgresql.JSON(), nullable=False), sa.CheckConstraint('amount > 0', name='positive_amount'), sa.ForeignKeyConstraint(['registration_id'], ['event_registration.registrations.id']), sa.PrimaryKeyConstraint('id'), schema='events') op.create_foreign_key(None, 'registrations', 'payment_transactions', ['transaction_id'], ['id'], source_schema='event_registration', referent_schema='events')
def upgrade(): op.create_table('agreements', sa.Column('id', sa.Integer(), nullable=False), sa.Column('uuid', sa.String(), nullable=False), sa.Column('type', sa.String(), nullable=False), sa.Column('event_id', sa.Integer(), nullable=False), sa.Column('identifier', sa.String(), nullable=False), sa.Column('person_email', sa.String(), nullable=False), sa.Column('person_name', sa.String(), nullable=False), sa.Column('state', PyIntEnum(AgreementState), nullable=False), sa.Column('timestamp', UTCDateTime, nullable=False), sa.Column('user_id', sa.Integer(), nullable=True), sa.Column('signed_dt', UTCDateTime, nullable=True), sa.Column('signed_from_ip', sa.String(), nullable=True), sa.Column('reason', sa.String(), nullable=True), sa.Column('attachment', sa.LargeBinary(), nullable=True), sa.Column('attachment_filename', sa.String(), nullable=True), sa.Column('data', postgresql.JSON(), nullable=True), sa.UniqueConstraint('event_id', 'type', 'identifier'), sa.PrimaryKeyConstraint('id'), schema='events')
def upgrade(): if context.is_offline_mode(): raise Exception('This upgrade is only possible in online mode') conn = op.get_bind() op.add_column('blocking_principals', sa.Column('local_group_id', sa.Integer(), nullable=True), schema='roombooking') op.add_column('blocking_principals', sa.Column('mp_group_name', sa.String(), nullable=True), schema='roombooking') op.add_column('blocking_principals', sa.Column('mp_group_provider', sa.String(), nullable=True), schema='roombooking') op.add_column('blocking_principals', sa.Column('type', PyIntEnum(PrincipalType), nullable=True), schema='roombooking') op.add_column('blocking_principals', sa.Column('user_id', sa.Integer(), nullable=True), schema='roombooking') res = conn.execute("SELECT id, principal FROM roombooking.blocking_principals") for id_, principal in res: args = _principal_to_args(principal) conn.execute("UPDATE roombooking.blocking_principals SET type = %s, user_id = %s, local_group_id = %s, " "mp_group_provider = %s, mp_group_name = %s WHERE id = %s", args + (id_,)) op.drop_column('blocking_principals', 'principal', schema='roombooking') op.create_index(None, 'blocking_principals', ['local_group_id'], schema='roombooking') op.create_index(None, 'blocking_principals', ['user_id'], schema='roombooking') op.create_foreign_key(None, 'blocking_principals', 'users', ['user_id'], ['id'], source_schema='roombooking', referent_schema='users') op.create_foreign_key(None, 'blocking_principals', 'groups', ['local_group_id'], ['id'], source_schema='roombooking', referent_schema='users')
class PaperReviewQuestion(ReviewQuestionMixin, db.Model): __tablename__ = 'review_questions' __table_args__ = {'schema': 'event_paper_reviewing'} event_backref_name = 'paper_review_questions' type = db.Column(PyIntEnum(PaperReviewType), nullable=False)
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'))
class AbstractPersonLink(PersonLinkBase): """Association between EventPerson and Abstract.""" __tablename__ = 'abstract_person_links' __auto_table_args = {'schema': 'event_abstracts'} person_link_backref_name = 'abstract_links' person_link_unique_columns = ('abstract_id', ) object_relationship_name = 'abstract' abstract_id = db.Column(db.Integer, db.ForeignKey('event_abstracts.abstracts.id'), index=True, nullable=False) is_speaker = db.Column(db.Boolean, nullable=False, default=False) author_type = db.Column(PyIntEnum(AuthorType), nullable=False, default=AuthorType.none) # relationship backrefs: # - abstract (Abstract.person_links) @locator_property def locator(self): return dict(self.abstract.locator, person_id=self.id) @return_ascii def __repr__(self): return format_repr(self, 'id', 'person_id', 'abstract_id', is_speaker=False, author_type=None, _text=self.full_name)
def upgrade(): op.create_table( 'review_conditions', sa.Column('id', sa.Integer(), nullable=False), sa.Column('type', PyIntEnum(EditableType), nullable=False), sa.Column('event_id', sa.Integer(), nullable=False, index=True), sa.ForeignKeyConstraint(['event_id'], ['events.events.id']), sa.PrimaryKeyConstraint('id'), schema='event_editing', ) op.create_table( 'review_condition_file_types', sa.Column('review_condition_id', sa.Integer(), autoincrement=False, nullable=False, index=True), sa.Column('file_type_id', sa.Integer(), autoincrement=False, nullable=False, index=True), sa.ForeignKeyConstraint( ['file_type_id'], ['event_editing.file_types.id'], ), sa.ForeignKeyConstraint( ['review_condition_id'], ['event_editing.review_conditions.id'], ), sa.PrimaryKeyConstraint('review_condition_id', 'file_type_id'), schema='event_editing', )
class EditingReviewCondition(db.Model): __tablename__ = 'review_conditions' __table_args__ = {'schema': 'event_editing'} id = db.Column(db.Integer, primary_key=True) type = db.Column(PyIntEnum(EditableType), nullable=False) event_id = db.Column(db.Integer, db.ForeignKey('events.events.id'), index=True, nullable=False) event = db.relationship('Event', lazy=True, backref=db.backref('editing_review_conditions', cascade='all, delete-orphan', lazy=True)) file_types = db.relationship( 'EditingFileType', secondary='event_editing.review_condition_file_types', collection_class=set, lazy=False, backref=db.backref('review_conditions', collection_class=set, lazy=True)) # relationship backrefs: # - file_types (EditingFileType.review_conditions) def __repr__(self): return format_repr(self, 'id', 'event_id')
def protection_mode(cls): if not cls.disable_protection_mode: return db.Column( PyIntEnum(ProtectionMode, exclude_values=cls.disallowed_protection_modes), nullable=False, default=cls.default_protection_mode)
def _mappers_configured(): from .revisions import EditingRevision, InitialRevisionState, FinalRevisionState # Editable.state -- the state of the editable itself cases = db.cast(db.case({ FinalRevisionState.none: db.case({ InitialRevisionState.new: EditableState.new, InitialRevisionState.ready_for_review: EditableState.ready_for_review, InitialRevisionState.needs_submitter_confirmation: EditableState.needs_submitter_confirmation }, value=EditingRevision.initial_state), # the states resulting in None are always followed by another revision, so we don't ever # expect the latest revision of an editable to have such a state FinalRevisionState.replaced: None, FinalRevisionState.needs_submitter_confirmation: None, FinalRevisionState.needs_submitter_changes: EditableState.needs_submitter_changes, FinalRevisionState.accepted: EditableState.accepted, FinalRevisionState.rejected: EditableState.rejected, }, value=EditingRevision.final_state), PyIntEnum(EditableState)) query = (select([cases]) .where(EditingRevision.editable_id == Editable.id) .order_by(EditingRevision.created_dt.desc()) .limit(1) .correlate_except(EditingRevision)) Editable.state = column_property(query) # Editable.revision_count -- the number of revisions the editable has query = (select([db.func.count(EditingRevision.id)]) .where(EditingRevision.editable_id == Editable.id) .correlate_except(EditingRevision)) Editable.revision_count = column_property(query)
class PaperReviewingRole(db.Model): """Represents a role a user performs regarding a particular contribution.""" __tablename__ = 'contribution_roles' __table_args__ = {'schema': 'event_paper_reviewing'} id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('users.users.id'), nullable=False, index=True) contribution_id = db.Column(db.Integer, db.ForeignKey('events.contributions.id'), index=True, nullable=False) role = db.Column(PyIntEnum(PaperReviewingRoleType), nullable=False, index=True) contribution = db.relationship('Contribution', lazy=False, backref=db.backref('paper_reviewing_roles', lazy=True)) user = db.relationship('User', lazy=False, backref=db.backref('paper_reviewing_roles', lazy='dynamic')) @return_ascii def __repr__(self): return format_repr(self, 'id', user_id=self.user_id, contribution_id=self.contribution_id)
class StaticSite(db.Model): """Static site for an Indico event.""" __tablename__ = 'static_sites' __table_args__ = {'schema': 'events'} #: Entry ID id = db.Column(db.Integer, primary_key=True) #: ID of the event event_id = db.Column(db.Integer, db.ForeignKey('events.events.id'), index=True, nullable=False) #: The state of the static site (a :class:`StaticSiteState` member) state = db.Column(PyIntEnum(StaticSiteState), default=StaticSiteState.pending, nullable=False) #: The date and time the static site was requested requested_dt = db.Column(UTCDateTime, default=now_utc, nullable=False) #: path to the zip archive of the static site path = db.Column(db.String, nullable=True) #: ID of the user who created the static site creator_id = db.Column(db.Integer, db.ForeignKey('users.users.id'), index=True, nullable=False) #: The user who created the static site creator = db.relationship('User', lazy=False, backref=db.backref('static_sites', lazy='dynamic')) #: The Event this static site is associated with event_new = db.relationship('Event', lazy=True, backref=db.backref('static_sites', lazy='dynamic')) @property def locator(self): return {'confId': self.event_id, 'id': self.id} def delete_file(self): if not self.path: return try: os.remove(self.path) except OSError as err: if err.errno != errno.ENOENT: raise def __committed__(self, change): super(StaticSite, self).__committed__(change) if change == 'delete': self.delete_file() @return_ascii def __repr__(self): state = self.state.name if self.state is not None else None return '<StaticSite({}, {}, {})>'.format(self.id, self.event_id, state)
def upgrade(): op.add_column('events', sa.Column('type', PyIntEnum(EventType), nullable=False, server_default=str(EventType.meeting.value)), schema='events') op.alter_column('events', 'type', server_default=None, schema='events')
def upgrade(): # Break op.create_table( 'breaks', sa.Column('id', sa.Integer(), nullable=False), sa.Column('title', sa.String(), nullable=False), sa.Column('description', sa.Text(), nullable=False), sa.Column('duration', sa.Interval(), nullable=False), sa.Column('text_color', sa.String(), nullable=False), sa.Column('background_color', sa.String(), nullable=False), sa.Column('room_name', sa.String(), nullable=False), sa.Column('inherit_location', sa.Boolean(), nullable=False), sa.Column('address', sa.Text(), nullable=False), sa.Column('venue_id', sa.Integer(), nullable=True, index=True), sa.Column('venue_name', sa.String(), nullable=False), sa.Column('room_id', sa.Integer(), nullable=True, index=True), sa.CheckConstraint("(room_id IS NULL) OR (venue_name = '' AND room_name = '')", name='no_custom_location_if_room'), sa.CheckConstraint("(venue_id IS NULL) OR (venue_name = '')", name='no_venue_name_if_venue_id'), sa.CheckConstraint("(room_id IS NULL) OR (venue_id IS NOT NULL)", name='venue_id_if_room_id'), sa.CheckConstraint("NOT inherit_location OR (venue_id IS NULL AND room_id IS NULL AND venue_name = '' AND " "room_name = '' AND address = '')", name='inherited_location'), sa.CheckConstraint("(text_color = '') = (background_color = '')", name='both_or_no_colors'), sa.CheckConstraint("text_color != '' AND background_color != ''", name='colors_not_empty'), sa.ForeignKeyConstraint(['room_id'], ['roombooking.rooms.id']), sa.ForeignKeyConstraint(['venue_id'], ['roombooking.locations.id']), sa.ForeignKeyConstraint(['venue_id', 'room_id'], ['roombooking.rooms.location_id', 'roombooking.rooms.id']), sa.PrimaryKeyConstraint('id'), schema='events' ) # TimetableEntry op.create_table( 'timetable_entries', sa.Column('id', sa.Integer(), nullable=False), sa.Column('event_id', sa.Integer(), nullable=False, index=True), sa.Column('parent_id', sa.Integer(), nullable=True, index=True), sa.Column('session_block_id', sa.Integer(), nullable=True, index=True, unique=True), sa.Column('contribution_id', sa.Integer(), nullable=True, index=True, unique=True), sa.Column('break_id', sa.Integer(), nullable=True, index=True, unique=True), sa.Column('type', PyIntEnum(TimetableEntryType), nullable=False), sa.Column('start_dt', UTCDateTime, nullable=False), sa.Index('ix_timetable_entries_start_dt_desc', sa.text('start_dt DESC')), sa.CheckConstraint('type != 1 OR parent_id IS NULL', name='valid_parent'), sa.CheckConstraint('type != 1 OR (contribution_id IS NULL AND break_id IS NULL AND ' 'session_block_id IS NOT NULL)', name='valid_session_block'), sa.CheckConstraint('type != 2 OR (session_block_id IS NULL AND break_id IS NULL AND ' 'contribution_id IS NOT NULL)', name='valid_contribution'), sa.CheckConstraint('type != 3 OR (contribution_id IS NULL AND session_block_id IS NULL AND ' 'break_id IS NOT NULL)', name='valid_break'), sa.ForeignKeyConstraint(['break_id'], ['events.breaks.id']), sa.ForeignKeyConstraint(['contribution_id'], ['events.contributions.id']), sa.ForeignKeyConstraint(['event_id'], ['events.events.id']), sa.ForeignKeyConstraint(['parent_id'], ['events.timetable_entries.id']), sa.ForeignKeyConstraint(['session_block_id'], ['events.session_blocks.id']), sa.PrimaryKeyConstraint('id'), schema='events' )
def upgrade(): op.add_column('forms', sa.Column('publish_registrations_public', PyIntEnum(_PublishRegistrationsMode), server_default='0', nullable=False), schema='event_registration') op.alter_column('forms', 'publish_registrations_public', server_default=None, schema='event_registration') op.execute( 'UPDATE event_registration.forms SET publish_registrations_public = 2 WHERE publish_registrations_enabled' ) op.add_column('forms', sa.Column('publish_registrations_participants', PyIntEnum(_PublishRegistrationsMode), server_default='0', nullable=False), schema='event_registration') op.alter_column('forms', 'publish_registrations_participants', server_default=None, schema='event_registration') op.execute( 'UPDATE event_registration.forms SET publish_registrations_participants = 2 WHERE publish_registrations_enabled' ) op.drop_column('forms', 'publish_registrations_enabled', schema='event_registration') op.create_check_constraint( 'publish_registrations_more_restrictive_to_public', 'forms', 'publish_registrations_public <= publish_registrations_participants', schema='event_registration') op.add_column('registrations', sa.Column('consent_to_publish', PyIntEnum(_PublishConsentType), server_default='2', nullable=False), schema='event_registration') op.alter_column('registrations', 'consent_to_publish', server_default=None, schema='event_registration')
def upgrade(): op.create_table( 'event_move_requests', sa.Column('id', sa.Integer(), nullable=False), sa.Column('event_id', sa.Integer(), nullable=False, index=True), sa.Column('category_id', sa.Integer(), nullable=False, index=True), sa.Column('requestor_id', sa.Integer(), nullable=False, index=True), sa.Column('state', PyIntEnum(_MoveRequestState), nullable=False), sa.Column('requestor_comment', sa.String(), nullable=False, default=''), sa.Column('moderator_comment', sa.String(), nullable=False, default=''), sa.Column('moderator_id', sa.Integer(), nullable=True), sa.Column('requested_dt', UTCDateTime, nullable=False), sa.CheckConstraint( '(state in (1, 2) AND moderator_id IS NOT NULL) OR moderator_id IS NULL', name='moderator_state'), sa.ForeignKeyConstraint(['category_id'], ['categories.categories.id']), sa.ForeignKeyConstraint(['event_id'], ['events.events.id']), sa.ForeignKeyConstraint(['moderator_id'], ['users.users.id']), sa.ForeignKeyConstraint(['requestor_id'], ['users.users.id']), sa.PrimaryKeyConstraint('id'), schema='categories') op.create_index(None, 'event_move_requests', ['event_id'], unique=True, schema='categories', postgresql_where=sa.text('state = 0')) op.add_column('categories', sa.Column('event_creation_mode', PyIntEnum(_EventCreationMode), nullable=False, server_default='1'), schema='categories') op.alter_column('categories', 'event_creation_mode', server_default=None, schema='categories') op.execute( 'UPDATE categories.categories SET event_creation_mode = 3 WHERE NOT event_creation_restricted' ) op.drop_column('categories', 'event_creation_restricted', schema='categories')
def upgrade(): op.execute(CreateSchema('users')) op.create_table('users', sa.Column('id', sa.Integer(), nullable=False), sa.Column('first_name', sa.String(), nullable=False, index=True), sa.Column('last_name', sa.String(), nullable=False, index=True), sa.Column('title', PyIntEnum(UserTitle), nullable=False), sa.Column('phone', sa.String(), nullable=False), sa.Column('affiliation', sa.String(), nullable=False, index=True), sa.Column('address', sa.Text(), nullable=False), sa.Column('merged_into_id', sa.Integer(), nullable=True), sa.Column('is_admin', sa.Boolean(), nullable=False, index=True), sa.Column('is_blocked', sa.Boolean(), nullable=False), sa.Column('is_deleted', sa.Boolean(), nullable=False), sa.Column('is_pending', sa.Boolean(), nullable=False), sa.ForeignKeyConstraint(['merged_into_id'], ['users.users.id']), sa.PrimaryKeyConstraint('id'), schema='users') op.create_table('emails', sa.Column('id', sa.Integer(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=False, index=True), sa.Column('email', sa.String(), nullable=False, index=True), sa.Column('is_primary', sa.Boolean(), nullable=False), sa.Column('is_user_deleted', sa.Boolean(), nullable=False), sa.CheckConstraint('email = lower(email)', name='lowercase_email'), sa.ForeignKeyConstraint(['user_id'], ['users.users.id']), sa.PrimaryKeyConstraint('id'), schema='users') op.create_index(None, 'emails', ['email'], unique=True, schema='users', postgresql_where=sa.text('NOT is_user_deleted')) op.create_index( None, 'emails', ['user_id'], unique=True, schema='users', postgresql_where=sa.text('is_primary AND NOT is_user_deleted'))
def render_mode(cls): # Only add the column if there's a choice # between several alternatives if len(cls.possible_render_modes) > 1: return db.Column(PyIntEnum(RenderMode), default=cls.default_render_mode, nullable=False) else: return cls.default_render_mode
def type(cls): exclude_values = set() if not cls.allow_emails: exclude_values.add(PrincipalType.email) if not cls.allow_networks: exclude_values.add(PrincipalType.network) return db.Column(PyIntEnum(PrincipalType, exclude_values=(exclude_values or None)), nullable=False)
def upgrade(): op.create_table( 'principals', sa.Column('mp_group_provider', sa.String(), nullable=True), sa.Column('mp_group_name', sa.String(), nullable=True), sa.Column('read_access', sa.Boolean(), nullable=False), sa.Column('full_access', sa.Boolean(), nullable=False), sa.Column('roles', postgresql.ARRAY(sa.String()), nullable=False), sa.Column('id', sa.Integer(), nullable=False), sa.Column('event_id', sa.Integer(), nullable=False, index=True), sa.Column('user_id', sa.Integer(), nullable=True, index=True), sa.Column('local_group_id', sa.Integer(), nullable=True, index=True), sa.Column('type', PyIntEnum(PrincipalType), nullable=True), sa.Column('email', sa.String(), nullable=True, index=True), sa.Index('ix_uq_principals_user', 'user_id', 'event_id', unique=True, postgresql_where=sa.text('type = 1')), sa.Index('ix_uq_principals_local_group', 'local_group_id', 'event_id', unique=True, postgresql_where=sa.text('type = 2')), sa.Index('ix_uq_principals_mp_group', 'mp_group_provider', 'mp_group_name', 'event_id', unique=True, postgresql_where=sa.text('type = 3')), sa.Index('ix_uq_principals_email', 'email', 'event_id', unique=True, postgresql_where=sa.text('type = 4')), sa.CheckConstraint('type != 1 OR (local_group_id IS NULL AND mp_group_provider IS NULL AND email IS NULL AND ' 'mp_group_name IS NULL AND user_id IS NOT NULL)', name='valid_user'), sa.CheckConstraint('type != 2 OR (user_id IS NULL AND mp_group_provider IS NULL AND email IS NULL AND ' 'mp_group_name IS NULL AND local_group_id IS NOT NULL)', name='valid_local_group'), sa.CheckConstraint('type != 3 OR (local_group_id IS NULL AND user_id IS NULL AND email IS NULL AND ' 'mp_group_provider IS NOT NULL AND mp_group_name IS NOT NULL)', name='valid_multipass_group'), sa.CheckConstraint('type != 4 OR (local_group_id IS NULL AND mp_group_provider IS NULL AND ' 'mp_group_name IS NULL AND user_id IS NULL AND email IS NOT NULL)', name='valid_email'), sa.CheckConstraint('email IS NULL OR email = lower(email)', name='lowercase_email'), sa.CheckConstraint('read_access OR full_access OR array_length(roles, 1) IS NOT NULL', name='has_privs'), sa.ForeignKeyConstraint(['event_id'], ['events.events.id']), sa.ForeignKeyConstraint(['local_group_id'], ['users.groups.id']), sa.ForeignKeyConstraint(['user_id'], ['users.users.id']), sa.PrimaryKeyConstraint('id'), schema='events' ) op.create_index(None, 'principals', ['mp_group_provider', 'mp_group_name'], schema='events') op.add_column('events', sa.Column('protection_mode', PyIntEnum(ProtectionMode), nullable=False, server_default=str(ProtectionMode.inheriting.value)), schema='events') op.alter_column('events', 'protection_mode', server_default=None, schema='events')
def upgrade(): if context.is_offline_mode(): raise Exception('This upgrade is only possible in online mode') op.create_table( 'room_principals', sa.Column('read_access', sa.Boolean(), nullable=False), sa.Column('full_access', sa.Boolean(), nullable=False), sa.Column('permissions', postgresql.ARRAY(sa.String()), nullable=False), sa.Column('id', sa.Integer(), nullable=False), sa.Column('room_id', sa.Integer(), nullable=False, index=True), sa.Column('local_group_id', sa.Integer(), nullable=True, index=True), sa.Column('mp_group_provider', sa.String(), nullable=True), sa.Column('mp_group_name', sa.String(), nullable=True), sa.Column('user_id', sa.Integer(), nullable=True, index=True), sa.Column('type', PyIntEnum(PrincipalType, exclude_values={PrincipalType.email, PrincipalType.network, PrincipalType.event_role}), nullable=False), sa.CheckConstraint('NOT read_access', name='no_read_access'), sa.CheckConstraint('read_access OR full_access OR array_length(permissions, 1) IS NOT NULL', name='has_privs'), sa.CheckConstraint('type != 1 OR (local_group_id IS NULL AND mp_group_name IS NULL AND ' 'mp_group_provider IS NULL AND user_id IS NOT NULL)', name='valid_user'), sa.CheckConstraint('type != 2 OR (mp_group_name IS NULL AND mp_group_provider IS NULL AND user_id IS NULL AND ' 'local_group_id IS NOT NULL)', name='valid_local_group'), sa.CheckConstraint('type != 3 OR (local_group_id IS NULL AND user_id IS NULL AND mp_group_name IS NOT NULL AND ' 'mp_group_provider IS NOT NULL)', name='valid_multipass_group'), sa.ForeignKeyConstraint(['local_group_id'], ['users.groups.id']), sa.ForeignKeyConstraint(['room_id'], ['roombooking.rooms.id']), sa.ForeignKeyConstraint(['user_id'], ['users.users.id']), sa.PrimaryKeyConstraint('id'), schema='roombooking' ) op.create_index(None, 'room_principals', ['mp_group_provider', 'mp_group_name'], schema='roombooking') op.create_index('ix_uq_room_principals_user', 'room_principals', ['user_id', 'room_id'], unique=True, schema='roombooking', postgresql_where=sa.text('type = 1')) op.create_index('ix_uq_room_principals_local_group', 'room_principals', ['local_group_id', 'room_id'], unique=True, schema='roombooking', postgresql_where=sa.text('type = 2')) op.create_index('ix_uq_room_principals_mp_group', 'room_principals', ['mp_group_provider', 'mp_group_name', 'room_id'], unique=True, schema='roombooking', postgresql_where=sa.text('type = 3')) op.add_column('rooms', sa.Column('protection_mode', PyIntEnum(ProtectionMode, exclude_values={ProtectionMode.inheriting}), nullable=False, server_default=unicode(ProtectionMode.protected.value)), schema='roombooking') _upgrade_permissions() op.alter_column('rooms', 'protection_mode', server_default=None, schema='roombooking')
def upgrade(): op.add_column('contribution_fields', sa.Column('is_user_editable', sa.Boolean(), nullable=False, server_default='true'), schema='events') op.add_column('contribution_fields', sa.Column('visibility', PyIntEnum(ContributionFieldVisibility), nullable=False, server_default='1'), schema='events') op.alter_column('contribution_fields', 'is_user_editable', server_default=None, schema='events') op.alter_column('contribution_fields', 'visibility', server_default=None, schema='events')
class Editable(db.Model): __tablename__ = 'editables' __table_args__ = (db.UniqueConstraint('contribution_id', 'type'), { 'schema': 'event_editing' }) id = db.Column(db.Integer, primary_key=True) contribution_id = db.Column(db.ForeignKey('events.contributions.id'), index=True, nullable=False) type = db.Column(PyIntEnum(EditableType), nullable=False) editor_id = db.Column(db.ForeignKey('users.users.id'), index=True, nullable=True) published_revision_id = db.Column( db.ForeignKey('event_editing.revisions.id'), index=True, nullable=True) contribution = db.relationship('Contribution', lazy=True, backref=db.backref( 'editables', lazy=True, )) editor = db.relationship('User', lazy=True, backref=db.backref('editor_for_editables', lazy='dynamic')) published_revision = db.relationship( 'EditingRevision', foreign_keys=published_revision_id, lazy=True, ) # relationship backrefs: # - revisions (EditingRevision.editable) @return_ascii def __repr__(self): return format_repr(self, 'id', 'contribution_id', 'type') # TODO: state - either a column property referencing the newest revision's state or a normal column @locator_property def locator(self): return dict(self.contribution.locator, type=self.type.name) @property def event(self): return self.contribution.event def can_comment(self, user): return (self.event.can_manage(user, permission='paper_editing') or self.contribution.is_user_associated(user, check_abstract=True))
class StaticSite(StoredFileMixin, db.Model): """Static site for an Indico event.""" __tablename__ = 'static_sites' __table_args__ = {'schema': 'events'} # StoredFileMixin settings add_file_date_column = False file_required = False #: Entry ID id = db.Column(db.Integer, primary_key=True) #: ID of the event event_id = db.Column(db.Integer, db.ForeignKey('events.events.id'), index=True, nullable=False) #: The state of the static site (a :class:`StaticSiteState` member) state = db.Column(PyIntEnum(StaticSiteState), default=StaticSiteState.pending, nullable=False) #: The date and time the static site was requested requested_dt = db.Column(UTCDateTime, default=now_utc, nullable=False) #: ID of the user who created the static site creator_id = db.Column(db.Integer, db.ForeignKey('users.users.id'), index=True, nullable=False) #: The user who created the static site creator = db.relationship('User', lazy=False, backref=db.backref('static_sites', lazy='dynamic')) #: The Event this static site is associated with event_new = db.relationship('Event', lazy=True, backref=db.backref('static_sites', lazy='dynamic')) @property def locator(self): return {'confId': self.event_id, 'id': self.id} def _build_storage_path(self): path_segments = ['event', strict_unicode(self.event_new.id), 'static'] self.assign_id() filename = '{}-{}'.format(self.id, self.filename) path = posixpath.join(*(path_segments + [filename])) return Config.getInstance().getStaticSiteStorage(), path @return_ascii def __repr__(self): return format_repr(self, 'id', 'event_id', 'state')
class EditingFileType(db.Model): __tablename__ = 'file_types' @declared_attr def __table_args__(cls): return ( db.Index( 'ix_uq_file_types_event_id_type_name_lower', cls.event_id, cls.type, db.func.lower(cls.name), unique=True, ), { 'schema': 'event_editing' }, ) id = db.Column(db.Integer, primary_key=True) event_id = db.Column(db.ForeignKey('events.events.id'), index=True, nullable=False) type = db.Column(PyIntEnum(EditableType), nullable=False) name = db.Column(db.String, nullable=False) extensions = db.Column(ARRAY(db.String), nullable=False, default=[]) allow_multiple_files = db.Column(db.Boolean, nullable=False, default=False) required = db.Column(db.Boolean, nullable=False, default=False) publishable = db.Column(db.Boolean, nullable=False, default=False) filename_template = db.Column(db.String, nullable=True) event = db.relationship('Event', lazy=True, backref=db.backref('editing_file_types', cascade='all, delete-orphan', lazy=True)) # relationship backrefs: # - files (EditingRevisionFile.file_type) # - review_conditions (EditingReviewCondition.file_types) @return_ascii def __repr__(self): return format_repr(self, 'id', 'event_id', 'extensions', allow_multiple_files=False, required=False, publishable=False, filename_template=None, _text=self.name)
def upgrade(): op.create_table('vc_rooms', sa.Column('id', sa.Integer(), nullable=False), sa.Column('type', sa.String(), nullable=False), sa.Column('name', sa.String(), nullable=False), sa.Column('status', PyIntEnum(VCRoomStatus), nullable=False), 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.Column('data', postgresql.JSON(), nullable=False), sa.PrimaryKeyConstraint('id'), schema='events') op.create_table('vc_room_events', sa.Column('id', sa.Integer(), nullable=False), sa.Column('event_id', sa.Integer(), autoincrement=False, nullable=False, index=True), sa.Column('vc_room_id', sa.Integer(), nullable=False, index=True), sa.Column('link_type', PyIntEnum(VCRoomLinkType), nullable=False), sa.Column('link_id', sa.String(), nullable=True), sa.Column('show', sa.Boolean(), nullable=False), sa.Column('data', postgresql.JSON(), nullable=False), sa.ForeignKeyConstraint(['vc_room_id'], ['events.vc_rooms.id']), sa.PrimaryKeyConstraint('id'), schema='events')
def upgrade(): op.create_table('logs', sa.Column('id', sa.Integer(), nullable=False), sa.Column('event_id', sa.Integer(), nullable=False, index=True), sa.Column('user_id', sa.Integer(), nullable=True, index=True), sa.Column('logged_dt', UTCDateTime, nullable=False), sa.Column('realm', PyIntEnum(EventLogRealm), nullable=False), sa.Column('kind', PyIntEnum(EventLogKind), nullable=False), sa.Column('module', sa.String(), nullable=False), sa.Column('type', sa.String(), nullable=False), sa.Column('summary', sa.String(), nullable=False), sa.Column('data', postgresql.JSON(), nullable=False), sa.ForeignKeyConstraint(['user_id'], ['users.users.id']), sa.PrimaryKeyConstraint('id'), schema='events')