This commit is contained in:
2025-05-25 10:31:22 +02:00
parent 1caeb8fc98
commit 225e33056a
102 changed files with 8390 additions and 0 deletions

1
migrations/README Normal file
View File

@@ -0,0 +1 @@
Single-database configuration for Flask.

Binary file not shown.

46
migrations/alembic.ini Normal file
View File

@@ -0,0 +1,46 @@
[alembic]
script_location = migrations
# A generic, single database configuration.
# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic,flask_migrate
[handlers]
keys = console
[formatters]
keys = generic
[logger_root]
level = WARN
handlers = console
qualname =
[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine
[logger_alembic]
level = INFO
handlers =
qualname = alembic
[logger_flask_migrate]
level = INFO
handlers =
qualname = flask_migrate
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S

113
migrations/env.py Normal file
View File

@@ -0,0 +1,113 @@
import logging
from logging.config import fileConfig
from flask import current_app
from alembic import context
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)
logger = logging.getLogger('alembic.env')
def get_engine():
try:
# this works with Flask-SQLAlchemy<3 and Alchemical
return current_app.extensions['migrate'].db.get_engine()
except (TypeError, AttributeError):
# this works with Flask-SQLAlchemy>=3
return current_app.extensions['migrate'].db.engine
def get_engine_url():
try:
return get_engine().url.render_as_string(hide_password=False).replace(
'%', '%%')
except AttributeError:
return str(get_engine().url).replace('%', '%%')
# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
config.set_main_option('sqlalchemy.url', get_engine_url())
target_db = current_app.extensions['migrate'].db
# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.
def get_metadata():
if hasattr(target_db, 'metadatas'):
return target_db.metadatas[None]
return target_db.metadata
def run_migrations_offline():
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url, target_metadata=get_metadata(), literal_binds=True
)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
# this callback is used to prevent an auto-migration from being generated
# when there are no changes to the schema
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
def process_revision_directives(context, revision, directives):
if getattr(config.cmd_opts, 'autogenerate', False):
script = directives[0]
if script.upgrade_ops.is_empty():
directives[:] = []
logger.info('No changes in schema detected.')
conf_args = current_app.extensions['migrate'].configure_args
if conf_args.get("process_revision_directives") is None:
conf_args["process_revision_directives"] = process_revision_directives
connectable = get_engine()
with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=get_metadata(),
**conf_args
)
with context.begin_transaction():
context.run_migrations()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()

24
migrations/script.py.mako Normal file
View File

