Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

147 rename the link class to file #148

Merged
merged 11 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,21 @@ Let's say that you want to query all the Shot Lighting tasks where a specific
asset is referenced:

```python
from stalker import Asset, Shot, Version
from stalker import Asset, File, Shot, Version

my_asset = Asset.query.filter_by(name="My Asset").first()
refs = Version.query.filter_by(name="Lighting").filter(Version.inputs.contains(my_asset)).all()
# Let's assume we have multiple Versions created for this Asset already
my_asset_version = my_asset.versions[0]
# get a file from that version
my_asset_version_file = my_asset_version.files[0]
# now get any other Lighting Versions that is referencing this file
refs = (
Version.query
.join(File, Version.files)
.filter(Version.name=="Lighting")
.filter(File.references.contains(my_asset_version_file))
.all()
)
```

Let's say you want to get all the tasks assigned to you in a specific Project:
Expand Down
15 changes: 7 additions & 8 deletions alembic/versions/2252e51506de_multiple_repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@ def downgrade():
# before dropping Project_Repositories, carry all the data back,
# note that only the first repository found per project will be
# restored to the Project.repository_id column
op.execute(
'update "Projects" '
" set repository_id = ("
" select "
" repo_id"
' from "Project_Repositories" '
' where project_id = "Projects".id limit 1'
" )"
op.execute("""
UPDATE "Projects" SET repository_id = (
SELECT
repo_id
FROM "Project_Repositories"
WHERE project_id = "Projects".id LIMIT 1
)"""
)

op.drop_table("Project_Repositories")
57 changes: 26 additions & 31 deletions alembic/versions/2e4a3813ae76_created_daily_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,39 +98,39 @@ def create_status(name, code):
# Insert in to SimpleEntities
op.execute(
f"""INSERT INTO "SimpleEntities" (entity_type, name, description,
created_by_id, updated_by_id, date_created, date_updated, type_id,
thumbnail_id, html_style, html_class, stalker_version)
VALUES ('StatusList', 'Daily Statuses', '', NULL, NULL,
(SELECT CAST(NOW() at time zone 'utc' AS timestamp)),
(SELECT CAST(NOW() at time zone 'utc' AS timestamp)), NULL, NULL,
'', '', '{stalker.__version__}')"""
created_by_id, updated_by_id, date_created, date_updated, type_id,
thumbnail_id, html_style, html_class, stalker_version)
VALUES ('StatusList', 'Daily Statuses', '', NULL, NULL,
(SELECT CAST(NOW() at time zone 'utc' AS timestamp)),
(SELECT CAST(NOW() at time zone 'utc' AS timestamp)), NULL, NULL,
'', '', '{stalker.__version__}')"""
)

# insert in to Entities and StatusLists
op.execute(
"""INSERT INTO "Entities" (id)
VALUES ((
SELECT id
FROM "SimpleEntities"
WHERE "SimpleEntities".name = 'Daily Statuses'
));
INSERT INTO "StatusLists" (id, target_entity_type)
VALUES ((
SELECT id
FROM "SimpleEntities"
WHERE "SimpleEntities".name = 'Daily Statuses'), 'Daily');"""
VALUES ((
SELECT id
FROM "SimpleEntities"
WHERE "SimpleEntities".name = 'Daily Statuses'
));
INSERT INTO "StatusLists" (id, target_entity_type)
VALUES ((
SELECT id
FROM "SimpleEntities"
WHERE "SimpleEntities".name = 'Daily Statuses'), 'Daily');"""
)

