refac
This commit is contained in:
+18
-5
@@ -20,8 +20,14 @@ depends_on: Union[str, Sequence[str], None] = None
|
|||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
def upgrade() -> None:
|
||||||
|
conn = op.get_bind()
|
||||||
|
inspector = sa.inspect(conn)
|
||||||
|
|
||||||
# New columns to be added to channel_member table
|
# New columns to be added to channel_member table
|
||||||
|
cm_cols = {c['name'] for c in inspector.get_columns('channel_member')}
|
||||||
|
if 'status' not in cm_cols:
|
||||||
op.add_column('channel_member', sa.Column('status', sa.Text(), nullable=True))
|
op.add_column('channel_member', sa.Column('status', sa.Text(), nullable=True))
|
||||||
|
if 'is_active' not in cm_cols:
|
||||||
op.add_column(
|
op.add_column(
|
||||||
'channel_member',
|
'channel_member',
|
||||||
sa.Column(
|
sa.Column(
|
||||||
@@ -32,7 +38,7 @@ def upgrade() -> None:
|
|||||||
server_default=sa.sql.expression.true(),
|
server_default=sa.sql.expression.true(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
if 'is_channel_muted' not in cm_cols:
|
||||||
op.add_column(
|
op.add_column(
|
||||||
'channel_member',
|
'channel_member',
|
||||||
sa.Column(
|
sa.Column(
|
||||||
@@ -43,6 +49,7 @@ def upgrade() -> None:
|
|||||||
server_default=sa.sql.expression.false(),
|
server_default=sa.sql.expression.false(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
if 'is_channel_pinned' not in cm_cols:
|
||||||
op.add_column(
|
op.add_column(
|
||||||
'channel_member',
|
'channel_member',
|
||||||
sa.Column(
|
sa.Column(
|
||||||
@@ -53,18 +60,22 @@ def upgrade() -> None:
|
|||||||
server_default=sa.sql.expression.false(),
|
server_default=sa.sql.expression.false(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
if 'data' not in cm_cols:
|
||||||
op.add_column('channel_member', sa.Column('data', sa.JSON(), nullable=True))
|
op.add_column('channel_member', sa.Column('data', sa.JSON(), nullable=True))
|
||||||
|
if 'meta' not in cm_cols:
|
||||||
op.add_column('channel_member', sa.Column('meta', sa.JSON(), nullable=True))
|
op.add_column('channel_member', sa.Column('meta', sa.JSON(), nullable=True))
|
||||||
|
if 'joined_at' not in cm_cols:
|
||||||
op.add_column('channel_member', sa.Column('joined_at', sa.BigInteger(), nullable=False))
|
op.add_column('channel_member', sa.Column('joined_at', sa.BigInteger(), nullable=False))
|
||||||
|
if 'left_at' not in cm_cols:
|
||||||
op.add_column('channel_member', sa.Column('left_at', sa.BigInteger(), nullable=True))
|
op.add_column('channel_member', sa.Column('left_at', sa.BigInteger(), nullable=True))
|
||||||
|
if 'last_read_at' not in cm_cols:
|
||||||
op.add_column('channel_member', sa.Column('last_read_at', sa.BigInteger(), nullable=True))
|
op.add_column('channel_member', sa.Column('last_read_at', sa.BigInteger(), nullable=True))
|
||||||
|
if 'updated_at' not in cm_cols:
|
||||||
op.add_column('channel_member', sa.Column('updated_at', sa.BigInteger(), nullable=True))
|
op.add_column('channel_member', sa.Column('updated_at', sa.BigInteger(), nullable=True))
|
||||||
|
|
||||||
# New columns to be added to message table
|
# New columns to be added to message table
|
||||||
|
msg_cols = {c['name'] for c in inspector.get_columns('message')}
|
||||||
|
if 'is_pinned' not in msg_cols:
|
||||||
op.add_column(
|
op.add_column(
|
||||||
'message',
|
'message',
|
||||||
sa.Column(
|
sa.Column(
|
||||||
@@ -75,7 +86,9 @@ def upgrade() -> None:
|
|||||||
server_default=sa.sql.expression.false(),
|
server_default=sa.sql.expression.false(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
if 'pinned_at' not in msg_cols:
|
||||||
op.add_column('message', sa.Column('pinned_at', sa.BigInteger(), nullable=True))
|
op.add_column('message', sa.Column('pinned_at', sa.BigInteger(), nullable=True))
|
||||||
|
if 'pinned_by' not in msg_cols:
|
||||||
op.add_column('message', sa.Column('pinned_by', sa.Text(), nullable=True))
|
op.add_column('message', sa.Column('pinned_by', sa.Text(), nullable=True))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,11 @@ from sqlalchemy.sql import column, table
|
|||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
def upgrade() -> None:
|
||||||
|
conn = op.get_bind()
|
||||||
|
inspector = sa.inspect(conn)
|
||||||
|
existing_tables = set(inspector.get_table_names())
|
||||||
|
|
||||||
|
if 'pinned_note' not in existing_tables:
|
||||||
op.create_table(
|
op.create_table(
|
||||||
'pinned_note',
|
'pinned_note',
|
||||||
sa.Column('id', sa.Text(), nullable=False),
|
sa.Column('id', sa.Text(), nullable=False),
|
||||||
@@ -37,8 +42,6 @@ def upgrade() -> None:
|
|||||||
sa.UniqueConstraint('user_id', 'note_id', name='uq_pinned_note'),
|
sa.UniqueConstraint('user_id', 'note_id', name='uq_pinned_note'),
|
||||||
)
|
)
|
||||||
|
|
||||||
conn = op.get_bind()
|
|
||||||
|
|
||||||
note_table = table('note', column('id', sa.Text), column('user_id', sa.Text), column('is_pinned', sa.Boolean))
|
note_table = table('note', column('id', sa.Text), column('user_id', sa.Text), column('is_pinned', sa.Boolean))
|
||||||
|
|
||||||
pinned_note_table = table(
|
pinned_note_table = table(
|
||||||
|
|||||||
Reference in New Issue
Block a user