refac
This commit is contained in:
1 parent
98d3b23085
commit
1b9d22e324
2 files changed
+59
-43
No files matched your search
+17
-10
@@ -20,20 +20,27 @@ depends_on: Union[str, Sequence[str], None] = None
|
|||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
def upgrade() -> None:
|
||||||
|
conn = op.get_bind()
|
||||||
|
inspector = sa.inspect(conn)
|
||||||
|
|
||||||
# Add message_id column to channel_file table
|
# Add message_id column to channel_file table
|
||||||
with op.batch_alter_table('channel_file', schema=None) as batch_op:
|
cf_cols = {c['name'] for c in inspector.get_columns('channel_file')}
|
||||||
batch_op.add_column(
|
if 'message_id' not in cf_cols:
|
||||||
sa.Column(
|
with op.batch_alter_table('channel_file', schema=None) as batch_op:
|
||||||
'message_id',
|
batch_op.add_column(
|
||||||
sa.Text(),
|
sa.Column(
|
||||||
sa.ForeignKey('message.id', ondelete='CASCADE', name='fk_channel_file_message_id'),
|
'message_id',
|
||||||
nullable=True,
|
sa.Text(),
|
||||||
|
sa.ForeignKey('message.id', ondelete='CASCADE', name='fk_channel_file_message_id'),
|
||||||
|
nullable=True,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
# Add data column to knowledge table
|
# Add data column to knowledge table
|
||||||
with op.batch_alter_table('knowledge', schema=None) as batch_op:
|
k_cols = {c['name'] for c in inspector.get_columns('knowledge')}
|
||||||
batch_op.add_column(sa.Column('data', sa.JSON(), nullable=True))
|
if 'data' not in k_cols:
|
||||||
|
with op.batch_alter_table('knowledge', schema=None) as batch_op:
|
||||||
|
batch_op.add_column(sa.Column('data', sa.JSON(), nullable=True))
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
def downgrade() -> None:
|
||||||
|
|||||||
+42
-33
@@ -20,42 +20,53 @@ depends_on: Union[str, Sequence[str], None] = None
|
|||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
def upgrade() -> None:
|
||||||
|
conn = op.get_bind()
|
||||||
|
inspector = sa.inspect(conn)
|
||||||
|
existing_tables = set(inspector.get_table_names())
|
||||||
|
|
||||||
# Update 'channel' table
|
# Update 'channel' table
|
||||||
op.add_column('channel', sa.Column('is_private', sa.Boolean(), nullable=True))
|
channel_cols = {c['name'] for c in inspector.get_columns('channel')}
|
||||||
|
if 'is_private' not in channel_cols:
|
||||||
op.add_column('channel', sa.Column('archived_at', sa.BigInteger(), nullable=True))
|
op.add_column('channel', sa.Column('is_private', sa.Boolean(), nullable=True))
|
||||||
op.add_column('channel', sa.Column('archived_by', sa.Text(), nullable=True))
|
if 'archived_at' not in channel_cols:
|
||||||
|
op.add_column('channel', sa.Column('archived_at', sa.BigInteger(), nullable=True))
|
||||||
op.add_column('channel', sa.Column('deleted_at', sa.BigInteger(), nullable=True))
|
if 'archived_by' not in channel_cols:
|
||||||
op.add_column('channel', sa.Column('deleted_by', sa.Text(), nullable=True))
|
op.add_column('channel', sa.Column('archived_by', sa.Text(), nullable=True))
|
||||||
|
if 'deleted_at' not in channel_cols:
|
||||||
op.add_column('channel', sa.Column('updated_by', sa.Text(), nullable=True))
|
op.add_column('channel', sa.Column('deleted_at', sa.BigInteger(), nullable=True))
|
||||||
|
if 'deleted_by' not in channel_cols:
|
||||||
|
op.add_column('channel', sa.Column('deleted_by', sa.Text(), nullable=True))
|
||||||
|
if 'updated_by' not in channel_cols:
|
||||||
|
op.add_column('channel', sa.Column('updated_by', sa.Text(), nullable=True))
|
||||||
|
|
||||||
# Update 'channel_member' table
|
# Update 'channel_member' table
|
||||||
op.add_column('channel_member', sa.Column('role', sa.Text(), nullable=True))
|
cm_cols = {c['name'] for c in inspector.get_columns('channel_member')}
|
||||||
op.add_column('channel_member', sa.Column('invited_by', sa.Text(), nullable=True))
|
if 'role' not in cm_cols:
|
||||||
op.add_column('channel_member', sa.Column('invited_at', sa.BigInteger(), nullable=True))
|
op.add_column('channel_member', sa.Column('role', sa.Text(), nullable=True))
|
||||||
|
if 'invited_by' not in cm_cols:
|
||||||
|
op.add_column('channel_member', sa.Column('invited_by', sa.Text(), nullable=True))
|
||||||
|
if 'invited_at' not in cm_cols:
|
||||||
|
op.add_column('channel_member', sa.Column('invited_at', sa.BigInteger(), nullable=True))
|
||||||
|
|
||||||
# Create 'channel_webhook' table
|
# Create 'channel_webhook' table
|
||||||
op.create_table(
|
if 'channel_webhook' not in existing_tables:
|
||||||
'channel_webhook',
|
op.create_table(
|
||||||
sa.Column('id', sa.Text(), primary_key=True, unique=True, nullable=False),
|
'channel_webhook',
|
||||||
sa.Column('user_id', sa.Text(), nullable=False),
|
sa.Column('id', sa.Text(), primary_key=True, unique=True, nullable=False),
|
||||||
sa.Column(
|
sa.Column('user_id', sa.Text(), nullable=False),
|
||||||
'channel_id',
|
sa.Column(
|
||||||
sa.Text(),
|
'channel_id',
|
||||||
sa.ForeignKey('channel.id', ondelete='CASCADE'),
|
sa.Text(),
|
||||||
nullable=False,
|
sa.ForeignKey('channel.id', ondelete='CASCADE'),
|
||||||
),
|
nullable=False,
|
||||||
sa.Column('name', sa.Text(), nullable=False),
|
),
|
||||||
sa.Column('profile_image_url', sa.Text(), nullable=True),
|
sa.Column('name', sa.Text(), nullable=False),
|
||||||
sa.Column('token', sa.Text(), nullable=False),
|
sa.Column('profile_image_url', sa.Text(), nullable=True),
|
||||||
sa.Column('last_used_at', sa.BigInteger(), nullable=True),
|
sa.Column('token', sa.Text(), nullable=False),
|
||||||
sa.Column('created_at', sa.BigInteger(), nullable=False),
|
sa.Column('last_used_at', sa.BigInteger(), nullable=True),
|
||||||
sa.Column('updated_at', sa.BigInteger(), nullable=False),
|
sa.Column('created_at', sa.BigInteger(), nullable=False),
|
||||||
)
|
sa.Column('updated_at', sa.BigInteger(), nullable=False),
|
||||||
|
)
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
def downgrade() -> None:
|
||||||
@@ -74,5 +85,3 @@ def downgrade() -> None:
|
|||||||
|
|
||||||
# Drop 'channel_webhook' table
|
# Drop 'channel_webhook' table
|
||||||
op.drop_table('channel_webhook')
|
op.drop_table('channel_webhook')
|
||||||
|
|
||||||
pass
|
|
||||||
Reference in new issue
Block a user