-
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 branch 'release-0.2.0' into feat/kevin-1588
- Loading branch information
Showing
57 changed files
with
854 additions
and
305 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
70 changes: 70 additions & 0 deletions
70
backend/lcfs/db/migrations/versions/2025-01-14-14-03_5163af6ba4a4.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,70 @@ | ||
"""revert org display balance | ||
Revision ID: 5163af6ba4a4 | ||
Revises: f78e53370ed2 | ||
Create Date: 2025-01-14 14:03:50.975682 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "5163af6ba4a4" | ||
down_revision = "f78e53370ed2" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# Reapply the original logic for balances: | ||
op.execute( | ||
""" | ||
CREATE OR REPLACE FUNCTION update_organization_balance() | ||
RETURNS TRIGGER AS $$ | ||
DECLARE | ||
new_total_balance BIGINT; | ||
new_reserved_balance BIGINT; | ||
org_id INT := COALESCE(NEW.organization_id, OLD.organization_id); | ||
BEGIN | ||
SELECT COALESCE(SUM(compliance_units), 0) | ||
INTO new_total_balance | ||
FROM "transaction" | ||
WHERE organization_id = org_id | ||
AND transaction_action = 'Adjustment'; | ||
SELECT COALESCE(SUM(compliance_units), 0) | ||
INTO new_reserved_balance | ||
FROM "transaction" | ||
WHERE organization_id = org_id | ||
AND transaction_action = 'Reserved' | ||
AND compliance_units < 0; | ||
UPDATE organization | ||
SET total_balance = new_total_balance, | ||
reserved_balance = new_reserved_balance | ||
WHERE organization_id = org_id; | ||
RETURN NEW; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
""" | ||
) | ||
|
||
op.execute( | ||
""" | ||
DROP TRIGGER IF EXISTS update_organization_balance_trigger ON "transaction"; | ||
""" | ||
) | ||
op.execute( | ||
""" | ||
CREATE TRIGGER update_organization_balance_trigger | ||
AFTER INSERT OR UPDATE OR DELETE ON "transaction" | ||
FOR EACH ROW EXECUTE FUNCTION update_organization_balance(); | ||
""" | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
pass |
61 changes: 61 additions & 0 deletions
61
backend/lcfs/db/migrations/versions/2025-01-14-18-12_fe03799b4018.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,61 @@ | ||
"""Update other_uses_fossil_derived in fuel_type | ||
Revision ID: fe03799b4018 | ||
Revises: fa98709e7952 | ||
Create Date: 2025-01-14 18:12:43.683691 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "fe03799b4018" | ||
down_revision = "5163af6ba4a4" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# Set other_uses_fossil_derived to false | ||
op.execute(""" | ||
UPDATE fuel_type | ||
SET other_uses_fossil_derived = false | ||
WHERE fuel_type IN ( | ||
'CNG', 'Electricity', 'Hydrogen', 'LNG', 'Propane', | ||
'Natural gas-based gasoline', 'Petroleum-based diesel', | ||
'Petroleum-based gasoline' | ||
) | ||
""") | ||
|
||
# Set other_uses_fossil_derived to true | ||
op.execute(""" | ||
UPDATE fuel_type | ||
SET other_uses_fossil_derived = true | ||
WHERE fuel_type IN ( | ||
'Alternative jet fuel', 'Biodiesel', 'Ethanol', 'HDRD', | ||
'Other diesel fuel', 'Renewable gasoline', 'Renewable naphtha' | ||
) | ||
""") | ||
|
||
def downgrade() -> None: | ||
# Revert `other_uses_fossil_derived` to original values for false | ||
op.execute(""" | ||
UPDATE fuel_type | ||
SET other_uses_fossil_derived = true | ||
WHERE fuel_type IN ( | ||
'CNG', 'Electricity', 'Hydrogen', 'LNG', 'Propane', | ||
'Natural gas-based gasoline', 'Petroleum-based diesel', | ||
'Petroleum-based gasoline' | ||
) | ||
""") | ||
|
||
# Revert `other_uses_fossil_derived` to original values for true | ||
op.execute(""" | ||
UPDATE fuel_type | ||
SET other_uses_fossil_derived = false | ||
WHERE fuel_type IN ( | ||
'Alternative jet fuel', 'Biodiesel', 'Ethanol', 'HDRD', | ||
'Other diesel fuel', 'Renewable gasoline', 'Renewable naphtha' | ||
) | ||
""") |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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.