Python sqlalchemy.dialects.postgresql.UUID Examples

The following are 30 code examples of sqlalchemy.dialects.postgresql.UUID(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sqlalchemy.dialects.postgresql , or try the search function .
Example #1
Source File: 0278_add_more_stuff_to_orgs.py    From notifications-api with MIT License 6 votes vote down vote up
def upgrade():
    op.create_table(
        'domain',
        sa.Column('domain', sa.String(length=255), nullable=False),
        sa.Column('organisation_id', postgresql.UUID(as_uuid=True), nullable=False),
        sa.ForeignKeyConstraint(['organisation_id'], ['organisation.id'], ),
        sa.PrimaryKeyConstraint('domain')
    )
    op.create_index(op.f('ix_domain_domain'), 'domain', ['domain'], unique=True)

    op.add_column('organisation', sa.Column('email_branding_id', postgresql.UUID(as_uuid=True), nullable=True))
    op.create_foreign_key('fk_organisation_email_branding_id', 'organisation', 'email_branding', ['email_branding_id'], ['id'])

    op.add_column('organisation', sa.Column('letter_branding_id', postgresql.UUID(as_uuid=True), nullable=True))
    op.create_foreign_key('fk_organisation_letter_branding_id', 'organisation', 'letter_branding', ['letter_branding_id'], ['id'])

    op.add_column('organisation', sa.Column('agreement_signed', sa.Boolean(), nullable=True))
    op.add_column('organisation', sa.Column('agreement_signed_at', sa.DateTime(), nullable=True))
    op.add_column('organisation', sa.Column('agreement_signed_by_id', postgresql.UUID(as_uuid=True), nullable=True))
    op.add_column('organisation', sa.Column('agreement_signed_version', sa.Float(), nullable=True))
    op.add_column('organisation', sa.Column('crown', sa.Boolean(), nullable=True))
    op.add_column('organisation', sa.Column('organisation_type', sa.String(length=255), nullable=True))
    op.create_foreign_key('fk_organisation_agreement_user_id', 'organisation', 'users', ['agreement_signed_by_id'], ['id']) 
Example #2
Source File: 0090_inbound_sms.py    From notifications-api with MIT License 6 votes vote down vote up
def upgrade():
    op.create_table(
        'inbound_sms',
        sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
        sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
        sa.Column('content', sa.String, nullable=False),
        sa.Column('notify_number', sa.String, nullable=False),
        sa.Column('user_number', sa.String, nullable=False),
        sa.Column('created_at', sa.DateTime, nullable=False),
        sa.Column('provider_date', sa.DateTime, nullable=True),
        sa.Column('provider_reference', sa.String, nullable=True),

        sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
        sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_inbound_sms_service_id'), 'inbound_sms', ['service_id'], unique=False)
    op.create_index(op.f('ix_inbound_sms_user_number'), 'inbound_sms', ['user_number'], unique=False) 
Example #3
Source File: 0242_template_folders.py    From notifications-api with MIT License 6 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('template_folder',
        sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
        sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
        sa.Column('name', sa.String(), nullable=False),
        sa.Column('parent_id', postgresql.UUID(as_uuid=True), nullable=True),
        sa.ForeignKeyConstraint(['parent_id'], ['template_folder.id'], ),
        sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
        sa.PrimaryKeyConstraint('id')
    )
    op.create_table('template_folder_map',
        sa.Column('template_id', postgresql.UUID(as_uuid=True), nullable=False),
        sa.Column('template_folder_id', postgresql.UUID(as_uuid=True), nullable=False),
        sa.ForeignKeyConstraint(['template_folder_id'], ['template_folder.id'], ),
        sa.ForeignKeyConstraint(['template_id'], ['templates.id'], ),
        sa.PrimaryKeyConstraint('template_id')
    ) 
Example #4
Source File: 0068_add_created_by_to_provider.py    From notifications-api with MIT License 6 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('provider_details', sa.Column('created_by_id', postgresql.UUID(as_uuid=True), nullable=True))
    op.create_index(op.f('ix_provider_details_created_by_id'), 'provider_details', ['created_by_id'], unique=False)
    op.create_foreign_key('provider_details_created_by_id_fkey', 'provider_details', 'users', ['created_by_id'], ['id'])
    op.add_column('provider_details_history', sa.Column('created_by_id', postgresql.UUID(as_uuid=True), nullable=True))
    op.create_index(
        op.f('ix_provider_details_history_created_by_id'),
        'provider_details_history',
        ['created_by_id'],
        unique=False
    )
    op.create_foreign_key(
        'provider_details_history_created_by_id_fkey',
        'provider_details_history',
        'users',
        ['created_by_id'],
        ['id']
    )
    # ### end Alembic commands ### 
Example #5
Source File: 0075_create_rates_table.py    From notifications-api with MIT License 6 votes vote down vote up
def upgrade():
    notification_types = postgresql.ENUM('email', 'sms', 'letter', name='notification_type', create_type=False)
    op.create_table('rates',
    sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
    sa.Column('valid_from', sa.DateTime(), nullable=False),
    sa.Column('rate', sa.Numeric(), nullable=False),
    sa.Column('notification_type', notification_types, nullable=False),
    sa.PrimaryKeyConstraint('id')
    )

    op.create_index(op.f('ix_rates_notification_type'), 'rates', ['notification_type'], unique=False)

    op.get_bind()
    op.execute("INSERT INTO rates(id, valid_from, rate, notification_type) "
               "VALUES('{}', '2016-05-18 00:00:00', 1.65, 'sms')".format(uuid.uuid4()))
    op.execute("INSERT INTO rates(id, valid_from, rate, notification_type) "
               "VALUES('{}', '2017-04-01 00:00:00', 1.58, 'sms')".format(uuid.uuid4())) 
Example #6
Source File: ee2373fbe3a4_.py    From zou with GNU Affero General Public License v3.0 6 votes vote down vote up
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('output_file', sa.Column('uploaded_movie_url', sa.VARCHAR(length=600), autoincrement=False, nullable=True))
    op.add_column('output_file', sa.Column('uploaded_movie_name', sa.VARCHAR(length=150), autoincrement=False, nullable=True))
    op.drop_constraint(None, 'output_file', type_='foreignkey')
    op.drop_constraint('output_file_uc', 'output_file', type_='unique')
    op.create_unique_constraint('output_file_uc', 'output_file', ['name', 'entity_id', 'output_type_id', 'task_type_id', 'representation', 'revision'])
    op.drop_column('output_file', 'temporal_entity_id')
    op.drop_constraint(None, 'asset_instance', type_='foreignkey')
    op.create_index('ix_asset_instance_entity_type_id', 'asset_instance', ['entity_type_id'], unique=False)
    op.create_index('ix_asset_instance_entity_id', 'asset_instance', ['entity_id'], unique=False)
    op.drop_constraint('asset_instance_uc', 'asset_instance', type_='unique')
    op.create_unique_constraint('asset_instance_uc', 'asset_instance', ['asset_id', 'entity_id', 'number'])
    op.drop_constraint('asset_instance_name_uc', 'asset_instance', type_='unique')
    op.create_unique_constraint('asset_instance_name_uc', 'asset_instance', ['entity_id', 'name'])
    op.drop_index(op.f('ix_asset_instance_scene_id'), table_name='asset_instance')
    op.alter_column('asset_instance', 'entity_type_id',
               existing_type=postgresql.UUID(),
               nullable=False)
    op.alter_column('asset_instance', 'entity_id',
               existing_type=postgresql.UUID(),
               nullable=False)
    op.drop_column('asset_instance', 'scene_id')
    op.drop_table('asset_instance_link')
    # ### end Alembic commands ### 
Example #7
Source File: 0318_service_contact_list.py    From notifications-api with MIT License 6 votes vote down vote up
def upgrade():
    op.create_table(
        'service_contact_list',
        sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
        sa.Column('original_file_name', sa.String(), nullable=False),
        sa.Column('row_count', sa.Integer(), nullable=False),
        sa.Column('template_type', postgresql.ENUM(name='template_type', create_type=False), nullable=False),
        sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
        sa.Column('created_by_id', postgresql.UUID(as_uuid=True), nullable=True),
        sa.Column('created_at', sa.DateTime(), nullable=False),
        sa.Column('updated_at', sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(['created_by_id'], ['users.id'], ),
        sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
        sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_service_contact_list_created_by_id'), 'service_contact_list', ['created_by_id'], unique=False)
    op.create_index(op.f('ix_service_contact_list_service_id'), 'service_contact_list', ['service_id'], unique=False)
    op.add_column('jobs', sa.Column('contact_list_id', postgresql.UUID(as_uuid=True), nullable=True))
    op.create_foreign_key('jobs_contact_list_id_fkey', 'jobs', 'service_contact_list', ['contact_list_id'], ['id']) 
Example #8
Source File: 0084_add_job_stats.py    From notifications-api with MIT License 6 votes vote down vote up
def upgrade():
    op.create_table('job_statistics',
    sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
    sa.Column('job_id', postgresql.UUID(as_uuid=True), nullable=False),
    sa.Column('emails_sent', sa.BigInteger(), nullable=False),
    sa.Column('emails_delivered', sa.BigInteger(), nullable=False),
    sa.Column('emails_failed', sa.BigInteger(), nullable=False),
    sa.Column('sms_sent', sa.BigInteger(), nullable=False),
    sa.Column('sms_delivered', sa.BigInteger(), nullable=False),
    sa.Column('sms_failed', sa.BigInteger(), nullable=False),
    sa.Column('letters_sent', sa.BigInteger(), nullable=False),
    sa.Column('letters_failed', sa.BigInteger(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['job_id'], ['jobs.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_job_statistics_job_id'), 'job_statistics', ['job_id'], unique=True) 
Example #9
Source File: 0210_remove_monthly_billing.py    From notifications-api with MIT License 6 votes vote down vote up
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('monthly_billing',
    sa.Column('id', postgresql.UUID(), autoincrement=False, nullable=False),
    sa.Column('service_id', postgresql.UUID(), autoincrement=False, nullable=False),
    sa.Column('notification_type', postgresql.ENUM('email', 'sms', 'letter', name='notification_type'), autoincrement=False, nullable=False),
    sa.Column('monthly_totals', postgresql.JSON(astext_type=sa.Text()), autoincrement=False, nullable=False),
    sa.Column('updated_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
    sa.Column('start_date', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
    sa.Column('end_date', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
    sa.ForeignKeyConstraint(['service_id'], ['services.id'], name='monthly_billing_service_id_fkey'),
    sa.PrimaryKeyConstraint('id', name='monthly_billing_pkey'),
    sa.UniqueConstraint('service_id', 'start_date', 'notification_type', name='uix_monthly_billing')
    )
    op.create_index('ix_monthly_billing_service_id', 'monthly_billing', ['service_id'], unique=False)
    # ### end Alembic commands ### 
Example #10
Source File: 0151_refactor_letter_rates.py    From notifications-api with MIT License 6 votes vote down vote up
def downgrade():
    op.drop_table('letter_rates')
    op.create_table('letter_rates',
                    sa.Column('id', postgresql.UUID(), autoincrement=False, nullable=False),
                    sa.Column('valid_from', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
                    sa.PrimaryKeyConstraint('id', name='letter_rates_pkey'),
                    postgresql_ignore_search_path=False
                    )
    op.create_table('letter_rate_details',
                    sa.Column('id', postgresql.UUID(), autoincrement=False, nullable=False),
                    sa.Column('letter_rate_id', postgresql.UUID(), autoincrement=False, nullable=False),
                    sa.Column('page_total', sa.INTEGER(), autoincrement=False, nullable=False),
                    sa.Column('rate', sa.NUMERIC(), autoincrement=False, nullable=False),
                    sa.ForeignKeyConstraint(['letter_rate_id'], ['letter_rates.id'],
                                            name='letter_rate_details_letter_rate_id_fkey'),
                    sa.PrimaryKeyConstraint('id', name='letter_rate_details_pkey')
                    ) 
Example #11
Source File: 56c000fd001d_.py    From website with MIT License 6 votes vote down vote up
def downgrade():
    op.add_column(
        "projects",
        sa.Column("client_id", postgresql.UUID(), autoincrement=False, nullable=True),
    )
    op.add_column(
        "projects",
        sa.Column("secret_key", postgresql.UUID(), autoincrement=False, nullable=True),
    )
    op.drop_index(
        "release_username_password_is_active_idx", table_name="project_credentials"
    )
    op.drop_index(
        op.f("ix_project_credentials_is_active"), table_name="project_credentials"
    )
    op.drop_table("project_credentials") 
Example #12
Source File: 0005_add_provider_stats.py    From notifications-api with MIT License 6 votes vote down vote up
def upgrade():
    op.create_table('provider_rates',
    sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
    sa.Column('valid_from', sa.DateTime(), nullable=False),
    sa.Column('provider', sa.Enum('mmg', 'twilio', 'firetext', 'ses', name='providers'), nullable=False),
    sa.Column('rate', sa.Numeric(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('provider_statistics',
    sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
    sa.Column('day', sa.Date(), nullable=False),
    sa.Column('provider', sa.Enum('mmg', 'twilio', 'firetext', 'ses', name='providers'), nullable=False),
    sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
    sa.Column('unit_count', sa.BigInteger(), nullable=False),
    sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_provider_statistics_service_id'), 'provider_statistics', ['service_id'], unique=False) 
Example #13
Source File: 0175_drop_job_statistics_table.py    From notifications-api with MIT License 6 votes vote down vote up
def downgrade():
    op.create_table('job_statistics',
    sa.Column('id', postgresql.UUID(), autoincrement=False, nullable=False),
    sa.Column('job_id', postgresql.UUID(), autoincrement=False, nullable=False),
    sa.Column('emails_sent', sa.BIGINT(), autoincrement=False, nullable=False),
    sa.Column('emails_delivered', sa.BIGINT(), autoincrement=False, nullable=False),
    sa.Column('emails_failed', sa.BIGINT(), autoincrement=False, nullable=False),
    sa.Column('sms_sent', sa.BIGINT(), autoincrement=False, nullable=False),
    sa.Column('sms_delivered', sa.BIGINT(), autoincrement=False, nullable=False),
    sa.Column('sms_failed', sa.BIGINT(), autoincrement=False, nullable=False),
    sa.Column('letters_sent', sa.BIGINT(), autoincrement=False, nullable=False),
    sa.Column('letters_failed', sa.BIGINT(), autoincrement=False, nullable=False),
    sa.Column('created_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
    sa.Column('updated_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
    sa.Column('sent', sa.BIGINT(), autoincrement=False, nullable=True),
    sa.Column('delivered', sa.BIGINT(), autoincrement=False, nullable=True),
    sa.Column('failed', sa.BIGINT(), autoincrement=False, nullable=True),
    sa.ForeignKeyConstraint(['job_id'], ['jobs.id'], name='job_statistics_job_id_fkey'),
    sa.PrimaryKeyConstraint('id', name='job_statistics_pkey')
    ) 
Example #14
Source File: 0007_template_history.py    From notifications-api with MIT License 6 votes vote down vote up
def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint("fk_templates_created_by_id", 'templates', type_='foreignkey')
    op.drop_index(op.f('ix_templates_created_by_id'), table_name='templates')
    op.drop_column('templates', 'version')
    op.drop_column('templates', 'created_by_id')
    op.alter_column('api_keys_history', 'created_by_id',
               existing_type=postgresql.UUID(),
               nullable=True)
    op.alter_column('api_keys_history', 'created_at',
               existing_type=postgresql.TIMESTAMP(),
               nullable=True)
    op.drop_index(op.f('ix_templates_history_service_id'), table_name='templates_history')
    op.drop_index(op.f('ix_templates_history_created_by_id'), table_name='templates_history')
    op.drop_table('templates_history')
    ### end Alembic commands ### 
Example #15
Source File: 0110_monthly_billing.py    From notifications-api with MIT License 6 votes vote down vote up
def upgrade():

    op.create_table('monthly_billing',
                    sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
                    sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
                    sa.Column('month', sa.String(), nullable=False),
                    sa.Column('year', sa.Float(), nullable=False),
                    sa.Column('notification_type',
                              postgresql.ENUM('email', 'sms', 'letter', name='notification_type', create_type=False),
                              nullable=False),
                    sa.Column('monthly_totals', postgresql.JSON(), nullable=False),
                    sa.Column('updated_at', sa.DateTime, nullable=False),
                    sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_index(op.f('ix_monthly_billing_service_id'), 'monthly_billing', ['service_id'], unique=False)
    op.create_index(op.f('uix_monthly_billing'), 'monthly_billing', ['service_id', 'month', 'year', 'notification_type'], unique=True) 
Example #16
Source File: 0252_letter_branding_table.py    From notifications-api with MIT License 6 votes vote down vote up
def upgrade():
    op.create_table('letter_branding',
                    sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
                    sa.Column('name', sa.String(length=255), nullable=False),
                    sa.Column('filename', sa.String(length=255), nullable=False),
                    sa.Column('domain', sa.Text(), nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    sa.UniqueConstraint('domain'),
                    sa.UniqueConstraint('filename'),
                    sa.UniqueConstraint('name')
                    )
    op.create_table('service_letter_branding',
                    sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
                    sa.Column('letter_branding_id', postgresql.UUID(as_uuid=True), nullable=False),
                    sa.ForeignKeyConstraint(['letter_branding_id'], ['letter_branding.id'], ),
                    sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
                    sa.PrimaryKeyConstraint('service_id')
                    )

    op.get_bind() 
Example #17
Source File: 0118_service_sms_senders.py    From notifications-api with MIT License 6 votes vote down vote up
def upgrade():
    op.create_table('service_sms_senders',
                    sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
                    sa.Column('sms_sender', sa.String(length=11), nullable=False),
                    sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
                    sa.Column('is_default', sa.Boolean(), nullable=False),
                    sa.Column('inbound_number_id', postgresql.UUID(as_uuid=True), nullable=True),
                    sa.Column('created_at', sa.DateTime(), nullable=False),
                    sa.Column('updated_at', sa.DateTime(), nullable=True),
                    sa.ForeignKeyConstraint(['inbound_number_id'], ['inbound_numbers.id'], ),
                    sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_index(op.f('ix_service_sms_senders_inbound_number_id'), 'service_sms_senders', ['inbound_number_id'],
                    unique=True)
    op.create_index(op.f('ix_service_sms_senders_service_id'), 'service_sms_senders', ['service_id'], unique=True)

    # populate govuk seeded service
    op.execute("""
        INSERT INTO service_sms_senders
        (id, sms_sender, service_id, is_default, inbound_number_id, created_at, updated_at)
        VALUES ('286d6176-adbe-7ea7-ba26-b7606ee5e2a4', 'GOVUK', 'd6aa2c68-a2d9-4437-ab19-3ae8eb202553', true, null, now(), null)
    """) 
Example #18
Source File: 0128_noti_to_sms_sender.py    From notifications-api with MIT License 6 votes vote down vote up
def upgrade():
    op.create_index(op.f('ix_service_letter_contacts_service_id'), 'service_letter_contacts', ['service_id'],
                    unique=False)
    op.drop_index('ix_service_letter_contact_service_id', table_name='service_letter_contacts')
    op.create_index(op.f('ix_service_sms_senders_service_id'), 'service_sms_senders', ['service_id'], unique=False)
    op.execute(
        'ALTER TABLE templates_history ALTER COLUMN template_type TYPE template_type USING template_type::template_type')

    # new table
    op.create_table('notification_to_sms_sender',
    sa.Column('notification_id', postgresql.UUID(as_uuid=True), nullable=False),
    sa.Column('service_sms_sender_id', postgresql.UUID(as_uuid=True), nullable=False),
    sa.ForeignKeyConstraint(['notification_id'], ['notifications.id'], ),
    sa.ForeignKeyConstraint(['service_sms_sender_id'], ['service_sms_senders.id'], ),
    sa.PrimaryKeyConstraint('notification_id', 'service_sms_sender_id')
    )
    op.create_index(op.f('ix_notification_to_sms_sender_notification_id'), 'notification_to_sms_sender', ['notification_id'], unique=True)
    op.create_index(op.f('ix_notification_to_sms_sender_service_sms_sender_id'), 'notification_to_sms_sender', ['service_sms_sender_id'], unique=False) 
Example #19
Source File: 854bd902b1bc_change_kernel_identification.py    From backend.ai-manager with GNU Lesser General Public License v3.0 6 votes vote down vote up
def upgrade():
    op.drop_constraint('fk_vfolder_attachment_vfolder_vfolders', 'vfolder_attachment', type_='foreignkey')
    op.drop_constraint('fk_vfolder_attachment_kernel_kernels', 'vfolder_attachment', type_='foreignkey')
    op.drop_constraint('pk_kernels', 'kernels', type_='primary')
    op.add_column('kernels',
                  sa.Column('id', GUID(),
                            server_default=sa.text('uuid_generate_v4()'),
                            nullable=False))
    op.add_column('kernels', sa.Column('role', sa.String(length=16), nullable=False, default='master'))
    op.create_primary_key('pk_kernels', 'kernels', ['id'])
    op.alter_column(
        'kernels', 'sess_id',
        existing_type=postgresql.UUID(),
        type_=sa.String(length=64),
        nullable=True,
        existing_server_default=sa.text('uuid_generate_v4()'))
    op.create_index(op.f('ix_kernels_sess_id'), 'kernels', ['sess_id'], unique=False)
    op.create_index(op.f('ix_kernels_sess_id_role'), 'kernels', ['sess_id', 'role'], unique=False)
    op.create_foreign_key('fk_vfolder_attachment_vfolder_vfolders',
                          'vfolder_attachment', 'vfolders',
                          ['vfolder'], ['id'], onupdate='CASCADE', ondelete='CASCADE')
    op.create_foreign_key('fk_vfolder_attachment_kernel_kernels',
                          'vfolder_attachment', 'kernels',
                          ['kernel'], ['id'], onupdate='CASCADE', ondelete='CASCADE') 
Example #20
Source File: 0162_remove_org.py    From notifications-api with MIT License 6 votes vote down vote up
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('services_history', sa.Column('organisation_id', postgresql.UUID(), autoincrement=False, nullable=True))  # noqa
    op.add_column('services', sa.Column('organisation_id', postgresql.UUID(), autoincrement=False, nullable=True))

    op.create_table(
        'organisation',
        sa.Column('id', postgresql.UUID(), autoincrement=False, nullable=False),
        sa.Column('colour', sa.VARCHAR(length=7), autoincrement=False, nullable=True),
        sa.Column('logo', sa.VARCHAR(length=255), autoincrement=False, nullable=True),
        sa.Column('name', sa.VARCHAR(length=255), autoincrement=False, nullable=True),
        sa.PrimaryKeyConstraint('id', name='organisation_pkey')
    )

    op.create_index('ix_services_history_organisation_id', 'services_history', ['organisation_id'], unique=False)
    op.create_foreign_key('services_organisation_id_fkey', 'services', 'organisation', ['organisation_id'], ['id'])
    op.create_index('ix_services_organisation_id', 'services', ['organisation_id'], unique=False)

    op.alter_column('service_email_branding', 'email_branding_id', nullable=True) 
Example #21
Source File: 0147_drop_mapping_tables.py    From notifications-api with MIT License 6 votes vote down vote up
def downgrade():
    op.create_table('notification_to_email_reply_to',
                    sa.Column('notification_id', postgresql.UUID(), autoincrement=False, nullable=False),
                    sa.Column('service_email_reply_to_id', postgresql.UUID(), autoincrement=False, nullable=False),
                    sa.ForeignKeyConstraint(['notification_id'], ['notifications.id'],
                                            name='notification_to_email_reply_to_notification_id_fkey'),
                    sa.ForeignKeyConstraint(['service_email_reply_to_id'], ['service_email_reply_to.id'],
                                            name='notification_to_email_reply_to_service_email_reply_to_id_fkey'),
                    sa.PrimaryKeyConstraint('notification_id', 'service_email_reply_to_id',
                                            name='notification_to_email_reply_to_pkey')
                    )
    op.create_table('notification_to_sms_sender',
                    sa.Column('notification_id', postgresql.UUID(), autoincrement=False, nullable=False),
                    sa.Column('service_sms_sender_id', postgresql.UUID(), autoincrement=False, nullable=False),
                    sa.ForeignKeyConstraint(['notification_id'], ['notifications.id'],
                                            name='notification_to_sms_sender_notification_id_fkey'),
                    sa.ForeignKeyConstraint(['service_sms_sender_id'], ['service_sms_senders.id'],
                                            name='notification_to_sms_sender_service_sms_sender_id_fkey'),
                    sa.PrimaryKeyConstraint('notification_id', 'service_sms_sender_id',
                                            name='notification_to_sms_sender_pkey')
                    ) 
Example #22
Source File: 0015_fix_template_data.py    From notifications-api with MIT License 6 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.get_bind()
    query = 'update templates_history set created_by_id = ' \
            '(select created_by_id from templates where templates.id = templates_history.id) ' \
            'where created_by_id is null'
    op.execute(query)
    op.execute('update templates_history set archived = False')
    op.alter_column('api_keys_history', 'created_at',
               existing_type=postgresql.TIMESTAMP(),
               nullable=False)
    op.alter_column('api_keys_history', 'created_by_id',
               existing_type=postgresql.UUID(),
               nullable=False)
    op.alter_column('templates_history', 'archived',
               existing_type=sa.BOOLEAN(),
               nullable=False)
    op.alter_column('templates_history', 'created_by_id',
               existing_type=postgresql.UUID(),
               nullable=False)
    ### end Alembic commands ### 
Example #23
Source File: 0302_add_org_id_to_services.py    From notifications-api with MIT License 5 votes vote down vote up
def upgrade():
    op.add_column('services', sa.Column('organisation_id', postgresql.UUID(as_uuid=True), nullable=True))
    op.create_index(op.f('ix_services_organisation_id'), 'services', ['organisation_id'], unique=False)
    op.create_foreign_key("fk_service_organisation", 'services', 'organisation', ['organisation_id'], ['id'])
    op.add_column('services_history', sa.Column('organisation_id', postgresql.UUID(as_uuid=True), nullable=True))
    op.create_index(op.f('ix_services_history_organisation_id'), 'services_history', ['organisation_id'], unique=False) 
Example #24
Source File: 0311_add_inbound_sms_history.py    From notifications-api with MIT License 5 votes vote down vote up
def upgrade():
    op.create_table('inbound_sms_history',
    sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=True),
    sa.Column('notify_number', sa.String(), nullable=False),
    sa.Column('provider_date', sa.DateTime(), nullable=True),
    sa.Column('provider_reference', sa.String(), nullable=True),
    sa.Column('provider', sa.String(), nullable=False),
    sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_inbound_sms_history_service_id'), 'inbound_sms_history', ['service_id'], unique=False) 
Example #25
Source File: 0196_complaints_table_.py    From notifications-api with MIT License 5 votes vote down vote up
def upgrade():
    op.create_table('complaints',
    sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
    sa.Column('notification_id', postgresql.UUID(as_uuid=True), nullable=False),
    sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
    sa.Column('ses_feedback_id', sa.Text(), nullable=True),
    sa.Column('complaint_type', sa.Text(), nullable=True),
    sa.Column('complaint_date', sa.DateTime(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['notification_id'], ['notification_history.id'], ),
    sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_complaints_notification_id'), 'complaints', ['notification_id'], unique=False)
    op.create_index(op.f('ix_complaints_service_id'), 'complaints', ['service_id'], unique=False) 
Example #26
Source File: 0115_add_inbound_numbers.py    From notifications-api with MIT License 5 votes vote down vote up
def upgrade():
    op.create_table('inbound_numbers',
    sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
    sa.Column('number', sa.String(length=11), nullable=False),
    sa.Column('provider', sa.String(), nullable=False),
    sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=True),
    sa.Column('active', sa.Boolean(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('number')
    )
    op.create_index(op.f('ix_inbound_numbers_service_id'), 'inbound_numbers', ['service_id'], unique=True) 
Example #27
Source File: 0100_notification_created_by.py    From notifications-api with MIT License 5 votes vote down vote up
def upgrade():
    op.add_column('notifications', sa.Column('created_by_id', postgresql.UUID(as_uuid=True), nullable=True))
    op.create_foreign_key(None, 'notifications', 'users', ['created_by_id'], ['id'])

    op.add_column('notification_history', sa.Column('created_by_id', postgresql.UUID(as_uuid=True), nullable=True))
    op.create_foreign_key(None, 'notification_history', 'users', ['created_by_id'], ['id']) 
Example #28
Source File: 0007_template_history.py    From notifications-api with MIT License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('templates_history',
    sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
    sa.Column('name', sa.String(length=255), nullable=False),
    sa.Column('template_type', sa.String(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.Column('content', sa.Text(), nullable=False),
    sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
    sa.Column('subject', sa.Text(), nullable=True),
    sa.Column('created_by_id', postgresql.UUID(as_uuid=True), nullable=True),
    sa.Column('version', sa.Integer(), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('id', 'version')
    )
    op.create_index(op.f('ix_templates_history_created_by_id'), 'templates_history', ['created_by_id'], unique=False)
    op.create_index(op.f('ix_templates_history_service_id'), 'templates_history', ['service_id'], unique=False)
    op.add_column('templates', sa.Column('created_by_id', postgresql.UUID(as_uuid=True), nullable=True))
    op.add_column('templates', sa.Column('version', sa.Integer(), nullable=True))
    
    
    op.get_bind()
    op.execute('UPDATE templates SET created_by_id = (SELECT user_id FROM user_to_service WHERE templates.service_id = user_to_service.service_id LIMIT 1)')
    op.execute('UPDATE templates SET version = 1, created_at = now()')
    op.execute((
      'INSERT INTO templates_history (id, name, template_type, created_at, updated_at, content, service_id, subject, version)'
      ' SELECT id, name, template_type, created_at, updated_at, content, service_id, subject, version FROM templates'))


    op.alter_column('templates', 'created_at', nullable=False)
    op.alter_column('templates', 'created_by_id', nullable=False)
    op.alter_column('templates', 'version', nullable=False)

    op.create_index(op.f('ix_templates_created_by_id'), 'templates', ['created_by_id'], unique=False)
    op.create_foreign_key("fk_templates_created_by_id", 'templates', 'users', ['created_by_id'], ['id'])
    ### end Alembic commands ### 
Example #29
Source File: 0288_add_go_live_user.py    From notifications-api with MIT License 5 votes vote down vote up
def upgrade():
    op.add_column('services', sa.Column('go_live_at', sa.DateTime(), nullable=True))
    op.add_column('services', sa.Column('go_live_user_id', postgresql.UUID(as_uuid=True), nullable=True))
    op.create_foreign_key('fk_services_go_live_user', 'services', 'users', ['go_live_user_id'], ['id'])
    op.add_column('services_history', sa.Column('go_live_at', sa.DateTime(), nullable=True))
    op.add_column('services_history', sa.Column('go_live_user_id', postgresql.UUID(as_uuid=True), nullable=True)) 
Example #30
Source File: 0164_add_organisation_to_service.py    From notifications-api with MIT License 5 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('organisation_to_service',
    sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
    sa.Column('organisation_id', postgresql.UUID(as_uuid=True), nullable=False),
    sa.ForeignKeyConstraint(['organisation_id'], ['organisation.id'], ),
    sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
    sa.PrimaryKeyConstraint('service_id')
    )
    # ### end Alembic commands ###