# Add Review Statues To StatusList_Statuses
# Add new Task statuses to StatusList
op.execute(
"""INSERT INTO "StatusList_Statuses" (status_list_id, status_id)
VALUES
((SELECT id FROM "StatusLists" WHERE target_entity_type = 'Daily'),
(SELECT id FROM "Statuses" WHERE code = 'OPEN')),
((SELECT id FROM "StatusLists" WHERE target_entity_type = 'Daily'),
(SELECT id FROM "Statuses" WHERE code = 'CLS'))
"""
VALUES
((SELECT id FROM "StatusLists" WHERE target_entity_type = 'Daily'),
(SELECT id FROM "Statuses" WHERE code = 'OPEN')),
((SELECT id FROM "StatusLists" WHERE target_entity_type = 'Daily'),
(SELECT id FROM "Statuses" WHERE code = 'CLS'))
"""
)


Expand All @@ -142,17 +142,12 @@ def downgrade():
# Delete Open Status
op.execute(
"""DELETE FROM "StatusList_Statuses" WHERE
status_id IN (
select id FROM "SimpleEntities" WHERE
name = 'Open');
status_id IN (select id FROM "SimpleEntities" WHERE name = 'Open');
DELETE FROM "Statuses" WHERE
id IN (select id FROM "SimpleEntities" WHERE
name = 'Open');
id IN (select id FROM "SimpleEntities" WHERE name = 'Open');
DELETE FROM "Entities" WHERE
id IN (select id FROM "SimpleEntities" WHERE
name = 'Open');
DELETE FROM "SimpleEntities" WHERE
name = 'Open';
id IN (select id FROM "SimpleEntities" WHERE name = 'Open');
DELETE FROM "SimpleEntities" WHERE name = 'Open';
"""
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,97 +22,95 @@ def upgrade():
# First cleanup TimeLogs table
logger.info("Removing duplicate TimeLog entries")
op.execute(
"""
-- first remove direct duplicates
with cte as (
select
row_number() over (partition by resource_id, start) as rn,
id,
start,
"end",
resource_id
from "TimeLogs"
where exists (
select
1
from "TimeLogs" as tlogs
where tlogs.start <= "TimeLogs".start
and "TimeLogs".start < tlogs.end
and tlogs.id != "TimeLogs".id
and tlogs.resource_id = "TimeLogs".resource_id
)
order by start
) delete from "TimeLogs"
where "TimeLogs".id in (select id from cte where rn > 1);"""
"""-- first remove direct duplicates
with cte as (
select
row_number() over (partition by resource_id, start) as rn,
id,
start,
"end",
resource_id
from "TimeLogs"
where exists (
select
1
from "TimeLogs" as tlogs
where tlogs.start <= "TimeLogs".start
and "TimeLogs".start < tlogs.end
and tlogs.id != "TimeLogs".id
and tlogs.resource_id = "TimeLogs".resource_id
)
order by start
) delete from "TimeLogs"
where "TimeLogs".id in (select id from cte where rn > 1);"""
)

logger.info(
"Removing contained TimeLog entries (TimeLogs surrounded by other " "TimeLogs"
)
op.execute(
"""
-- remove any contained (TimeLogs surrounded by other TimeLogs) TimeLogs
with cte as (
select
"TimeLogs".id,
"TimeLogs".start,
"TimeLogs".end,
"TimeLogs".resource_id
from "TimeLogs"
join "TimeLogs" as tlogs on
"TimeLogs".start > tlogs.start and "TimeLogs".start < tlogs.end
and "TimeLogs".end > tlogs.start and "TimeLogs".end < tlogs.end
and "TimeLogs".resource_id = tlogs.resource_id
) delete from "TimeLogs"
where "TimeLogs".id in (select id from cte);"""
"""-- remove any contained (TimeLogs surrounded by other TimeLogs) TimeLogs
with cte as (
select
"TimeLogs".id,
"TimeLogs".start,
"TimeLogs".end,
"TimeLogs".resource_id
from "TimeLogs"
join "TimeLogs" as tlogs on
"TimeLogs".start > tlogs.start and "TimeLogs".start < tlogs.end
and "TimeLogs".end > tlogs.start and "TimeLogs".end < tlogs.end
and "TimeLogs".resource_id = tlogs.resource_id
) delete from "TimeLogs"
where "TimeLogs".id in (select id from cte);"""
)

logger.info("Trimming residual overlapping TimeLog.end values")
op.execute(
"""-- then trim the end dates of the TimeLogs that are still overlapping with others
update "TimeLogs"
set "end" = (
select
tlogs.start
from "TimeLogs" as tlogs
where "TimeLogs".start < tlogs.start and "TimeLogs".end > tlogs.start
and "TimeLogs".resource_id = tlogs.resource_id
limit 1
)
where "TimeLogs".end - "TimeLogs".start > interval '10 min'
and exists(
select
1
from "TimeLogs" as tlogs
where "TimeLogs".start < tlogs.start and "TimeLogs".end > tlogs.start
and "TimeLogs".resource_id = tlogs.resource_id
);
"""
-- then trim the end dates of the TimeLogs that are still overlapping with others
update "TimeLogs"
set "end" = (
select
tlogs.start
from "TimeLogs" as tlogs
where "TimeLogs".start < tlogs.start and "TimeLogs".end > tlogs.start
and "TimeLogs".resource_id = tlogs.resource_id
limit 1
)
where "TimeLogs".end - "TimeLogs".start > interval '10 min'
and exists(
select
1
from "TimeLogs" as tlogs
where "TimeLogs".start < tlogs.start and "TimeLogs".end > tlogs.start
and "TimeLogs".resource_id = tlogs.resource_id
);"""
)

