-
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 remote-tracking branch 'origin/release-0.2.0' into fix/kevin-1545
- Loading branch information
Showing
47 changed files
with
1,023 additions
and
2,807 deletions.
There are no files selected for viewing
600 changes: 600 additions & 0 deletions
600
backend/lcfs/db/migrations/versions/2024-12-24-07-40_d9cdd9fca0ce.py
Large diffs are not rendered by default.
Oops, something went wrong.
84 changes: 84 additions & 0 deletions
84
backend/lcfs/db/migrations/versions/2024-12-30-13-54_9329e38396e1.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,84 @@ | ||
"""add update_count_transfers_in_progress db function and update existing counts | ||
Revision ID: 9329e38396e1 | ||
Revises: d9cdd9fca0ce | ||
Create Date: 2024-12-30 13:54:09.361644 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "9329e38396e1" | ||
down_revision = "d9cdd9fca0ce" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# Create or replace the trigger function without considering Draft transfers | ||
op.execute( | ||
""" | ||
CREATE OR REPLACE FUNCTION update_count_transfers_in_progress() | ||
RETURNS TRIGGER AS $$ | ||
BEGIN | ||
-- Update count_transfers_in_progress for from_organization_id and to_organization_id | ||
UPDATE organization o | ||
SET count_transfers_in_progress = ( | ||
SELECT COUNT(DISTINCT t.transfer_id) | ||
FROM transfer t | ||
WHERE | ||
t.current_status_id IN (3, 4) | ||
AND (t.from_organization_id = o.organization_id OR t.to_organization_id = o.organization_id) | ||
) | ||
WHERE o.organization_id = COALESCE(NEW.from_organization_id, OLD.from_organization_id) | ||
OR o.organization_id = COALESCE(NEW.to_organization_id, OLD.to_organization_id); | ||
RETURN NEW; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
""" | ||
) | ||
|
||
# Create the trigger | ||
op.execute( | ||
""" | ||
CREATE TRIGGER update_count_transfers_in_progress_trigger | ||
AFTER INSERT OR UPDATE OR DELETE ON transfer | ||
FOR EACH ROW | ||
EXECUTE FUNCTION update_count_transfers_in_progress(); | ||
""" | ||
) | ||
|
||
# Update existing counts for all organizations by aggregating both sent and received transfers without double-counting | ||
op.execute( | ||
""" | ||
UPDATE organization o | ||
SET count_transfers_in_progress = COALESCE(sub.total_transfer_count, 0) | ||
FROM ( | ||
SELECT | ||
org.organization_id, | ||
COUNT(DISTINCT t.transfer_id) AS total_transfer_count | ||
FROM | ||
organization org | ||
LEFT JOIN transfer t ON org.organization_id = t.from_organization_id | ||
OR org.organization_id = t.to_organization_id | ||
WHERE | ||
t.current_status_id IN (3, 4) | ||
GROUP BY | ||
org.organization_id | ||
) sub | ||
WHERE | ||
o.organization_id = sub.organization_id; | ||
""" | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
# Drop the trigger | ||
op.execute( | ||
"DROP TRIGGER IF EXISTS update_count_transfers_in_progress_trigger ON transfer;" | ||
) | ||
# Drop the trigger function | ||
op.execute("DROP FUNCTION IF EXISTS update_count_transfers_in_progress();") |
67 changes: 67 additions & 0 deletions
67
backend/lcfs/db/migrations/versions/2025-01-03-23-31_e883ad1f0f60.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,67 @@ | ||
"""Rename Reassessed | ||
Revision ID: e883ad1f0f60 | ||
Revises: 9329e38396e1 | ||
Create Date: 2025-01-03 23:31:19.098618 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
from alembic_postgresql_enum import TableReference | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "e883ad1f0f60" | ||
down_revision = "9329e38396e1" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.sync_enum_values( | ||
"public", | ||
"compliancereportstatusenum", | ||
[ | ||
"Draft", | ||
"Submitted", | ||
"Recommended_by_analyst", | ||
"Recommended_by_manager", | ||
"Assessed", | ||
"Reassessed", | ||
], | ||
[ | ||
TableReference( | ||
table_schema="public", | ||
table_name="compliance_report_status", | ||
column_name="status", | ||
) | ||
], | ||
enum_values_to_rename=[("ReAssessed", "Reassessed")], | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.sync_enum_values( | ||
"public", | ||
"compliancereportstatusenum", | ||
[ | ||
"Draft", | ||
"Submitted", | ||
"Recommended_by_analyst", | ||
"Recommended_by_manager", | ||
"Assessed", | ||
"ReAssessed", | ||
], | ||
[ | ||
TableReference( | ||
table_schema="public", | ||
table_name="compliance_report_status", | ||
column_name="status", | ||
) | ||
], | ||
enum_values_to_rename=[("Reassessed", "ReAssessed")], | ||
) | ||
# ### end Alembic commands ### |
37 changes: 37 additions & 0 deletions
37
backend/lcfs/db/migrations/versions/2025-01-04-13-24_bfa7bbb1eea3.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,37 @@ | ||
"""Update fuel type name | ||
Revision ID: bfa7bbb1eea3 | ||
Revises: 9329e38396e1 | ||
Create Date: 2025-01-03 13:24:19.525006 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "bfa7bbb1eea3" | ||
down_revision = "e883ad1f0f60" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# Update fuel type name | ||
op.execute(""" | ||
UPDATE fuel_type | ||
SET fuel_type = 'Other diesel fuel', | ||
provision_1_id = 3 -- Change from prescribed (1) to default (3) | ||
WHERE fuel_type = 'Other diesel'; | ||
""") | ||
|
||
|
||
def downgrade() -> None: | ||
# Revert fuel type name update | ||
op.execute(""" | ||
UPDATE fuel_type | ||
SET fuel_type = 'Other diesel', | ||
provision_1_id = 1 -- Change from default (3) to prescribed (1) | ||
WHERE fuel_type = 'Other diesel fuel'; | ||
""") | ||
|
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
Empty file.
58 changes: 0 additions & 58 deletions
58
backend/lcfs/db/seeders/common/admin_adjustment_status_seeder.py
This file was deleted.
Oops, something went wrong.
56 changes: 0 additions & 56 deletions
56
backend/lcfs/db/seeders/common/allocation_agreement_seeder.py
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.