|
@ -8,7 +8,6 @@ Create Date: 2021-03-13 20:29:10.062757 |
|
|
from alembic import op |
|
|
from alembic import op |
|
|
import sqlalchemy as sa |
|
|
import sqlalchemy as sa |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# revision identifiers, used by Alembic. |
|
|
# revision identifiers, used by Alembic. |
|
|
from sqlalchemy.exc import OperationalError |
|
|
from sqlalchemy.exc import OperationalError |
|
|
|
|
|
|
|
@ -17,6 +16,7 @@ down_revision = None |
|
|
branch_labels = None |
|
|
branch_labels = None |
|
|
depends_on = None |
|
|
depends_on = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def ignore_duplicate(fn): |
|
|
def ignore_duplicate(fn): |
|
|
try: |
|
|
try: |
|
|
fn() |
|
|
fn() |
|
@ -24,18 +24,20 @@ def ignore_duplicate(fn): |
|
|
if "duplicate" in str(e): |
|
|
if "duplicate" in str(e): |
|
|
pass |
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def upgrade(): |
|
|
def upgrade(): |
|
|
# ### commands auto generated by Alembic - please adjust! ### |
|
|
# ### commands auto generated by Alembic - please adjust! ### |
|
|
try: |
|
|
try: |
|
|
op.create_table('api_keys', |
|
|
op.create_table('api_keys', |
|
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), |
|
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), |
|
|
sa.Column('key', sa.String(), nullable=True), |
|
|
sa.Column('key', sa.String(), nullable=True), |
|
|
sa.Column('user_id', sa.Integer(), nullable=True), |
|
|
sa.Column('user_id', sa.Integer(), nullable=True), |
|
|
sa.Column('created_date', sa.DateTime(), nullable=True), |
|
|
sa.Column('created_date', sa.DateTime(), nullable=True), |
|
|
sa.ForeignKeyConstraint(['user_id'], ['users.id'], name='fk_user_api_key_user_id', onupdate='CASCADE', ondelete='CASCADE'), |
|
|
sa.ForeignKeyConstraint(['user_id'], ['users.id'], name='fk_user_api_key_user_id', |
|
|
sa.PrimaryKeyConstraint('id'), |
|
|
onupdate='CASCADE', ondelete='CASCADE'), |
|
|
sa.UniqueConstraint('key') |
|
|
sa.PrimaryKeyConstraint('id'), |
|
|
) |
|
|
sa.UniqueConstraint('key') |
|
|
|
|
|
) |
|
|
except OperationalError: |
|
|
except OperationalError: |
|
|
pass |
|
|
pass |
|
|
|
|
|
|
|
@ -51,7 +53,8 @@ def upgrade(): |
|
|
batch_op.drop_constraint("fk_peer_server_id_server", type_="foreignkey") |
|
|
batch_op.drop_constraint("fk_peer_server_id_server", type_="foreignkey") |
|
|
|
|
|
|
|
|
with op.batch_alter_table('peer', schema=None) as batch_op: |
|
|
with op.batch_alter_table('peer', schema=None) as batch_op: |
|
|
batch_op.create_foreign_key('fk_peer_server_id_server', 'server', ['server_id'], ['id'], onupdate='CASCADE', ondelete='CASCADE') |
|
|
batch_op.create_foreign_key('fk_peer_server_id_server', 'server', ['server_id'], ['id'], onupdate='CASCADE', |
|
|
|
|
|
ondelete='CASCADE') |
|
|
|
|
|
|
|
|
ignore_duplicate(lambda: op.add_column('peer', sa.Column('configuration', sa.Text(), nullable=True))) |
|
|
ignore_duplicate(lambda: op.add_column('peer', sa.Column('configuration', sa.Text(), nullable=True))) |
|
|
ignore_duplicate(lambda: op.add_column('peer', sa.Column('keep_alive', sa.Integer(), nullable=True))) |
|
|
ignore_duplicate(lambda: op.add_column('peer', sa.Column('keep_alive', sa.Integer(), nullable=True))) |
|
@ -60,11 +63,9 @@ def upgrade(): |
|
|
ignore_duplicate(lambda: op.add_column('peer', sa.Column('shared_key', sa.Text(), nullable=True))) |
|
|
ignore_duplicate(lambda: op.add_column('peer', sa.Column('shared_key', sa.Text(), nullable=True))) |
|
|
ignore_duplicate(lambda: op.add_column('peer', sa.Column('v6_address', sa.String(), nullable=True))) |
|
|
ignore_duplicate(lambda: op.add_column('peer', sa.Column('v6_address', sa.String(), nullable=True))) |
|
|
|
|
|
|
|
|
|
|
|
# op.drop_constraint(None, 'peer', type_='foreignkey') |
|
|
#op.drop_constraint(None, 'peer', type_='foreignkey') |
|
|
|
|
|
# |
|
|
# |
|
|
#op.drop_column('peer', 'server') |
|
|
# op.drop_column('peer', 'server') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
|
with op.batch_alter_table('peer', schema=None) as batch_op: |
|
|
with op.batch_alter_table('peer', schema=None) as batch_op: |
|
@ -80,8 +81,7 @@ def upgrade(): |
|
|
ignore_duplicate(lambda: op.add_column('server', sa.Column('subnet', sa.Integer(), nullable=False))) |
|
|
ignore_duplicate(lambda: op.add_column('server', sa.Column('subnet', sa.Integer(), nullable=False))) |
|
|
ignore_duplicate(lambda: op.add_column('server', sa.Column('v6_address', sa.String(), nullable=True))) |
|
|
ignore_duplicate(lambda: op.add_column('server', sa.Column('v6_address', sa.String(), nullable=True))) |
|
|
ignore_duplicate(lambda: op.add_column('server', sa.Column('v6_subnet', sa.Integer(), nullable=False))) |
|
|
ignore_duplicate(lambda: op.add_column('server', sa.Column('v6_subnet', sa.Integer(), nullable=False))) |
|
|
#op.create_unique_constraint(None, 'server', ['v6_address']) |
|
|
# op.create_unique_constraint(None, 'server', ['v6_address']) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
|
with op.batch_alter_table('server', schema=None) as batch_op: |
|
|
with op.batch_alter_table('server', schema=None) as batch_op: |
|
|