more robust migrations

This commit is contained in:
2025-06-02 18:58:48 +02:00
parent 4dbaa27cba
commit 5c6c3f436e
51 changed files with 401 additions and 273 deletions

View File

@@ -19,23 +19,41 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
inspector = inspect(conn)
columns = [col['name'] for col in inspector.get_columns('message')]
with op.batch_alter_table('message', schema=None) as batch_op: with op.batch_alter_table('message', schema=None) as batch_op:
batch_op.add_column(sa.Column('has_attachment', sa.Boolean(), nullable=True)) if 'has_attachment' not in columns:
batch_op.add_column(sa.Column('attachment_name', sa.String(length=255), nullable=True)) batch_op.add_column(sa.Column('has_attachment', sa.Boolean(), nullable=True))
batch_op.add_column(sa.Column('attachment_path', sa.String(length=512), nullable=True)) if 'attachment_name' not in columns:
batch_op.add_column(sa.Column('attachment_type', sa.String(length=100), nullable=True)) batch_op.add_column(sa.Column('attachment_name', sa.String(length=255), nullable=True))
batch_op.add_column(sa.Column('attachment_size', sa.Integer(), nullable=True)) if 'attachment_path' not in columns:
batch_op.add_column(sa.Column('attachment_path', sa.String(length=512), nullable=True))
if 'attachment_type' not in columns:
batch_op.add_column(sa.Column('attachment_type', sa.String(length=100), nullable=True))
if 'attachment_size' not in columns:
batch_op.add_column(sa.Column('attachment_size', sa.Integer(), nullable=True))
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
inspector = inspect(conn)
columns = [col['name'] for col in inspector.get_columns('message')]
with op.batch_alter_table('message', schema=None) as batch_op: with op.batch_alter_table('message', schema=None) as batch_op:
batch_op.drop_column('attachment_size') if 'attachment_size' in columns:
batch_op.drop_column('attachment_type') batch_op.drop_column('attachment_size')
batch_op.drop_column('attachment_path') if 'attachment_type' in columns:
batch_op.drop_column('attachment_name') batch_op.drop_column('attachment_type')
batch_op.drop_column('has_attachment') if 'attachment_path' in columns:
batch_op.drop_column('attachment_path')
if 'attachment_name' in columns:
batch_op.drop_column('attachment_name')
if 'has_attachment' in columns:
batch_op.drop_column('has_attachment')
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@@ -22,20 +22,20 @@ def upgrade():
conn = op.get_bind() conn = op.get_bind()
inspector = sa.inspect(conn) inspector = sa.inspect(conn)
if 'user' not in inspector.get_table_names(): if 'user' not in inspector.get_table_names():
conn = op.get_bind() conn = op.get_bind()
inspector = inspect(conn) inspector = inspect(conn)
tables = inspector.get_table_names() tables = inspector.get_table_names()
if 'user' not in tables: if 'user' not in tables:
op.create_table('user', op.create_table('user',
sa.Column('id', sa.Integer(), nullable=False), sa.Column('id', sa.Integer(), nullable=False),
sa.Column('username', sa.String(length=150), nullable=False), sa.Column('username', sa.String(length=150), nullable=False),
sa.Column('email', sa.String(length=150), nullable=False), sa.Column('email', sa.String(length=150), nullable=False),
sa.Column('password_hash', sa.String(length=128), nullable=True), sa.Column('password_hash', sa.String(length=128), nullable=True),
sa.PrimaryKeyConstraint('id'), sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email'), sa.UniqueConstraint('email'),
sa.UniqueConstraint('username') sa.UniqueConstraint('username')
) )
def downgrade(): def downgrade():

View File

