-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: supports task collaborators (#189)
- Loading branch information
Showing
43 changed files
with
906 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
labelu/alembic_labelu/versions/2eb983c9a254_add_collaborators_and_updaters.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
"""add_collaborators_and_updaters | ||
Revision ID: 2eb983c9a254 | ||
Revises: eb9c5b98168b | ||
Create Date: 2025-02-19 16:16:39.259779 | ||
""" | ||
from datetime import datetime | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.sql import table, column | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '2eb983c9a254' | ||
down_revision = 'eb9c5b98168b' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# Create task_collaborator table | ||
op.create_table( | ||
'task_collaborator', | ||
sa.Column('task_id', sa.Integer(), nullable=False), | ||
sa.Column('user_id', sa.Integer(), nullable=False), | ||
sa.Column( | ||
'created_at', | ||
sa.DateTime(timezone=True), | ||
server_default=sa.text('CURRENT_TIMESTAMP'), | ||
nullable=False | ||
), | ||
sa.ForeignKeyConstraint( | ||
['task_id'], | ||
['task.id'], | ||
ondelete='CASCADE' | ||
), | ||
sa.ForeignKeyConstraint( | ||
['user_id'], | ||
['user.id'], | ||
ondelete='CASCADE' | ||
), | ||
sa.PrimaryKeyConstraint('task_id', 'user_id') | ||
) | ||
|
||
# Performances index | ||
op.create_index( | ||
'ix_task_collaborator_task_id', | ||
'task_collaborator', | ||
['task_id'] | ||
) | ||
op.create_index( | ||
'ix_task_collaborator_user_id', | ||
'task_collaborator', | ||
['user_id'] | ||
) | ||
op.create_index( | ||
'ix_task_created_by_deleted_at', | ||
'task', | ||
['created_by', 'deleted_at'] | ||
) | ||
|
||
# Task sample: updater -> updaters; create a new table task_sample_updater | ||
op.create_table( | ||
'task_sample_updater', | ||
sa.Column('sample_id', sa.Integer(), nullable=False), | ||
sa.Column('user_id', sa.Integer(), nullable=False), | ||
sa.Column( | ||
'created_at', | ||
sa.DateTime(timezone=True), | ||
server_default=sa.text('CURRENT_TIMESTAMP'), | ||
nullable=False | ||
), | ||
sa.ForeignKeyConstraint( | ||
['sample_id'], | ||
['task_sample.id'], | ||
ondelete='CASCADE' | ||
), | ||
sa.ForeignKeyConstraint( | ||
['user_id'], | ||
['user.id'], | ||
ondelete='CASCADE' | ||
), | ||
sa.PrimaryKeyConstraint('sample_id', 'user_id') | ||
) | ||
|
||
# Performances index | ||
op.create_index( | ||
'ix_task_sample_updater_sample_id', | ||
'task_sample_updater', | ||
['sample_id'] | ||
) | ||
op.create_index( | ||
'ix_task_sample_updater_user_id', | ||
'task_sample_updater', | ||
['user_id'] | ||
) | ||
|
||
# Migrate data from task_sample.updated_by to task_sample_updater | ||
task_sample = table( | ||
'task_sample', | ||
column('id', sa.Integer), | ||
column('updated_by', sa.Integer), | ||
column('updated_at', sa.DateTime) | ||
) | ||
|
||
task_sample_updater = table( | ||
'task_sample_updater', | ||
column('sample_id', sa.Integer), | ||
column('user_id', sa.Integer), | ||
column('created_at', sa.DateTime) | ||
) | ||
|
||
conn = op.get_bind() | ||
for row in conn.execute(sa.select([task_sample.c.id, task_sample.c.updated_by, task_sample.c.updated_at])): | ||
if row.updated_by: | ||
conn.execute( | ||
task_sample_updater.insert().values( | ||
sample_id=row.id, | ||
user_id=row.updated_by, | ||
created_at=row.updated_at or datetime.now() | ||
) | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_index('ix_task_collaborator_user_id') | ||
op.drop_index('ix_task_collaborator_task_id') | ||
|
||
op.drop_table('task_collaborator') | ||
|
||
op.drop_index('ix_task_sample_updater_user_id') | ||
op.drop_index('ix_task_sample_updater_task_sample_id') | ||
|
||
op.drop_table('task_sample_updater') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.