-
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.
feat: Add default CI to Fuel Category
* Default CI is actually associated to fuel category and used as a fallback in several scenarios * The one covered here is Other, where if the user selects other it needs to use the CI of the Cateory, NOT the Type.
- Loading branch information
Showing
7 changed files
with
187 additions
and
20 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
backend/lcfs/db/migrations/versions/2024-12-17-23-58_851e09cf8661.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,62 @@ | ||
"""Add Default CI to Categories | ||
Revision ID: 851e09cf8661 | ||
Revises: 5b374dd97469 | ||
Create Date: 2024-12-17 23:58:07.462215 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "851e09cf8661" | ||
down_revision = "5b374dd97469" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column( | ||
"fuel_category", | ||
sa.Column( | ||
"default_carbon_intensity", | ||
sa.Numeric(precision=10, scale=2), | ||
nullable=True, | ||
comment="Default carbon intensity of the fuel category", | ||
), | ||
) | ||
|
||
# Populate default values for existing records | ||
op.execute( | ||
""" | ||
UPDATE "fuel_category" SET "default_carbon_intensity" = 88.83 WHERE "description" = 'Jet fuel'; | ||
""" | ||
) | ||
op.execute( | ||
""" | ||
UPDATE "fuel_category" SET "default_carbon_intensity" = 100.21 WHERE "description" = 'Diesel'; | ||
""" | ||
) | ||
op.execute( | ||
""" | ||
UPDATE "fuel_category" SET "default_carbon_intensity" = 93.67 WHERE "description" = 'Gasoline'; | ||
""" | ||
) | ||
|
||
# Now set the column to NOT NULL after populating defaults | ||
op.alter_column( | ||
"fuel_category", | ||
"default_carbon_intensity", | ||
existing_type=sa.Numeric(precision=10, scale=2), | ||
nullable=False, | ||
) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column("fuel_category", "default_carbon_intensity") | ||
# ### 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
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
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