"""apollo link Revision ID: 3b4851325438 Revises: bf2079dbad6e Create Date: 2019-10-10 15:15:48.302732 """ from alembic import op import sqlalchemy as sa from sqlalchemy.engine.reflection import Inspector # revision identifiers, used by Alembic. revision = '3b4851325438' down_revision = 'bf2079dbad6e' branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### conn = op.get_bind() tables = Inspector.from_engine(conn).get_table_names() if 'Isrc' in tables: op.drop_table('Isrc') op.create_table('Album', sa.Column('id', sa.BigInteger(), nullable=False), sa.Column('name', sa.String(), nullable=False), sa.Column('upc', sa.String(length=12), nullable=False), sa.CheckConstraint("upc ~ '^\\d{12}$'", name=op.f('ck_Album_ck_Upc_value_format')), sa.PrimaryKeyConstraint('id', name=op.f('pk_Album')), sa.UniqueConstraint('upc', name=op.f('uq_Album_upc')) ) op.create_table('Track', sa.Column('id', sa.BigInteger(), nullable=False), sa.Column('name', sa.String(), nullable=False), sa.Column('isrc', sa.String(length=12), nullable=False), sa.Column('album_id', sa.BigInteger(), nullable=False), sa.CheckConstraint("isrc ~ '^[A-Z]{2}[A-Z0-9]{3}\\d{7}$'", name=op.f('ck_Track_ck_Isrc_value_format')), sa.ForeignKeyConstraint(['album_id'], ['Album.id'], name=op.f('fk_Track_album_id_Album')), sa.PrimaryKeyConstraint('id', name=op.f('pk_Track')), sa.UniqueConstraint('isrc', 'album_id', name='uq_Track_isrc_album_id') ) op.create_table('AppleAlbum', sa.Column('album_id', sa.BigInteger(), nullable=False), sa.Column('apple_id', sa.String(), nullable=False), sa.Column('url', sa.String(), nullable=False), sa.Column('cover_art', sa.String(), nullable=False), sa.ForeignKeyConstraint(['album_id'], ['Album.id'], name=op.f('fk_AppleAlbum_album_id_Album'), ondelete='CASCADE'), sa.PrimaryKeyConstraint('album_id', name=op.f('pk_AppleAlbum')), sa.UniqueConstraint('apple_id', name=op.f('uq_AppleAlbum_apple_id')), sa.UniqueConstraint('url', name=op.f('uq_AppleAlbum_url')) ) op.create_table('AppleArtist', sa.Column('artist_id', sa.BigInteger(), nullable=False), sa.Column('apple_id', sa.String(), nullable=False), sa.Column('url', sa.String(), nullable=False), sa.ForeignKeyConstraint(['artist_id'], ['Artist.id'], name=op.f('fk_AppleArtist_artist_id_Artist')), sa.PrimaryKeyConstraint('artist_id', name=op.f('pk_AppleArtist')), sa.UniqueConstraint('apple_id', name=op.f('uq_AppleArtist_apple_id')), sa.UniqueConstraint('url', name=op.f('uq_AppleArtist_url')) ) op.create_table('AppleTrack', sa.Column('track_id', sa.BigInteger(), nullable=False), sa.Column('apple_id', sa.String(), nullable=False), sa.Column('url', sa.String(), nullable=False), sa.ForeignKeyConstraint(['track_id'], ['Track.id'], name=op.f('fk_AppleTrack_track_id_Track')), sa.PrimaryKeyConstraint('track_id', name=op.f('pk_AppleTrack')), sa.UniqueConstraint('apple_id', name=op.f('uq_AppleTrack_apple_id')), sa.UniqueConstraint('url', name=op.f('uq_AppleTrack_url')) ) op.create_table('ArtistAlbum', sa.Column('artist_id', sa.BigInteger(), nullable=False), sa.Column('album_id', sa.BigInteger(), nullable=False), sa.ForeignKeyConstraint(['album_id'], ['Album.id'], name=op.f('fk_ArtistAlbum_album_id_Album')), sa.ForeignKeyConstraint(['artist_id'], ['Artist.id'], name=op.f('fk_ArtistAlbum_artist_id_Artist')), sa.PrimaryKeyConstraint('artist_id', 'album_id', name=op.f('pk_ArtistAlbum')) ) op.create_table('ArtistTrack', sa.Column('artist_id', sa.BigInteger(), nullable=False), sa.Column('track_id', sa.BigInteger(), nullable=False), sa.ForeignKeyConstraint(['artist_id'], ['Artist.id'], name=op.f('fk_ArtistTrack_artist_id_Artist')), sa.ForeignKeyConstraint(['track_id'], ['Track.id'], name=op.f('fk_ArtistTrack_track_id_Track')), sa.PrimaryKeyConstraint('artist_id', 'track_id', name=op.f('pk_ArtistTrack')) ) op.create_table('SpotifyAlbum', sa.Column('album_id', sa.BigInteger(), nullable=False), sa.Column('spotify_id', sa.String(), nullable=False), sa.Column('url', sa.String(), nullable=False), sa.Column('cover_art', sa.String(), nullable=False), sa.ForeignKeyConstraint(['album_id'], ['Album.id'], name=op.f('fk_SpotifyAlbum_album_id_Album'), ondelete='CASCADE'), sa.PrimaryKeyConstraint('album_id', name=op.f('pk_SpotifyAlbum')), sa.UniqueConstraint('spotify_id', name=op.f('uq_SpotifyAlbum_spotify_id')), sa.UniqueConstraint('url', name=op.f('uq_SpotifyAlbum_url')) ) op.create_table('SpotifyArtist', sa.Column('artist_id', sa.BigInteger(), nullable=False), sa.Column('spotify_id', sa.String(), nullable=False), sa.Column('url', sa.String(), nullable=False), sa.ForeignKeyConstraint(['artist_id'], ['Artist.id'], name=op.f('fk_SpotifyArtist_artist_id_Artist')), sa.PrimaryKeyConstraint('artist_id', name=op.f('pk_SpotifyArtist')), sa.UniqueConstraint('spotify_id', name=op.f('uq_SpotifyArtist_spotify_id')), sa.UniqueConstraint('url', name=op.f('uq_SpotifyArtist_url')) ) op.create_table('SpotifyTrack', sa.Column('track_id', sa.BigInteger(), nullable=False), sa.Column('spotify_id', sa.String(), nullable=False), sa.Column('url', sa.String(), nullable=False), sa.ForeignKeyConstraint(['track_id'], ['Track.id'], name=op.f('fk_SpotifyTrack_track_id_Track')), sa.PrimaryKeyConstraint('track_id', name=op.f('pk_SpotifyTrack')), sa.UniqueConstraint('spotify_id', name=op.f('uq_SpotifyTrack_spotify_id')), sa.UniqueConstraint('url', name=op.f('uq_SpotifyTrack_url')) ) op.alter_column('Artist', 'id', existing_type=sa.INTEGER(), type_=sa.BigInteger(), autoincrement=True, existing_server_default=sa.text('nextval(\'"Artist_id_seq"\'::regclass)')) op.add_column('Campaign', sa.Column('album_id', sa.BigInteger(), nullable=True)) op.add_column('Campaign', sa.Column('artist_id', sa.BigInteger(), nullable=True)) op.add_column('Campaign', sa.Column('track_id', sa.BigInteger(), nullable=True)) op.create_foreign_key(op.f('fk_Campaign_artist_id_Artist'), 'Campaign', 'Artist', ['artist_id'], ['id']) op.create_foreign_key(op.f('fk_Campaign_album_id_Album'), 'Campaign', 'Album', ['album_id'], ['id']) op.create_foreign_key(op.f('fk_Campaign_track_id_Track'), 'Campaign', 'Track', ['track_id'], ['id']) op.alter_column('Record', 'artist_id', existing_type=sa.INTEGER(), type_=sa.BigInteger(), existing_nullable=False) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### op.alter_column('Record', 'artist_id', existing_type=sa.BigInteger(), type_=sa.INTEGER(), existing_nullable=False) op.drop_constraint(op.f('fk_Campaign_track_id_Track'), 'Campaign', type_='foreignkey') op.drop_constraint(op.f('fk_Campaign_album_id_Album'), 'Campaign', type_='foreignkey') op.drop_constraint(op.f('fk_Campaign_artist_id_Artist'), 'Campaign', type_='foreignkey') op.drop_column('Campaign', 'track_id') op.drop_column('Campaign', 'artist_id') op.drop_column('Campaign', 'album_id') op.alter_column('Artist', 'id', existing_type=sa.BigInteger(), type_=sa.INTEGER(), autoincrement=True, existing_server_default=sa.text('nextval(\'"Artist_id_seq"\'::regclass)')) op.drop_table('SpotifyTrack') op.drop_table('SpotifyArtist') op.drop_table('SpotifyAlbum') op.drop_table('ArtistTrack') op.drop_table('ArtistAlbum') op.drop_table('AppleTrack') op.drop_table('AppleArtist') op.drop_table('AppleAlbum') op.drop_table('Track') op.drop_table('Album') # ### end Alembic commands ###