@@ -0,0 +1,24 @@
"""${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)}
down_revision = ${repr(down_revision)}
branch_labels = ${repr(branch_labels)}
depends_on = ${repr(depends_on)}
def upgrade():
${upgrades if upgrades else "pass"}
def downgrade():
${downgrades if downgrades else "pass"}

View File

@@ -0,0 +1,36 @@
"""Add user authentication fields
Revision ID: 1c297825e3a9
Revises:
Create Date: 2025-05-23 08:39:40.494853
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '1c297825e3a9'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('user',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('username', 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.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email'),
sa.UniqueConstraint('username')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('user')
# ### end Alembic commands ###

View File

@@ -0,0 +1,32 @@
"""Add is_admin to Contact model
Revision ID: 25da158dd705
Revises: 7a5747dc773f
Create Date: 2025-05-23 16:10:53.731035
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '25da158dd705'
down_revision = '7a5747dc773f'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('contact', schema=None) as batch_op:
batch_op.add_column(sa.Column('is_admin', sa.Boolean(), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('contact', schema=None) as batch_op:
batch_op.drop_column('is_admin')
# ### end Alembic commands ###

View File

@@ -0,0 +1,38 @@
"""Add room member permissions table
Revision ID: 26b0e5357f52
Revises: 2c5f57dddb78
Create Date: 2025-05-23 21:44:58.832286
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '26b0e5357f52'
down_revision = '2c5f57dddb78'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('room_member_permissions',
sa.Column('room_id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('can_view', sa.Boolean(), nullable=False),
sa.Column('can_upload', sa.Boolean(), nullable=False),
sa.Column('can_delete', sa.Boolean(), nullable=False),
sa.Column('can_share', sa.Boolean(), nullable=False),
sa.ForeignKeyConstraint(['room_id'], ['room.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('room_id', 'user_id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('room_member_permissions')
# ### end Alembic commands ###

View File

@@ -0,0 +1,40 @@
"""Add room members table
Revision ID: 2c5f57dddb78
Revises: 3a5b8d8e53cd
Create Date: 2025-05-23 21:27:17.497481
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '2c5f57dddb78'
down_revision = '3a5b8d8e53cd'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('room_members',
sa.Column('room_id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['room_id'], ['room.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('room_id', 'user_id')
)
with op.batch_alter_table('room', schema=None) as batch_op:
batch_op.drop_column('is_private')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('room', schema=None) as batch_op:
batch_op.add_column(sa.Column('is_private', sa.BOOLEAN(), autoincrement=False, nullable=True))
op.drop_table('room_members')
# ### end Alembic commands ###

View File

@@ -0,0 +1,37 @@
"""Add rooms table
Revision ID: 3a5b8d8e53cd
Revises: c21f243b3640
Create Date: 2025-05-23 21:25:27.880150
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '3a5b8d8e53cd'
down_revision = 'c21f243b3640'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('room',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=100), nullable=False),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('created_by', sa.Integer(), nullable=False),
sa.Column('is_private', sa.Boolean(), nullable=True),
sa.ForeignKeyConstraint(['created_by'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('room')
# ### end Alembic commands ###

View File

@@ -0,0 +1,40 @@
"""Add contact fields to User model
Revision ID: 43dfd2543fad
Revises: dbcb5d2d3ed0
Create Date: 2025-05-23 09:24:23.926302
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '43dfd2543fad'
down_revision = 'dbcb5d2d3ed0'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.add_column(sa.Column('phone', sa.String(length=20), nullable=True))
batch_op.add_column(sa.Column('company', sa.String(length=100), nullable=True))
batch_op.add_column(sa.Column('position', sa.String(length=100), nullable=True))
batch_op.add_column(sa.Column('notes', sa.Text(), nullable=True))
batch_op.add_column(sa.Column('is_active', sa.Boolean(), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.drop_column('is_active')
batch_op.drop_column('notes')
batch_op.drop_column('position')
batch_op.drop_column('company')
batch_op.drop_column('phone')
# ### end Alembic commands ###

View File

@@ -0,0 +1,47 @@
"""add room_file table for file/folder metadata and uploader info
Revision ID: 64b5c28510b0
Revises: b978642e7b10
Create Date: 2025-05-24 10:07:02.159730
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '64b5c28510b0'
down_revision = 'b978642e7b10'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('room_file',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('room_id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('path', sa.String(length=1024), nullable=False),
sa.Column('type', sa.String(length=10), nullable=False),
sa.Column('size', sa.BigInteger(), nullable=True),
sa.Column('modified', sa.Float(), nullable=True),
sa.Column('uploaded_by', sa.Integer(), nullable=False),
sa.Column('uploaded_at', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['room_id'], ['room.id'], ),
sa.ForeignKeyConstraint(['uploaded_by'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('room_member_permissions', schema=None) as batch_op:
batch_op.drop_column('preferred_view')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('room_member_permissions', schema=None) as batch_op:
batch_op.add_column(sa.Column('preferred_view', sa.VARCHAR(length=10), autoincrement=False, nullable=False))
op.drop_table('room_file')
# ### end Alembic commands ###

View File

@@ -0,0 +1,60 @@
"""Add starred column to room_file table
Revision ID: 6651332488d9
Revises: be1f7bdd10e1
Create Date: 2025-05-24 18:14:38.320999
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = '6651332488d9'
down_revision = 'be1f7bdd10e1'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('room_file', schema=None) as batch_op:
batch_op.add_column(sa.Column('starred', sa.Boolean(), nullable=True))
batch_op.alter_column('path',
existing_type=sa.VARCHAR(length=1024),
type_=sa.String(length=255),
existing_nullable=False)
batch_op.alter_column('size',
existing_type=sa.BIGINT(),
type_=sa.Integer(),
existing_nullable=True)
batch_op.alter_column('uploaded_by',
existing_type=sa.INTEGER(),
nullable=True)
batch_op.alter_column('uploaded_at',
existing_type=postgresql.TIMESTAMP(),
nullable=True)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('room_file', schema=None) as batch_op:
batch_op.alter_column('uploaded_at',
existing_type=postgresql.TIMESTAMP(),
nullable=False)
batch_op.alter_column('uploaded_by',
existing_type=sa.INTEGER(),
nullable=False)
batch_op.alter_column('size',
existing_type=sa.Integer(),
type_=sa.BIGINT(),
existing_nullable=True)
batch_op.alter_column('path',
existing_type=sa.String(length=255),
type_=sa.VARCHAR(length=1024),
existing_nullable=False)
batch_op.drop_column('starred')
# ### end Alembic commands ###

View File

@@ -0,0 +1,34 @@
"""fix existing users
Revision ID: 7554ab70efe7
Revises: 43dfd2543fad
Create Date: 2024-03-19 10:05:00.000000
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.sql import text
# revision identifiers, used by Alembic.
revision = '7554ab70efe7'
down_revision = '43dfd2543fad'
branch_labels = None
depends_on = None
def upgrade():
# Update existing users to set default values
connection = op.get_bind()
connection.execute(
text("""
UPDATE "user"
SET position = 'Administrator',
is_active = true
WHERE position IS NULL
""")
)
def downgrade():
pass

View File

@@ -0,0 +1,24 @@
"""merge heads
Revision ID: 76da0573e84b
Revises: add_deleted_by_to_room_file, create_user_starred_file_table
Create Date: 2025-05-25 10:03:03.423064
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '76da0573e84b'
down_revision = ('add_deleted_by_to_room_file', 'create_user_starred_file_table')
branch_labels = None
depends_on = None
def upgrade():
pass
def downgrade():
pass

View File

@@ -0,0 +1,42 @@
"""Update last_name field in User model
Revision ID: 7a5747dc773f
Revises: c243d6a1843d
Create Date: 2024-03-19 10:15:00.000000
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.sql import text
# revision identifiers, used by Alembic.
revision = '7a5747dc773f'
down_revision = 'c243d6a1843d'
branch_labels = None
depends_on = None
def upgrade():
# First, update any null last_name values to '(You)'
connection = op.get_bind()
connection.execute(
text("""
UPDATE "user"
SET last_name = '(You)'
WHERE last_name IS NULL
""")
)
# Then make the column non-nullable
op.alter_column('user', 'last_name',
existing_type=sa.String(length=150),
nullable=False,
server_default='(You)')
def downgrade():
op.alter_column('user', 'last_name',
existing_type=sa.String(length=150),
nullable=True,
server_default=None)

View File

@@ -0,0 +1,33 @@
"""Add deleted_by column to room_file table
Revision ID: add_deleted_by_to_room_file
Revises: add_deleted_column_to_room_file
Create Date: 2024-03-19 10:45:00.000000
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'add_deleted_by_to_room_file'
down_revision = 'add_deleted_column_to_room_file'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('room_file', schema=None) as batch_op:
batch_op.add_column(sa.Column('deleted_by', sa.Integer(), nullable=True))
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'])
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('room_file', schema=None) as batch_op:
batch_op.drop_constraint('fk_room_file_deleted_by_user', type_='foreignkey')
batch_op.drop_column('deleted_at')
batch_op.drop_column('deleted_by')
# ### end Alembic commands ###

View File

@@ -0,0 +1,29 @@
"""Add deleted column to room_file table
Revision ID: add_deleted_column_to_room_file
Revises: add_trashed_file_table
Create Date: 2024-03-19 10:30:00.000000
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'add_deleted_column_to_room_file'
down_revision = 'add_trashed_file_table'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
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 ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('room_file', schema=None) as batch_op:
batch_op.drop_column('deleted')
# ### end Alembic commands ###

View File

@@ -0,0 +1,42 @@
"""Add trashed file table
Revision ID: add_trashed_file_table
Revises: 6651332488d9
Create Date: 2024-03-19 10:00:00.000000
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = 'add_trashed_file_table'
down_revision = '6651332488d9'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('trashed_file',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('room_id', sa.Integer(), nullable=False),
sa.Column('name', 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('size', sa.Integer(), nullable=True),
sa.Column('modified', sa.Float(), nullable=True),
sa.Column('uploaded_by', sa.Integer(), nullable=True),
sa.Column('uploaded_at', sa.DateTime(), nullable=True),
sa.Column('deleted_by', sa.Integer(), nullable=False),
sa.Column('deleted_at', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['deleted_by'], ['user.id'], ),
sa.ForeignKeyConstraint(['room_id'], ['room.id'], ),
sa.ForeignKeyConstraint(['uploaded_by'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('trashed_file')
# ### end Alembic commands ###

View File

@@ -0,0 +1,38 @@
"""add preferred_view to user
Revision ID: b978642e7b10
Revises: 26b0e5357f52
Create Date: 2025-05-24 08:36:03.426879
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'b978642e7b10'
down_revision = '26b0e5357f52'
branch_labels = None
depends_on = None
def upgrade():
# Add preferred_view as nullable first
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():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.drop_column('preferred_view')
with op.batch_alter_table('room_member_permissions', schema=None) as batch_op:
batch_op.add_column(sa.Column('preferred_view', sa.VARCHAR(length=10), autoincrement=False, nullable=False))
# ### end Alembic commands ###

View File

@@ -0,0 +1,36 @@
"""Add granular permissions to RoomMemberPermission
Revision ID: be1f7bdd10e1
Revises: 64b5c28510b0
Create Date: 2025-05-24 12:32:19.239241
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'be1f7bdd10e1'
down_revision = '64b5c28510b0'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
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()))
batch_op.add_column(sa.Column('can_rename', sa.Boolean(), nullable=False, server_default=sa.false()))
batch_op.add_column(sa.Column('can_move', sa.Boolean(), nullable=False, server_default=sa.false()))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('room_member_permissions', schema=None) as batch_op:
batch_op.drop_column('can_move')
batch_op.drop_column('can_rename')
batch_op.drop_column('can_download')
# ### end Alembic commands ###

View File

@@ -0,0 +1,51 @@
"""add profile_picture to user
Revision ID: c21f243b3640
Revises: 25da158dd705
Create Date: 2025-05-23 19:28:16.977187
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = 'c21f243b3640'
down_revision = '25da158dd705'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('contact')
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.add_column(sa.Column('profile_picture', sa.String(length=255), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.drop_column('profile_picture')
op.create_table('contact',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('first_name', sa.VARCHAR(length=100), autoincrement=False, nullable=False),
sa.Column('last_name', sa.VARCHAR(length=100), autoincrement=False, nullable=False),
sa.Column('email', sa.VARCHAR(length=150), autoincrement=False, nullable=False),
sa.Column('phone', sa.VARCHAR(length=20), autoincrement=False, nullable=True),
sa.Column('company', sa.VARCHAR(length=100), autoincrement=False, nullable=True),
sa.Column('position', sa.VARCHAR(length=100), autoincrement=False, nullable=True),
sa.Column('notes', sa.TEXT(), autoincrement=False, nullable=True),
sa.Column('created_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
sa.Column('updated_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
sa.Column('owner_id', sa.INTEGER(), autoincrement=False, nullable=False),
sa.Column('is_active', sa.BOOLEAN(), autoincrement=False, nullable=True),
sa.Column('is_admin', sa.BOOLEAN(), autoincrement=False, nullable=True),
sa.ForeignKeyConstraint(['owner_id'], ['user.id'], name=op.f('contact_owner_id_fkey')),
sa.PrimaryKeyConstraint('id', name=op.f('contact_pkey')),
sa.UniqueConstraint('email', name=op.f('contact_email_key'), postgresql_include=[], postgresql_nulls_not_distinct=False)
)
# ### end Alembic commands ###

View File

@@ -0,0 +1,32 @@
"""Add last_name to User model
Revision ID: c243d6a1843d
Revises: 7554ab70efe7
Create Date: 2025-05-23 16:00:09.905001
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'c243d6a1843d'
down_revision = '7554ab70efe7'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.add_column(sa.Column('last_name', sa.String(length=150), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.drop_column('last_name')
# ### end Alembic commands ###

View File

@@ -0,0 +1,41 @@
"""Create user_starred_file table and remove starred column
Revision ID: create_user_starred_file_table
Revises: 6651332488d9
Create Date: 2024-03-19 10:00:00.000000
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = 'create_user_starred_file_table'
down_revision = '6651332488d9'
branch_labels = None
depends_on = None
def upgrade():
# Create user_starred_file table
op.create_table('user_starred_file',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('file_id', sa.Integer(), nullable=False),
sa.Column('starred_at', sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(['file_id'], ['room_file.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('user_id', 'file_id', name='unique_user_file_star')
)
# Remove starred column from room_file
with op.batch_alter_table('room_file', schema=None) as batch_op:
batch_op.drop_column('starred')
def downgrade():
# Add starred column back to room_file
with op.batch_alter_table('room_file', schema=None) as batch_op:
batch_op.add_column(sa.Column('starred', sa.Boolean(), nullable=True))
# Drop user_starred_file table
op.drop_table('user_starred_file')

View File

@@ -0,0 +1,38 @@
"""Increase password_hash column length
Revision ID: d8dcbf9fe881
Revises: 1c297825e3a9
Create Date: 2025-05-23 08:45:00.693155
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'd8dcbf9fe881'
down_revision = '1c297825e3a9'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
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 ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
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 ###

View File

@@ -0,0 +1,52 @@
"""Add Contact model
Revision ID: dbcb5d2d3ed0
Revises: d8dcbf9fe881
Create Date: 2025-05-23 08:55:10.537722
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'dbcb5d2d3ed0'
down_revision = 'd8dcbf9fe881'
branch_labels = None
depends_on = None
def upgrade():
# ### 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')
)
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.add_column(sa.Column('is_admin', sa.Boolean(), nullable=True))
batch_op.add_column(sa.Column('created_at', sa.DateTime(), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.drop_column('created_at')
batch_op.drop_column('is_admin')
op.drop_table('contact')
# ### end Alembic commands ###