-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1867 from fractal-analytics-platform/1866-link-co…
…llectionstatev2-to-taskgroupv2-with-taskgroupv2_id-optional-foreign-key Add foreign key `CollectionStateV2.taskgroupv2_id`
- Loading branch information
Showing
8 changed files
with
144 additions
and
1 deletion.
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 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
44 changes: 44 additions & 0 deletions
44
fractal_server/migrations/versions/d82ee0dc1e48_collectionstatev2_taskgroupv2_id.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,44 @@ | ||
"""CollectionStateV2.taskgroupv2_id | ||
Revision ID: d82ee0dc1e48 | ||
Revises: 742b74e1cc6e | ||
Create Date: 2024-10-09 14:13:59.288582 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "d82ee0dc1e48" | ||
down_revision = "742b74e1cc6e" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("collectionstatev2", schema=None) as batch_op: | ||
batch_op.add_column( | ||
sa.Column("taskgroupv2_id", sa.Integer(), nullable=True) | ||
) | ||
batch_op.create_foreign_key( | ||
batch_op.f("fk_collectionstatev2_taskgroupv2_id_taskgroupv2"), | ||
"taskgroupv2", | ||
["taskgroupv2_id"], | ||
["id"], | ||
) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("collectionstatev2", schema=None) as batch_op: | ||
batch_op.drop_constraint( | ||
batch_op.f("fk_collectionstatev2_taskgroupv2_id_taskgroupv2"), | ||
type_="foreignkey", | ||
) | ||
batch_op.drop_column("taskgroupv2_id") | ||
|
||
# ### end Alembic commands ### |
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
from fractal_server.app.models import UserGroup | ||
from fractal_server.app.models import UserOAuth | ||
from fractal_server.app.models.v2 import CollectionStateV2 | ||
from fractal_server.app.models.v2 import TaskGroupV2 | ||
from fractal_server.app.models.v2 import TaskV2 | ||
from fractal_server.config import get_settings | ||
|
@@ -113,3 +114,38 @@ async def test_task_group_v2(db): | |
assert task_group is None | ||
assert task1 is None | ||
assert task3 is None | ||
|
||
|
||
async def test_collection_state(db): | ||
|
||
user = UserOAuth(email="[email protected]", hashed_password="1234") | ||
db.add(user) | ||
await db.commit() | ||
await db.refresh(user) | ||
|
||
task_group = TaskGroupV2( | ||
user_id=user.id, | ||
origin="wheel-file", | ||
pkg_name="package-name", | ||
) | ||
db.add(task_group) | ||
await db.commit() | ||
await db.refresh(task_group) | ||
|
||
state = CollectionStateV2(taskgroupv2_id=task_group.id) | ||
db.add(state) | ||
await db.commit() | ||
|
||
assert state.taskgroupv2_id == task_group.id | ||
|
||
await db.delete(task_group) | ||
|
||
settings = Inject(get_settings) | ||
if settings.DB_ENGINE == "sqlite": | ||
await db.commit() | ||
await db.refresh(state) | ||
assert state.taskgroupv2_id is not None | ||
else: | ||
with pytest.raises(IntegrityError): | ||
await db.commit() | ||
await db.rollback() |
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