logger.info("Trimming residual overlapping TimeLog.start values")
op.execute(
"""-- then trim the start dates of the TimeLogs that are still overlapping with
-- others (there may be 10 min TimeLogs left in the previous query)
update "TimeLogs"
set start = (
select
tlogs.end
from "TimeLogs" as tlogs
where "TimeLogs".start > tlogs.start and "TimeLogs".start < tlogs.end
and "TimeLogs".resource_id = tlogs.resource_id
limit 1
)
where "TimeLogs".end - "TimeLogs".start > interval '10 min'
and exists(
select
1
from "TimeLogs" as tlogs
where "TimeLogs".start > tlogs.start and "TimeLogs".start < tlogs.end
and "TimeLogs".resource_id = tlogs.resource_id
limit 1
);
"""
-- then trim the start dates of the TimeLogs that are still overlapping with
-- others (there may be 10 min TimeLogs left in the previous query)
update "TimeLogs"
set start = (
select
tlogs.end
from "TimeLogs" as tlogs
where "TimeLogs".start > tlogs.start and "TimeLogs".start < tlogs.end
and "TimeLogs".resource_id = tlogs.resource_id
limit 1
)
where "TimeLogs".end - "TimeLogs".start > interval '10 min'
and exists(
select
1
from "TimeLogs" as tlogs
where "TimeLogs".start > tlogs.start and "TimeLogs".start < tlogs.end
and "TimeLogs".resource_id = tlogs.resource_id
limit 1
);"""
)

logger.info("Adding CheckConstraint(end > start) to TimeLogs table")
Expand Down
27 changes: 3 additions & 24 deletions alembic/versions/433d9caaafab_task_review_status_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,7 @@ def upgrade():
sa.Column("dependency_target", task_dependency_target_enum, nullable=True),
)
# fill data
op.execute(
"""
UPDATE
"Task_Dependencies"
SET
dependency_target = 'onend'
"""
)
op.execute("""UPDATE "Task_Dependencies" SET dependency_target = 'onend'""")

# alter column to be nullable false
op.alter_column(
Expand All @@ -182,14 +175,7 @@ def upgrade():
"Task_Dependencies", sa.Column("gap_constraint", sa.Integer(), nullable=True)
)
# fill data
op.execute(
"""
UPDATE
"Task_Dependencies"
SET
gap_constraint = 0
"""
)
op.execute("""UPDATE "Task_Dependencies" SET gap_constraint = 0 """)

# alter column to be nullable false
op.alter_column(
Expand All @@ -204,14 +190,7 @@ def upgrade():
sa.Column("gap_model", task_dependency_gap_model, nullable=True),
)
# fill data
op.execute(
"""
UPDATE
"Task_Dependencies"
SET
gap_model = 'length'
"""
)
op.execute("""UPDATE "Task_Dependencies" SET gap_model = 'length'""")

# alter column to be nullable false
op.alter_column(
Expand Down
11 changes: 5 additions & 6 deletions alembic/versions/46775e4a3d96_create_enum_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def upgrade():

# create new types
op.execute(
"""
CREATE TYPE "ResourceAllocationStrategy" AS ENUM
"""CREATE TYPE "ResourceAllocationStrategy" AS ENUM
('minallocated', 'maxloaded', 'minloaded', 'order', 'random');
CREATE TYPE "TaskDependencyGapModel" AS ENUM ('length', 'duration');
CREATE TYPE "TaskDependencyTarget" AS ENUM ('onend', 'onstart');
Expand All @@ -34,7 +33,7 @@ def upgrade():
"""
ALTER TABLE "Tasks" ALTER COLUMN bid_unit TYPE "TimeUnit"
USING ((bid_unit::text)::"TimeUnit");
"""
"""
)

# remove unnecessary types
Expand All @@ -47,15 +46,15 @@ def downgrade():
op.execute(
"""CREATE TYPE "TaskBidUnit" AS ENUM
('min', 'h', 'd', 'w', 'm', 'y');
"""
"""
)

# update the Task column to use the TimeUnit type instead of TaskBidUnit
op.execute(
"""
ALTER TABLE "Tasks" ALTER COLUMN bid_unit TYPE "TaskBidUnit"
USING ((bid_unit::text)::"TaskBidUnit");
"""
"""
)

# rename types
Expand All @@ -68,5 +67,5 @@ def downgrade():
DROP TYPE IF EXISTS "TaskDependencyGapModel" CASCADE;
DROP TYPE IF EXISTS "TaskDependencyTarget" CASCADE;
DROP TYPE IF EXISTS "ReviewScheduleModel" CASCADE;
"""
"""
)
Loading
Loading