@@ -19,25 +19,25 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind() conn = op.get_bind()
inspector = inspect(conn) inspector = inspect(conn)
tables = inspector.get_table_names() tables = inspector.get_table_names()
if 'mails' not in tables: if 'mails' not in tables:
op.create_table('mails', op.create_table('mails',
sa.Column('id', sa.Integer(), nullable=False), sa.Column('id', sa.Integer(), nullable=False),
sa.Column('recipient', sa.String(length=150), nullable=False), sa.Column('recipient', sa.String(length=150), nullable=False),
sa.Column('subject', sa.String(length=200), nullable=False), sa.Column('subject', sa.String(length=200), nullable=False),
sa.Column('body', sa.Text(), nullable=False), sa.Column('body', sa.Text(), nullable=False),
sa.Column('status', sa.String(length=20), nullable=False), sa.Column('status', sa.String(length=20), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('sent_at', sa.DateTime(), nullable=True), sa.Column('sent_at', sa.DateTime(), nullable=True),
sa.Column('template_id', sa.Integer(), nullable=True), sa.Column('template_id', sa.Integer(), nullable=True),
sa.Column('notif_id', sa.Integer(), nullable=True), sa.Column('notif_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['notif_id'], ['notifs.id'], ), sa.ForeignKeyConstraint(['notif_id'], ['notifs.id'], ),
sa.ForeignKeyConstraint(['template_id'], ['email_templates.id'], ), sa.ForeignKeyConstraint(['template_id'], ['email_templates.id'], ),
sa.PrimaryKeyConstraint('id') sa.PrimaryKeyConstraint('id')
) )
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@@ -19,15 +19,25 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
inspector = inspect(conn)
columns = [col['name'] for col in inspector.get_columns('contact')]
with op.batch_alter_table('contact', schema=None) as batch_op: with op.batch_alter_table('contact', schema=None) as batch_op:
batch_op.add_column(sa.Column('is_admin', sa.Boolean(), nullable=True)) if 'is_admin' not in columns:
batch_op.add_column(sa.Column('is_admin', sa.Boolean(), nullable=True))
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
inspector = inspect(conn)
columns = [col['name'] for col in inspector.get_columns('contact')]
with op.batch_alter_table('contact', schema=None) as batch_op: with op.batch_alter_table('contact', schema=None) as batch_op:
batch_op.drop_column('is_admin') if 'is_admin' in columns:
batch_op.drop_column('is_admin')
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@@ -25,18 +25,18 @@ def upgrade():
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind() conn = op.get_bind()
inspector = inspect(conn) inspector = inspect(conn)
tables = inspector.get_table_names() tables = inspector.get_table_names()
if 'template_variables' not in tables: if 'template_variables' not in tables:
op.create_table('template_variables', op.create_table('template_variables',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('notification_type', sa.VARCHAR(length=50), autoincrement=False, nullable=False), sa.Column('notification_type', sa.VARCHAR(length=50), autoincrement=False, nullable=False),
sa.Column('variable_name', sa.VARCHAR(length=50), autoincrement=False, nullable=False), sa.Column('variable_name', sa.VARCHAR(length=50), autoincrement=False, nullable=False),
sa.Column('description', sa.VARCHAR(length=200), autoincrement=False, nullable=False), sa.Column('description', sa.VARCHAR(length=200), autoincrement=False, nullable=False),
sa.Column('example_value', sa.VARCHAR(length=200), autoincrement=False, nullable=True), sa.Column('example_value', sa.VARCHAR(length=200), autoincrement=False, nullable=True),
sa.Column('created_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True), sa.Column('created_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
sa.PrimaryKeyConstraint('id', name=op.f('template_variables_pkey')) sa.PrimaryKeyConstraint('id', name=op.f('template_variables_pkey'))
) )
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@@ -19,27 +19,31 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind() conn = op.get_bind()
inspector = inspect(conn) inspector = inspect(conn)
tables = inspector.get_table_names() tables = inspector.get_table_names()
if 'room_file' not in tables: if 'room_file' not in tables:
op.create_table('room_file', op.create_table('room_file',
sa.Column('id', sa.Integer(), nullable=False), sa.Column('id', sa.Integer(), nullable=False),
sa.Column('room_id', sa.Integer(), nullable=False), sa.Column('room_id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False), sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('path', sa.String(length=1024), nullable=False), sa.Column('path', sa.String(length=1024), nullable=False),
sa.Column('type', sa.String(length=10), nullable=False), sa.Column('type', sa.String(length=10), nullable=False),
sa.Column('size', sa.BigInteger(), nullable=True), sa.Column('size', sa.BigInteger(), nullable=True),
sa.Column('modified', sa.Float(), nullable=True), sa.Column('modified', sa.Float(), nullable=True),
sa.Column('uploaded_by', sa.Integer(), nullable=False), sa.Column('uploaded_by', sa.Integer(), nullable=False),
sa.Column('uploaded_at', sa.DateTime(), nullable=False), sa.Column('uploaded_at', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['room_id'], ['room.id'], ), sa.ForeignKeyConstraint(['room_id'], ['room.id'], ),
sa.ForeignKeyConstraint(['uploaded_by'], ['user.id'], ), sa.ForeignKeyConstraint(['uploaded_by'], ['user.id'], ),
sa.PrimaryKeyConstraint('id') sa.PrimaryKeyConstraint('id')
) )
with op.batch_alter_table('room_member_permissions', schema=None) as batch_op:
batch_op.drop_column('preferred_view') # Check if preferred_view column exists before trying to drop it
columns = [col['name'] for col in inspector.get_columns('room_member_permissions')]
if 'preferred_view' in columns:
with op.batch_alter_table('room_member_permissions', schema=None) as batch_op:
batch_op.drop_column('preferred_view')
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@@ -19,43 +19,63 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
inspector = inspect(conn)
columns = [col['name'] for col in inspector.get_columns('room_file')]
with op.batch_alter_table('room_file', schema=None) as batch_op: with op.batch_alter_table('room_file', schema=None) as batch_op:
batch_op.add_column(sa.Column('starred', sa.Boolean(), nullable=True)) if 'starred' not in columns:
batch_op.alter_column('path', batch_op.add_column(sa.Column('starred', sa.Boolean(), nullable=True))
existing_type=sa.VARCHAR(length=1024),
type_=sa.String(length=255), # Only alter columns if they exist
existing_nullable=False) if 'path' in columns:
batch_op.alter_column('size', batch_op.alter_column('path',
existing_type=sa.BIGINT(), existing_type=sa.VARCHAR(length=1024),
type_=sa.Integer(), type_=sa.String(length=255),
existing_nullable=True) existing_nullable=False)
batch_op.alter_column('uploaded_by', if 'size' in columns:
existing_type=sa.INTEGER(), batch_op.alter_column('size',
nullable=True) existing_type=sa.BIGINT(),
batch_op.alter_column('uploaded_at', type_=sa.Integer(),
existing_type=postgresql.TIMESTAMP(), existing_nullable=True)
nullable=True) if 'uploaded_by' in columns:
batch_op.alter_column('uploaded_by',
existing_type=sa.INTEGER(),
nullable=True)
if 'uploaded_at' in columns:
batch_op.alter_column('uploaded_at',
existing_type=postgresql.TIMESTAMP(),
nullable=True)
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
inspector = inspect(conn)
columns = [col['name'] for col in inspector.get_columns('room_file')]
with op.batch_alter_table('room_file', schema=None) as batch_op: with op.batch_alter_table('room_file', schema=None) as batch_op:
batch_op.alter_column('uploaded_at', if 'uploaded_at' in columns:
existing_type=postgresql.TIMESTAMP(), batch_op.alter_column('uploaded_at',
nullable=False) existing_type=postgresql.TIMESTAMP(),
batch_op.alter_column('uploaded_by', nullable=False)
existing_type=sa.INTEGER(), if 'uploaded_by' in columns:
nullable=False) batch_op.alter_column('uploaded_by',
batch_op.alter_column('size', existing_type=sa.INTEGER(),
existing_type=sa.Integer(), nullable=False)
type_=sa.BIGINT(), if 'size' in columns:
existing_nullable=True) batch_op.alter_column('size',
batch_op.alter_column('path', existing_type=sa.Integer(),
existing_type=sa.String(length=255), type_=sa.BIGINT(),
type_=sa.VARCHAR(length=1024), existing_nullable=True)
existing_nullable=False) if 'path' in columns:
batch_op.drop_column('starred') batch_op.alter_column('path',
existing_type=sa.String(length=255),
type_=sa.VARCHAR(length=1024),
existing_nullable=False)
if 'starred' in columns:
batch_op.drop_column('starred')
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@@ -19,17 +19,31 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
inspector = inspect(conn)
columns = [col['name'] for col in inspector.get_columns('site_settings')]
with op.batch_alter_table('site_settings', schema=None) as batch_op: with op.batch_alter_table('site_settings', schema=None) as batch_op:
batch_op.add_column(sa.Column('company_website', sa.String(length=200), nullable=True)) if 'company_website' not in columns:
batch_op.add_column(sa.Column('company_email', sa.String(length=100), nullable=True)) batch_op.add_column(sa.Column('company_website', sa.String(length=200), nullable=True))
batch_op.add_column(sa.Column('company_phone', sa.String(length=20), nullable=True)) if 'company_email' not in columns:
batch_op.add_column(sa.Column('company_address', sa.String(length=200), nullable=True)) batch_op.add_column(sa.Column('company_email', sa.String(length=100), nullable=True))
batch_op.add_column(sa.Column('company_city', sa.String(length=100), nullable=True)) if 'company_phone' not in columns:
batch_op.add_column(sa.Column('company_state', sa.String(length=100), nullable=True)) batch_op.add_column(sa.Column('company_phone', sa.String(length=20), nullable=True))
batch_op.add_column(sa.Column('company_zip', sa.String(length=20), nullable=True)) if 'company_address' not in columns:
batch_op.add_column(sa.Column('company_country', sa.String(length=100), nullable=True)) batch_op.add_column(sa.Column('company_address', sa.String(length=200), nullable=True))
batch_op.add_column(sa.Column('company_description', sa.Text(), nullable=True)) if 'company_city' not in columns:
batch_op.add_column(sa.Column('company_industry', sa.String(length=100), nullable=True)) batch_op.add_column(sa.Column('company_city', sa.String(length=100), nullable=True))
if 'company_state' not in columns:
batch_op.add_column(sa.Column('company_state', sa.String(length=100), nullable=True))
if 'company_zip' not in columns:
batch_op.add_column(sa.Column('company_zip', sa.String(length=20), nullable=True))
if 'company_country' not in columns:
batch_op.add_column(sa.Column('company_country', sa.String(length=100), nullable=True))
if 'company_description' not in columns:
batch_op.add_column(sa.Column('company_description', sa.Text(), nullable=True))
if 'company_industry' not in columns:
batch_op.add_column(sa.Column('company_industry', sa.String(length=100), nullable=True))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@@ -10,6 +10,7 @@ import sqlalchemy as sa
from sqlalchemy import inspect from sqlalchemy import inspect
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '9faab7ef6036' revision = '9faab7ef6036'
down_revision = 'ca9026520dad' down_revision = 'ca9026520dad'
@@ -19,35 +20,35 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind() conn = op.get_bind()
inspector = inspect(conn) inspector = inspect(conn)
tables = inspector.get_table_names() tables = inspector.get_table_names()
if 'site_settings' not in tables: if 'site_settings' not in tables:
op.create_table('site_settings', op.create_table('site_settings',
sa.Column('id', sa.Integer(), nullable=False), sa.Column('id', sa.Integer(), nullable=False),
sa.Column('primary_color', sa.String(length=7), nullable=True), sa.Column('primary_color', sa.String(length=7), nullable=True),
sa.Column('secondary_color', sa.String(length=7), nullable=True), sa.Column('secondary_color', sa.String(length=7), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True), sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id') sa.PrimaryKeyConstraint('id')
) )
op.drop_table('color_settings') op.drop_table('color_settings')
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind() conn = op.get_bind()
inspector = inspect(conn) inspector = inspect(conn)
tables = inspector.get_table_names() tables = inspector.get_table_names()
if 'color_settings' not in tables: if 'color_settings' not in tables:
op.create_table('color_settings', op.create_table('color_settings',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('primary_color', sa.VARCHAR(length=7), autoincrement=False, nullable=True), sa.Column('primary_color', sa.VARCHAR(length=7), autoincrement=False, nullable=True),
sa.Column('secondary_color', sa.VARCHAR(length=7), autoincrement=False, nullable=True), sa.Column('secondary_color', sa.VARCHAR(length=7), autoincrement=False, nullable=True),
sa.Column('updated_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True), sa.Column('updated_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
sa.PrimaryKeyConstraint('id', name=op.f('color_settings_pkey')) sa.PrimaryKeyConstraint('id', name=op.f('color_settings_pkey'))
) )
op.drop_table('site_settings') op.drop_table('site_settings')
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@@ -19,51 +19,51 @@ depends_on = None
def upgrade(): def upgrade():
# Create conversation table first # Create conversation table first
conn = op.get_bind() conn = op.get_bind()
inspector = inspect(conn) inspector = inspect(conn)
tables = inspector.get_table_names() tables = inspector.get_table_names()
if 'conversation' not in tables: if 'conversation' not in tables:
op.create_table('conversation', op.create_table('conversation',
sa.Column('id', sa.Integer(), nullable=False), sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=100), nullable=False), sa.Column('name', sa.String(length=100), nullable=False),
sa.Column('description', sa.Text(), nullable=True), sa.Column('description', sa.Text(), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('created_by', sa.Integer(), nullable=False), sa.Column('created_by', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['created_by'], ['user.id'], ), sa.ForeignKeyConstraint(['created_by'], ['user.id'], ),
sa.PrimaryKeyConstraint('id') sa.PrimaryKeyConstraint('id')
) )
# Create conversation_members table # Create conversation_members table
conn = op.get_bind() conn = op.get_bind()
inspector = inspect(conn) inspector = inspect(conn)
tables = inspector.get_table_names() tables = inspector.get_table_names()
if 'conversation_members' not in tables: if 'conversation_members' not in tables:
op.create_table('conversation_members', op.create_table('conversation_members',
sa.Column('conversation_id', sa.Integer(), nullable=False), sa.Column('conversation_id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['conversation_id'], ['conversation.id'], ), sa.ForeignKeyConstraint(['conversation_id'], ['conversation.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('conversation_id', 'user_id') sa.PrimaryKeyConstraint('conversation_id', 'user_id')
) )
# Create message table # Create message table
conn = op.get_bind() conn = op.get_bind()
inspector = inspect(conn) inspector = inspect(conn)
tables = inspector.get_table_names() tables = inspector.get_table_names()
if 'message' not in tables: if 'message' not in tables:
op.create_table('message', op.create_table('message',
sa.Column('id', sa.Integer(), nullable=False), sa.Column('id', sa.Integer(), nullable=False),
sa.Column('content', sa.Text(), nullable=False), sa.Column('content', sa.Text(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('conversation_id', sa.Integer(), nullable=False), sa.Column('conversation_id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['conversation_id'], ['conversation.id'], ), sa.ForeignKeyConstraint(['conversation_id'], ['conversation.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id') sa.PrimaryKeyConstraint('id')
) )
def downgrade(): def downgrade():

View File

@@ -17,9 +17,15 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
inspector = inspect(conn)
columns = [col['name'] for col in inspector.get_columns('room_file')]
with op.batch_alter_table('room_file', schema=None) as batch_op: with op.batch_alter_table('room_file', schema=None) as batch_op:
batch_op.add_column(sa.Column('deleted_by', sa.Integer(), nullable=True)) if 'deleted_by' not in columns:
batch_op.add_column(sa.Column('deleted_at', sa.DateTime(), nullable=True)) batch_op.add_column(sa.Column('deleted_by', sa.Integer(), nullable=True))
if 'deleted_at' not in columns:
batch_op.add_column(sa.Column('deleted_at', sa.DateTime(), nullable=True))
batch_op.create_foreign_key('fk_room_file_deleted_by_user', 'user', ['deleted_by'], ['id']) batch_op.create_foreign_key('fk_room_file_deleted_by_user', 'user', ['deleted_by'], ['id'])
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@@ -17,8 +17,13 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('room_file', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('deleted', sa.Boolean(), nullable=False, server_default='false')) inspector = inspect(conn)
columns = [col['name'] for col in inspector.get_columns('room_file')]
if 'deleted' not in columns:
with op.batch_alter_table('room_file', schema=None) as batch_op:
batch_op.add_column(sa.Column('deleted', sa.Boolean(), nullable=False, server_default='false'))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@@ -18,28 +18,28 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind() conn = op.get_bind()
inspector = inspect(conn) inspector = inspect(conn)
tables = inspector.get_table_names() tables = inspector.get_table_names()
if 'trashed_file' not in tables: if 'trashed_file' not in tables:
op.create_table('trashed_file', op.create_table('trashed_file',
sa.Column('id', sa.Integer(), nullable=False), sa.Column('id', sa.Integer(), nullable=False),
sa.Column('room_id', sa.Integer(), nullable=False), sa.Column('room_id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False), sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('original_path', sa.String(length=255), nullable=False), sa.Column('original_path', sa.String(length=255), nullable=False),
sa.Column('type', sa.String(length=10), nullable=False), sa.Column('type', sa.String(length=10), nullable=False),
sa.Column('size', sa.Integer(), nullable=True), sa.Column('size', sa.Integer(), nullable=True),
sa.Column('modified', sa.Float(), nullable=True), sa.Column('modified', sa.Float(), nullable=True),
sa.Column('uploaded_by', sa.Integer(), nullable=True), sa.Column('uploaded_by', sa.Integer(), nullable=True),
sa.Column('uploaded_at', sa.DateTime(), nullable=True), sa.Column('uploaded_at', sa.DateTime(), nullable=True),
sa.Column('deleted_by', sa.Integer(), nullable=False), sa.Column('deleted_by', sa.Integer(), nullable=False),
sa.Column('deleted_at', sa.DateTime(), nullable=False), sa.Column('deleted_at', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['deleted_by'], ['user.id'], ), sa.ForeignKeyConstraint(['deleted_by'], ['user.id'], ),
sa.ForeignKeyConstraint(['room_id'], ['room.id'], ), sa.ForeignKeyConstraint(['room_id'], ['room.id'], ),
sa.ForeignKeyConstraint(['uploaded_by'], ['user.id'], ), sa.ForeignKeyConstraint(['uploaded_by'], ['user.id'], ),
sa.PrimaryKeyConstraint('id') sa.PrimaryKeyConstraint('id')
) )
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():

View File

@@ -18,14 +18,20 @@ depends_on = None
def upgrade(): def upgrade():
# Add preferred_view as nullable first # Check if the column exists before adding it
with op.batch_alter_table('user', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('preferred_view', sa.String(length=10), nullable=True)) inspector = inspect(conn)
# Set default value for existing users columns = [col['name'] for col in inspector.get_columns('user')]
op.execute("UPDATE \"user\" SET preferred_view = 'grid'")
# Make the column non-nullable if 'preferred_view' not in columns:
with op.batch_alter_table('user', schema=None) as batch_op: # Add preferred_view as nullable first
batch_op.alter_column('preferred_view', nullable=False) with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.add_column(sa.Column('preferred_view', sa.String(length=10), nullable=True))
# Set default value for existing users
op.execute("UPDATE \"user\" SET preferred_view = 'grid'")
# Make the column non-nullable
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.alter_column('preferred_view', nullable=False)
def downgrade(): def downgrade():

View File

@@ -19,10 +19,17 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
inspector = inspect(conn)
columns = [col['name'] for col in inspector.get_columns('room_member_permissions')]
with op.batch_alter_table('room_member_permissions', schema=None) as batch_op: with op.batch_alter_table('room_member_permissions', schema=None) as batch_op:
batch_op.add_column(sa.Column('can_download', sa.Boolean(), nullable=False, server_default=sa.false())) if 'can_download' not in columns:
batch_op.add_column(sa.Column('can_rename', sa.Boolean(), nullable=False, server_default=sa.false())) batch_op.add_column(sa.Column('can_download', sa.Boolean(), nullable=False, server_default=sa.false()))
batch_op.add_column(sa.Column('can_move', sa.Boolean(), nullable=False, server_default=sa.false())) if 'can_rename' not in columns:
batch_op.add_column(sa.Column('can_rename', sa.Boolean(), nullable=False, server_default=sa.false()))
if 'can_move' not in columns:
batch_op.add_column(sa.Column('can_move', sa.Boolean(), nullable=False, server_default=sa.false()))
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@@ -19,11 +19,14 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.drop_table('contact')
conn = op.get_bind() conn = op.get_bind()
inspector = inspect(conn) inspector = inspect(conn)
tables = inspector.get_table_names()
columns = [col['name'] for col in inspector.get_columns('user')] columns = [col['name'] for col in inspector.get_columns('user')]
if 'contact' in tables:
op.drop_table('contact')
with op.batch_alter_table('user', schema=None) as batch_op: with op.batch_alter_table('user', schema=None) as batch_op:
if 'profile_picture' not in columns: if 'profile_picture' not in columns:
batch_op.add_column(sa.Column('profile_picture', sa.String(length=255), nullable=True)) batch_op.add_column(sa.Column('profile_picture', sa.String(length=255), nullable=True))
@@ -33,8 +36,13 @@ def upgrade():
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
inspector = inspect(conn)
columns = [col['name'] for col in inspector.get_columns('user')]
with op.batch_alter_table('user', schema=None) as batch_op: with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.drop_column('profile_picture') if 'profile_picture' in columns:
batch_op.drop_column('profile_picture')
op.create_table('contact', op.create_table('contact',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),

View File

@@ -32,7 +32,12 @@ def upgrade():
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
inspector = inspect(conn)
columns = [col['name'] for col in inspector.get_columns('user')]
with op.batch_alter_table('user', schema=None) as batch_op: with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.drop_column('last_name') if 'last_name' in columns:
batch_op.drop_column('last_name')
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@@ -19,23 +19,23 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind() conn = op.get_bind()
inspector = inspect(conn) inspector = inspect(conn)
tables = inspector.get_table_names() tables = inspector.get_table_names()
if 'email_templates' not in tables: if 'email_templates' not in tables:
op.create_table('email_templates', op.create_table('email_templates',
sa.Column('id', sa.Integer(), nullable=False), sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=100), nullable=False), sa.Column('name', sa.String(length=100), nullable=False),
sa.Column('subject', sa.String(length=200), nullable=False), sa.Column('subject', sa.String(length=200), nullable=False),
sa.Column('body', sa.Text(), nullable=False), sa.Column('body', sa.Text(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True), sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('created_by', sa.Integer(), nullable=False), sa.Column('created_by', sa.Integer(), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=True), sa.Column('is_active', sa.Boolean(), nullable=True),
sa.ForeignKeyConstraint(['created_by'], ['user.id'], ), sa.ForeignKeyConstraint(['created_by'], ['user.id'], ),
sa.PrimaryKeyConstraint('id') sa.PrimaryKeyConstraint('id')
) )
op.drop_table('notification') op.drop_table('notification')
with op.batch_alter_table('events', schema=None) as batch_op: with op.batch_alter_table('events', schema=None) as batch_op:
batch_op.alter_column('details', batch_op.alter_column('details',
@@ -60,22 +60,22 @@ def downgrade():
type_=postgresql.JSONB(astext_type=sa.Text()), type_=postgresql.JSONB(astext_type=sa.Text()),
existing_nullable=True) existing_nullable=True)
conn = op.get_bind() conn = op.get_bind()
inspector = inspect(conn) inspector = inspect(conn)
tables = inspector.get_table_names() tables = inspector.get_table_names()
if 'notification' not in tables: if 'notification' not in tables:
op.create_table('notification', op.create_table('notification',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False), sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('user_id', sa.INTEGER(), autoincrement=False, nullable=False), sa.Column('user_id', sa.INTEGER(), autoincrement=False, nullable=False),
sa.Column('title', sa.VARCHAR(length=255), autoincrement=False, nullable=False), sa.Column('title', sa.VARCHAR(length=255), autoincrement=False, nullable=False),
sa.Column('message', sa.TEXT(), autoincrement=False, nullable=False), sa.Column('message', sa.TEXT(), autoincrement=False, nullable=False),
sa.Column('type', sa.VARCHAR(length=50), autoincrement=False, nullable=False), sa.Column('type', sa.VARCHAR(length=50), autoincrement=False, nullable=False),
sa.Column('is_read', sa.BOOLEAN(), autoincrement=False, nullable=True), sa.Column('is_read', sa.BOOLEAN(), autoincrement=False, nullable=True),
sa.Column('created_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True), sa.Column('created_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
sa.Column('link', sa.VARCHAR(length=512), autoincrement=False, nullable=True), sa.Column('link', sa.VARCHAR(length=512), autoincrement=False, nullable=True),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], name=op.f('notification_user_id_fkey')), sa.ForeignKeyConstraint(['user_id'], ['user.id'], name=op.f('notification_user_id_fkey')),
sa.PrimaryKeyConstraint('id', name=op.f('notification_pkey')) sa.PrimaryKeyConstraint('id', name=op.f('notification_pkey'))
) )
op.drop_table('email_templates') op.drop_table('email_templates')
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@@ -19,18 +19,18 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind() conn = op.get_bind()
inspector = inspect(conn) inspector = inspect(conn)
tables = inspector.get_table_names() tables = inspector.get_table_names()
if 'color_settings' not in tables: if 'color_settings' not in tables:
op.create_table('color_settings', op.create_table('color_settings',
sa.Column('id', sa.Integer(), nullable=False), sa.Column('id', sa.Integer(), nullable=False),
sa.Column('primary_color', sa.String(length=7), nullable=True), sa.Column('primary_color', sa.String(length=7), nullable=True),
sa.Column('secondary_color', sa.String(length=7), nullable=True), sa.Column('secondary_color', sa.String(length=7), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True), sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id') sa.PrimaryKeyConstraint('id')
) )
with op.batch_alter_table('room_file', schema=None) as batch_op: with op.batch_alter_table('room_file', schema=None) as batch_op:
batch_op.alter_column('deleted', batch_op.alter_column('deleted',
existing_type=sa.BOOLEAN(), existing_type=sa.BOOLEAN(),

View File

@@ -18,21 +18,21 @@ depends_on = None
def upgrade(): def upgrade():
# Create user_starred_file table # Create user_starred_file table
conn = op.get_bind() conn = op.get_bind()
inspector = inspect(conn) inspector = inspect(conn)
tables = inspector.get_table_names() tables = inspector.get_table_names()
if 'user_starred_file' not in tables: if 'user_starred_file' not in tables:
op.create_table('user_starred_file', op.create_table('user_starred_file',
sa.Column('id', sa.Integer(), nullable=False), sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('file_id', sa.Integer(), nullable=False), sa.Column('file_id', sa.Integer(), nullable=False),
sa.Column('starred_at', sa.DateTime(), nullable=True), sa.Column('starred_at', sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(['file_id'], ['room_file.id'], ), sa.ForeignKeyConstraint(['file_id'], ['room_file.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id'), sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('user_id', 'file_id', name='unique_user_file_star') sa.UniqueConstraint('user_id', 'file_id', name='unique_user_file_star')
) )
# Remove starred column from room_file # Remove starred column from room_file
with op.batch_alter_table('room_file', schema=None) as batch_op: with op.batch_alter_table('room_file', schema=None) as batch_op:

View File

@@ -19,21 +19,31 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('user', schema=None) as batch_op: conn = op.get_bind()
batch_op.alter_column('password_hash', inspector = inspect(conn)
existing_type=sa.VARCHAR(length=128), columns = [col['name'] for col in inspector.get_columns('user')]
type_=sa.String(length=256),
existing_nullable=True) if 'password_hash' in columns:
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.alter_column('password_hash',
existing_type=sa.VARCHAR(length=128),
type_=sa.String(length=256),
existing_nullable=True)
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('user', schema=None) as batch_op: conn = op.get_bind()
batch_op.alter_column('password_hash', inspector = inspect(conn)
existing_type=sa.String(length=256), columns = [col['name'] for col in inspector.get_columns('user')]
type_=sa.VARCHAR(length=128),
existing_nullable=True) if 'password_hash' in columns:
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.alter_column('password_hash',
existing_type=sa.String(length=256),
type_=sa.VARCHAR(length=128),
existing_nullable=True)
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@@ -19,27 +19,30 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.create_table('contact',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('first_name', sa.String(length=100), nullable=False),
sa.Column('last_name', sa.String(length=100), nullable=False),
sa.Column('email', sa.String(length=150), nullable=False),
sa.Column('phone', sa.String(length=20), nullable=True),
sa.Column('company', sa.String(length=100), nullable=True),
sa.Column('position', sa.String(length=100), nullable=True),
sa.Column('notes', sa.Text(), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('owner_id', sa.Integer(), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=True),
sa.ForeignKeyConstraint(['owner_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email')
)
# Check if columns exist before adding them
conn = op.get_bind() conn = op.get_bind()
inspector = inspect(conn) inspector = inspect(conn)
tables = inspector.get_table_names()
if 'contact' not in tables:
op.create_table('contact',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('first_name', sa.String(length=100), nullable=False),
sa.Column('last_name', sa.String(length=100), nullable=False),
sa.Column('email', sa.String(length=150), nullable=False),
sa.Column('phone', sa.String(length=20), nullable=True),
sa.Column('company', sa.String(length=100), nullable=True),
sa.Column('position', sa.String(length=100), nullable=True),
sa.Column('notes', sa.Text(), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('owner_id', sa.Integer(), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=True),
sa.ForeignKeyConstraint(['owner_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email')
)
# Check if columns exist before adding them
columns = [col['name'] for col in inspector.get_columns('user')] columns = [col['name'] for col in inspector.get_columns('user')]
with op.batch_alter_table('user', schema=None) as batch_op: with op.batch_alter_table('user', schema=None) as batch_op:
@@ -53,9 +56,15 @@ def upgrade():
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
inspector = inspect(conn)
columns = [col['name'] for col in inspector.get_columns('user')]
with op.batch_alter_table('user', schema=None) as batch_op: with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.drop_column('created_at') if 'created_at' in columns:
batch_op.drop_column('is_admin') batch_op.drop_column('created_at')
if 'is_admin' in columns:
batch_op.drop_column('is_admin')
op.drop_table('contact') op.drop_table('contact')
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@@ -19,22 +19,22 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind() conn = op.get_bind()
inspector = inspect(conn) inspector = inspect(conn)
tables = inspector.get_table_names() tables = inspector.get_table_names()
if 'message_attachment' not in tables: if 'message_attachment' not in tables:
op.create_table('message_attachment', op.create_table('message_attachment',
sa.Column('id', sa.Integer(), nullable=False), sa.Column('id', sa.Integer(), nullable=False),
sa.Column('message_id', sa.Integer(), nullable=False), sa.Column('message_id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False), sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('path', sa.String(length=512), nullable=False), sa.Column('path', sa.String(length=512), nullable=False),
sa.Column('type', sa.String(length=100), nullable=True), sa.Column('type', sa.String(length=100), nullable=True),
sa.Column('size', sa.Integer(), nullable=True), sa.Column('size', sa.Integer(), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=True), sa.Column('created_at', sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(['message_id'], ['message.id'], ), sa.ForeignKeyConstraint(['message_id'], ['message.id'], ),
sa.PrimaryKeyConstraint('id') sa.PrimaryKeyConstraint('id')
) )
with op.batch_alter_table('message', schema=None) as batch_op: with op.batch_alter_table('message', schema=None) as batch_op:
batch_op.drop_column('attachment_path') batch_op.drop_column('attachment_path')
batch_op.drop_column('attachment_type') batch_op.drop_column('attachment_type')

View File

@@ -19,8 +19,13 @@ depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('site_settings', schema=None) as batch_op: conn = op.get_bind()
batch_op.add_column(sa.Column('company_logo', sa.String(length=255), nullable=True)) inspector = inspect(conn)
columns = [col['name'] for col in inspector.get_columns('site_settings')]
if 'company_logo' not in columns:
with op.batch_alter_table('site_settings', schema=None) as batch_op:
batch_op.add_column(sa.Column('company_logo', sa.String(length=255), nullable=True))
# ### end Alembic commands ### # ### end Alembic commands ###