Commit 0124e2cf authored by Lukáš Lalinský's avatar Lukáš Lalinský

Multi-DB migrations

parent 30537256
......@@ -37,16 +37,10 @@ class TrackMBID(Base):
class TrackMBIDChange(Base):
__table__ = tables.track_mbid_change
track_mbid = relationship('TrackMBID')
account = relationship('Account')
class TrackMBIDSource(Base):
__table__ = tables.track_mbid_source
track_mbid = relationship('TrackMBID')
source = relationship('Source')
class Source(Base):
__table__ = tables.source
......
......@@ -206,7 +206,7 @@ fingerprint = Table('fingerprint', metadata,
Column('fingerprint', ARRAY(Integer), nullable=False),
Column('length', SmallInteger, CheckConstraint('length>0'), nullable=False),
Column('bitrate', SmallInteger, CheckConstraint('bitrate>0')),
Column('format_id', Integer, ForeignKey('format.id')),
Column('format_id', Integer),
Column('created', DateTime(timezone=True), server_default=sql.func.current_timestamp(), nullable=False),
Column('track_id', Integer, ForeignKey('track.id'), nullable=False),
Column('submission_count', Integer, nullable=False),
......@@ -217,9 +217,9 @@ fingerprint = Table('fingerprint', metadata,
fingerprint_source = Table('fingerprint_source', metadata,
Column('id', Integer, primary_key=True),
Column('fingerprint_id', Integer, ForeignKey('fingerprint.id'), nullable=False),
Column('fingerprint_id', Integer, nullable=False),
Column('submission_id', Integer, nullable=False),
Column('source_id', Integer, ForeignKey('source.id'), nullable=False),
Column('source_id', Integer, nullable=False),
Column('created', DateTime(timezone=True), server_default=sql.func.current_timestamp(), nullable=False),
Index('fingerprint_source_idx_submission_id', 'submission_id'),
info={'bind_key': 'ingest'},
......@@ -238,17 +238,17 @@ track_mbid = Table('track_mbid', metadata,
track_mbid_source = Table('track_mbid_source', metadata,
Column('id', Integer, primary_key=True),
Column('track_mbid_id', Integer, ForeignKey('track_mbid.id'), nullable=False, index=True),
Column('track_mbid_id', Integer, nullable=False, index=True),
Column('submission_id', Integer),
Column('source_id', Integer, ForeignKey('source.id'), nullable=False, index=True),
Column('source_id', Integer, nullable=False, index=True),
Column('created', DateTime(timezone=True), server_default=sql.func.current_timestamp(), nullable=False),
info={'bind_key': 'ingest'},
)
track_mbid_change = Table('track_mbid_change', metadata,
Column('id', Integer, primary_key=True),
Column('track_mbid_id', Integer, ForeignKey('track_mbid.id'), nullable=False, index=True),
Column('account_id', Integer, ForeignKey('account.id'), nullable=False),
Column('track_mbid_id', Integer, nullable=False, index=True),
Column('account_id', Integer, nullable=False),
Column('created', DateTime(timezone=True), server_default=sql.func.current_timestamp(), nullable=False),
Column('disabled', Boolean, nullable=False),
Column('note', Text),
......@@ -267,9 +267,9 @@ track_puid = Table('track_puid', metadata,
track_puid_source = Table('track_puid_source', metadata,
Column('id', Integer, primary_key=True),
Column('track_puid_id', Integer, ForeignKey('track_puid.id'), nullable=False),
Column('track_puid_id', Integer, nullable=False),
Column('submission_id', Integer, nullable=False),
Column('source_id', Integer, ForeignKey('source.id'), nullable=False),
Column('source_id', Integer, nullable=False),
Column('created', DateTime(timezone=True), server_default=sql.func.current_timestamp(), nullable=False),
info={'bind_key': 'ingest'},
)
......@@ -286,9 +286,9 @@ track_meta = Table('track_meta', metadata,
track_meta_source = Table('track_meta_source', metadata,
Column('id', Integer, primary_key=True),
Column('track_meta_id', Integer, ForeignKey('track_meta.id'), nullable=False),
Column('track_meta_id', Integer, nullable=False),
Column('submission_id', Integer, nullable=False),
Column('source_id', Integer, ForeignKey('source.id'), nullable=False),
Column('source_id', Integer, nullable=False),
Column('created', DateTime(timezone=True), server_default=sql.func.current_timestamp(), nullable=False),
info={'bind_key': 'ingest'},
)
......@@ -305,9 +305,9 @@ track_foreignid = Table('track_foreignid', metadata,
track_foreignid_source = Table('track_foreignid_source', metadata,
Column('id', Integer, primary_key=True),
Column('track_foreignid_id', Integer, ForeignKey('track_foreignid.id'), nullable=False),
Column('track_foreignid_id', Integer, nullable=False),
Column('submission_id', Integer, nullable=False),
Column('source_id', Integer, ForeignKey('source.id'), nullable=False),
Column('source_id', Integer, nullable=False),
Column('created', DateTime(timezone=True), server_default=sql.func.current_timestamp(), nullable=False),
info={'bind_key': 'ingest'},
)
......
CREATE DATABASE "acoustid";
CREATE DATABASE "acoustid_app";
CREATE DATABASE "acoustid_fingerprint";
CREATE DATABASE "acoustid_ingest";
CREATE DATABASE "musicbrainz";
CREATE DATABASE "acoustid_test";
\c acoustid
\c acoustid_fingerprint
create extension intarray;
create extension pgcrypto;
create extension acoustid;
\c musicbrainz
create extension pgcrypto;
create extension cube;
\c acoustid_test
......
......@@ -29,6 +29,8 @@ script_location = alembic
# are written from script.py.mako
# output_encoding = utf-8
databases = app,ingest,fingerprint
# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic
......
from __future__ import with_statement
import os
import logging
from alembic import context
from sqlalchemy import engine_from_config, pool
from logging.config import fileConfig
config = context.config
fileConfig(config.config_file_name)
logger = logging.getLogger("alembic.env")
import acoustid.tables
target_metadata = acoustid.tables.metadata
......@@ -17,12 +19,25 @@ acoustid_config = acoustid.config.Config()
acoustid_config.read(acoustid_config_filename)
acoustid_config.read_env()
def include_object(obj, name, type, reflected, compare_to):
if type == "table" and obj.schema == "musicbrainz":
return False
if type == "column" and not obj.table.schema == "musicbrainz":
return False
return True
use_two_phase_commit = acoustid_config.databases.use_two_phase_commit
def include_object(db_name):
def inner(obj, name, obj_type, reflected, compare_to):
if obj_type == "table":
if obj.schema == "musicbrainz":
return False
bind_key = obj.info.get('bind_key', 'main')
if bind_key != db_name:
return False
if obj_type == "column":
if obj.table.schema == "musicbrainz":
return False
bind_key = obj.table.info.get('bind_key', 'main')
if bind_key != db_name:
return False
return True
return inner
def run_migrations_offline():
......@@ -37,13 +52,20 @@ def run_migrations_offline():
script output.
"""
url = acoustid_config.database.create_url()
context.configure(
url=url, target_metadata=target_metadata, literal_binds=True,
include_object=include_object)
for name, db_config in acoustid_config.databases.databases.items():
if name.endswith(':ro') or name == 'musicbrainz':
continue
logger.info("Migrating database %s" % name)
with context.begin_transaction():
context.run_migrations()
context.configure(
url=db_config.create_url(),
target_metadata=target_metadata,
literal_binds=True,
include_object=include_object(name),
)
with context.begin_transaction():
context.run_migrations(engine_name=name)
def run_migrations_online():
......@@ -53,17 +75,47 @@ def run_migrations_online():
and associate a connection with the context.
"""
connectable = acoustid_config.database.create_engine(poolclass=pool.NullPool)
with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=target_metadata,
include_object=include_object,
)
with context.begin_transaction():
context.run_migrations()
engines = {}
for name, db_config in acoustid_config.databases.databases.items():
if name.endswith(':ro') or name == 'musicbrainz':
continue
engines[name] = rec = {}
rec["engine"] = db_config.create_engine(poolclass=pool.NullPool)
for name, rec in engines.items():
engine = rec["engine"]
rec["connection"] = conn = engine.connect()
if use_two_phase_commit:
rec["transaction"] = conn.begin_twophase()
else:
rec["transaction"] = conn.begin()
try:
for name, rec in engines.items():
logger.info("Migrating database %s" % name)
context.configure(
connection=rec["connection"],
upgrade_token="%s_upgrades" % name,
downgrade_token="%s_downgrades" % name,
target_metadata=target_metadata,
include_object=include_object(name),
)
context.run_migrations(engine_name=name)
if use_two_phase_commit:
for rec in engines.values():
rec["transaction"].prepare()
for rec in engines.values():
rec["transaction"].commit()
except:
for rec in engines.values():
rec["transaction"].rollback()
raise
finally:
for rec in engines.values():
rec["connection"].close()
if context.is_offline_mode():
......
"""${message}
<%!
import re
%>"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}
# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
......@@ -12,13 +18,20 @@ down_revision = ${repr(down_revision)}
branch_labels = ${repr(branch_labels)}
depends_on = ${repr(depends_on)}
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}
def upgrade():
${upgrades if upgrades else "pass"}
def upgrade(engine_name):
globals()["upgrade_%s" % engine_name]()
def downgrade(engine_name):
globals()["downgrade_%s" % engine_name]()
% for db_name in re.split(r',\s*', config.get_main_option("databases")):
def upgrade_${db_name}():
${context.get("%s_upgrades" % db_name, "pass")}
def downgrade():
${downgrades if downgrades else "pass"}
def downgrade_${db_name}():
${context.get("%s_downgrades" % db_name, "pass")}
% endfor
"""initial fks
Revision ID: 0c79593066ed
Revises: f9efedfb59a0
Create Date: 2019-11-14 11:36:14.795544
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '0c79593066ed'
down_revision = 'f9efedfb59a0'
branch_labels = None
depends_on = None
def upgrade(engine_name):
globals()["upgrade_%s" % engine_name]()
def downgrade(engine_name):
globals()["downgrade_%s" % engine_name]()
def upgrade_app():
# ### commands auto generated by Alembic - please adjust! ###
op.create_foreign_key(op.f('account_fk_application_id'), 'account', 'application', ['application_id'], ['id'])
op.create_foreign_key(op.f('account_google_fk_account_id'), 'account_google', 'account', ['account_id'], ['id'])
op.create_foreign_key(op.f('account_openid_fk_account_id'), 'account_openid', 'account', ['account_id'], ['id'])
op.create_foreign_key(op.f('application_fk_account_id'), 'application', 'account', ['account_id'], ['id'])
op.create_foreign_key(op.f('source_fk_application_id'), 'source', 'application', ['application_id'], ['id'])
op.create_foreign_key(op.f('source_fk_account_id'), 'source', 'account', ['account_id'], ['id'])
op.create_foreign_key(op.f('stats_lookups_fk_application_id'), 'stats_lookups', 'application', ['application_id'], ['id'])
op.create_foreign_key(op.f('stats_top_accounts_fk_account_id'), 'stats_top_accounts', 'account', ['account_id'], ['id'])
op.create_foreign_key(op.f('stats_user_agents_fk_application_id'), 'stats_user_agents', 'application', ['application_id'], ['id'])
# ### end Alembic commands ###
def downgrade_app():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(op.f('stats_user_agents_fk_application_id'), 'stats_user_agents', type_='foreignkey')
op.drop_constraint(op.f('stats_top_accounts_fk_account_id'), 'stats_top_accounts', type_='foreignkey')
op.drop_constraint(op.f('stats_lookups_fk_application_id'), 'stats_lookups', type_='foreignkey')
op.drop_constraint(op.f('source_fk_account_id'), 'source', type_='foreignkey')
op.drop_constraint(op.f('source_fk_application_id'), 'source', type_='foreignkey')
op.drop_constraint(op.f('application_fk_account_id'), 'application', type_='foreignkey')
op.drop_constraint(op.f('account_openid_fk_account_id'), 'account_openid', type_='foreignkey')
op.drop_constraint(op.f('account_google_fk_account_id'), 'account_google', type_='foreignkey')
op.drop_constraint(op.f('account_fk_application_id'), 'account', type_='foreignkey')
# ### end Alembic commands ###
def upgrade_ingest():
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###
def downgrade_ingest():
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###
def upgrade_fingerprint():
# ### commands auto generated by Alembic - please adjust! ###
op.create_foreign_key(op.f('fingerprint_fk_track_id'), 'fingerprint', 'track', ['track_id'], ['id'])
op.create_foreign_key(op.f('foreignid_fk_vendor_id'), 'foreignid', 'foreignid_vendor', ['vendor_id'], ['id'])
op.create_foreign_key(op.f('track_fk_new_id'), 'track', 'track', ['new_id'], ['id'])
op.create_foreign_key(op.f('track_foreignid_fk_foreignid_id'), 'track_foreignid', 'foreignid', ['foreignid_id'], ['id'])
op.create_foreign_key(op.f('track_foreignid_fk_track_id'), 'track_foreignid', 'track', ['track_id'], ['id'])
op.create_foreign_key(op.f('track_mbid_fk_track_id'), 'track_mbid', 'track', ['track_id'], ['id'])
op.create_foreign_key(op.f('track_meta_fk_track_id'), 'track_meta', 'track', ['track_id'], ['id'])
op.create_foreign_key(op.f('track_meta_fk_meta_id'), 'track_meta', 'meta', ['meta_id'], ['id'])
op.create_foreign_key(op.f('track_puid_fk_track_id'), 'track_puid', 'track', ['track_id'], ['id'])
# ### end Alembic commands ###
def downgrade_fingerprint():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(op.f('track_puid_fk_track_id'), 'track_puid', type_='foreignkey')
op.drop_constraint(op.f('track_meta_fk_meta_id'), 'track_meta', type_='foreignkey')
op.drop_constraint(op.f('track_meta_fk_track_id'), 'track_meta', type_='foreignkey')
op.drop_constraint(op.f('track_mbid_fk_track_id'), 'track_mbid', type_='foreignkey')
op.drop_constraint(op.f('track_foreignid_fk_track_id'), 'track_foreignid', type_='foreignkey')
op.drop_constraint(op.f('track_foreignid_fk_foreignid_id'), 'track_foreignid', type_='foreignkey')
op.drop_constraint(op.f('track_fk_new_id'), 'track', type_='foreignkey')
op.drop_constraint(op.f('foreignid_fk_vendor_id'), 'foreignid', type_='foreignkey')
op.drop_constraint(op.f('fingerprint_fk_track_id'), 'fingerprint', type_='foreignkey')
# ### end Alembic commands ###
"""remove recording_acoustid
Revision ID: 1550d60e9261
Revises: f99ba0e4ed97
Create Date: 2019-09-14 15:28:45.868715
"""
# revision identifiers, used by Alembic.
revision = '1550d60e9261'
down_revision = 'f99ba0e4ed97'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
op.drop_index('recording_acoustid_idx_acoustid', table_name='recording_acoustid')
op.drop_index('recording_acoustid_idx_uniq', table_name='recording_acoustid')
op.drop_table('recording_acoustid')
def downgrade():
op.create_table('recording_acoustid',
sa.Column('id', sa.INTEGER(), autoincrement=False, nullable=False),
sa.Column('acoustid', postgresql.UUID(), autoincrement=False, nullable=False),
sa.Column('recording', postgresql.UUID(), autoincrement=False, nullable=False),
sa.Column('disabled', sa.BOOLEAN(), server_default=sa.text(u'false'), autoincrement=False, nullable=False),
sa.Column('created', postgresql.TIMESTAMP(timezone=True), server_default=sa.text(u'CURRENT_TIMESTAMP'), autoincrement=False, nullable=False),
sa.Column('updated', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True),
sa.PrimaryKeyConstraint('id', name=u'recording_acoustid_pkey')
)
op.create_index('recording_acoustid_idx_uniq', 'recording_acoustid', ['recording', 'acoustid'], unique=True)
op.create_index('recording_acoustid_idx_acoustid', 'recording_acoustid', ['acoustid'], unique=False)
"""fixes
Revision ID: 3b48d5f44110
Revises: 57c4d22c87b8
Create Date: 2016-02-10 21:32:18.123976
"""
# revision identifiers, used by Alembic.
revision = '3b48d5f44110'
down_revision = '57c4d22c87b8'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
def upgrade():
op.create_foreign_key(op.f('account_google_fk_account_id'), 'account_google', 'account', ['account_id'], ['id'])
op.create_foreign_key(op.f('application_fk_account_id'), 'application', 'account', ['account_id'], ['id'])
op.create_foreign_key(op.f('stats_lookups_fk_application_id'), 'stats_lookups', 'application', ['application_id'], ['id'])
op.create_foreign_key(op.f('stats_user_agents_fk_application_id'), 'stats_user_agents', 'application', ['application_id'], ['id'])
op.drop_index('track_foreignid_idx_uniq', table_name='track_foreignid')
op.create_index('track_foreignid_idx_uniq', 'track_foreignid', ['track_id', 'foreignid_id'], unique=True)
op.drop_index('track_mbid_idx_uniq', table_name='track_mbid')
op.create_index('track_mbid_idx_uniq', 'track_mbid', ['track_id', 'mbid'], unique=True)
op.drop_index('track_meta_idx_uniq', table_name='track_meta')
op.create_index('track_meta_idx_uniq', 'track_meta', ['track_id', 'meta_id'], unique=True)
op.drop_index('track_puid_idx_uniq', table_name='track_puid')
op.create_index('track_puid_idx_uniq', 'track_puid', ['track_id', 'puid'], unique=True)
op.alter_column('account', 'created', nullable=False)
op.alter_column('application', 'created', nullable=False)
op.alter_column('track', 'created', nullable=False)
op.alter_column('fingerprint_source', 'created', nullable=False)
op.alter_column('track_mbid', 'created', nullable=False)
op.alter_column('track_mbid_source', 'created', nullable=False)
op.alter_column('track_mbid_change', 'created', nullable=False)
op.alter_column('track_mbid_flag', 'created', nullable=False)
op.alter_column('track_puid', 'created', nullable=False)
op.alter_column('track_puid_source', 'created', nullable=False)
op.alter_column('track_meta', 'created', nullable=False)
op.alter_column('track_meta_source', 'created', nullable=False)
op.alter_column('track_foreignid', 'created', nullable=False)
op.alter_column('track_foreignid_source', 'created', nullable=False)
op.alter_column('recording_acoustid', 'created', nullable=False)
def downgrade():
op.alter_column('recording_acoustid', 'created', nullable=True)
op.alter_column('track_foreignid_source', 'created', nullable=True)
op.alter_column('track_foreignid', 'created', nullable=True)
op.alter_column('track_meta_source', 'created', nullable=True)
op.alter_column('track_meta', 'created', nullable=True)
op.alter_column('track_puid_source', 'created', nullable=True)
op.alter_column('track_puid', 'created', nullable=True)
op.alter_column('track_mbid_flag', 'created', nullable=True)
op.alter_column('track_mbid_change', 'created', nullable=True)
op.alter_column('track_mbid_source', 'created', nullable=True)
op.alter_column('track_mbid', 'created', nullable=True)
op.alter_column('fingerprint_source', 'created', nullable=True)
op.alter_column('track', 'created', nullable=True)
op.alter_column('application', 'created', nullable=True)
op.alter_column('account', 'created', nullable=True)
op.drop_index('track_puid_idx_uniq', table_name='track_puid')
op.create_index('track_puid_idx_uniq', 'track_puid', ['track_id', 'puid'], unique=False)
op.drop_index('track_meta_idx_uniq', table_name='track_meta')
op.create_index('track_meta_idx_uniq', 'track_meta', ['track_id', 'meta_id'], unique=False)
op.drop_index('track_mbid_idx_uniq', table_name='track_mbid')
op.create_index('track_mbid_idx_uniq', 'track_mbid', ['track_id', 'mbid'], unique=False)
op.drop_index('track_foreignid_idx_uniq', table_name='track_foreignid')
op.create_index('track_foreignid_idx_uniq', 'track_foreignid', ['track_id', 'foreignid_id'], unique=False)
op.drop_constraint(op.f('stats_user_agents_fk_application_id'), 'stats_user_agents', type_='foreignkey')
op.drop_constraint(op.f('stats_lookups_fk_application_id'), 'stats_lookups', type_='foreignkey')
op.drop_constraint(op.f('application_fk_account_id'), 'application', type_='foreignkey')
op.drop_constraint(op.f('account_google_fk_account_id'), 'account_google', type_='foreignkey')
"""add submission_result
Revision ID: 64eb873263b6
Revises: 1550d60e9261
Create Date: 2019-09-14 15:45:52.593164
"""
# revision identifiers, used by Alembic.
revision = '64eb873263b6'
down_revision = '1550d60e9261'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
op.create_table('submission_result',
sa.Column('submission_id', sa.Integer(), autoincrement=False, nullable=False),
sa.Column('created', sa.DateTime(timezone=True), nullable=False),
sa.Column('account_id', sa.Integer(), nullable=False),
sa.Column('application_id', sa.Integer(), nullable=False),
sa.Column('application_version', sa.String(), nullable=True),
sa.Column('fingerprint_id', sa.Integer(), nullable=False),
sa.Column('track_id', sa.Integer(), nullable=False),
sa.Column('meta_id', sa.Integer(), nullable=True),
sa.Column('mbid', postgresql.UUID(), nullable=True),
sa.Column('puid', postgresql.UUID(), nullable=True),
sa.Column('foreignid', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('submission_id', name=op.f('submission_result_pkey'))
)
def downgrade():
op.drop_table('submission_result')
"""Remove submission_id constraints
Revision ID: ae7e1e5763ef
Revises: d5c0520500a6
Create Date: 2017-11-12 13:18:02.175779
"""
# revision identifiers, used by Alembic.
revision = 'ae7e1e5763ef'
down_revision = 'd5c0520500a6'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
def upgrade():
op.drop_constraint(u'fingerprint_source_fk_submission_id', 'fingerprint_source', type_='foreignkey')
op.drop_constraint(u'track_foreignid_source_fk_submission_id', 'track_foreignid_source', type_='foreignkey')
op.drop_constraint(u'track_mbid_source_fk_submission_id', 'track_mbid_source', type_='foreignkey')
op.drop_constraint(u'track_meta_source_fk_submission_id', 'track_meta_source', type_='foreignkey')
op.drop_constraint(u'track_puid_source_fk_submission_id', 'track_puid_source', type_='foreignkey')
def downgrade():
op.create_foreign_key(u'track_puid_source_fk_submission_id', 'track_puid_source', 'submission', ['submission_id'], ['id'])
op.create_foreign_key(u'track_meta_source_fk_submission_id', 'track_meta_source', 'submission', ['submission_id'], ['id'])
op.create_foreign_key(u'track_mbid_source_fk_submission_id', 'track_mbid_source', 'submission', ['submission_id'], ['id'])
op.create_foreign_key(u'track_foreignid_source_fk_submission_id', 'track_foreignid_source', 'submission', ['submission_id'], ['id'])
op.create_foreign_key(u'fingerprint_source_fk_submission_id', 'fingerprint_source', 'submission', ['submission_id'], ['id'])
"""account_is_admin
Revision ID: d5c0520500a6
Revises: 3b48d5f44110
Create Date: 2016-02-10 22:52:06.114214
"""
# revision identifiers, used by Alembic.
revision = 'd5c0520500a6'
down_revision = '3b48d5f44110'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('account',
sa.Column('is_admin', sa.Boolean(), server_default=sa.text('false'), nullable=False)
)
def downgrade():
op.drop_column('account', 'is_admin')
"""remove old tables
Revision ID: f99ba0e4ed97
Revises: ae7e1e5763ef
Create Date: 2019-09-14 15:18:20.248950
"""
# revision identifiers, used by Alembic.
revision = 'f99ba0e4ed97'
down_revision = 'ae7e1e5763ef'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
op.drop_table('track_mbid_flag')
op.drop_table('fingerprint_index_queue')
op.drop_table('replication_control')
op.drop_table('mirror_queue')
op.drop_table('acoustid_mb_replication_control')
def downgrade():
op.create_table('acoustid_mb_replication_control',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('current_schema_sequence', sa.INTEGER(), autoincrement=False, nullable=False),
sa.Column('current_replication_sequence', sa.INTEGER(), autoincrement=False, nullable=True),
sa.Column('last_replication_date', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True),
sa.PrimaryKeyConstraint('id', name=u'acoustid_mb_replication_control_pkey')
)
op.create_table('mirror_queue',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('txid', sa.BIGINT(), server_default=sa.text(u'txid_current()'), autoincrement=False, nullable=False),
sa.Column('tblname', sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column('op', sa.CHAR(length=1), autoincrement=False, nullable=False),
sa.Column('data', sa.TEXT(), autoincrement=False, nullable=False),
sa.PrimaryKeyConstraint('id', name=u'mirror_queue_pkey')
)
op.create_table('replication_control',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('current_schema_sequence', sa.INTEGER(), autoincrement=False, nullable=False),
sa.Column('current_replication_sequence', sa.INTEGER(), autoincrement=False, nullable=True),
sa.Column('last_replication_date', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True),
sa.PrimaryKeyConstraint('id', name=u'replication_control_pkey')
)
op.create_table('fingerprint_index_queue',
sa.Column('fingerprint_id', sa.INTEGER(), autoincrement=False, nullable=False)
)
op.create_table('track_mbid_flag',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('track_mbid_id', sa.INTEGER(), autoincrement=False, nullable=False),
sa.Column('account_id', sa.INTEGER(), autoincrement=False, nullable=False),
sa.Column('handled', sa.BOOLEAN(), server_default=sa.text(u'false'), autoincrement=False, nullable=False),
sa.Column('created', postgresql.TIMESTAMP(timezone=True), server_default=sa.text(u'CURRENT_TIMESTAMP'), autoincrement=False, nullable=False),
sa.ForeignKeyConstraint(['account_id'], [u'account.id'], name=u'track_mbid_flag_fk_account_id'),
sa.ForeignKeyConstraint(['track_mbid_id'], [u'track_mbid.id'], name=u'track_mbid_flag_fk_track_mbid_id'),
sa.PrimaryKeyConstraint('id', name=u'track_mbid_flag_pkey')
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment