Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
ca6a318
feat: historical snapshot migrations
Apr 9, 2025
375ee95
feat: historical fuel supply lookups
Apr 11, 2025
6d14a31
fix: etl updates for schedules
Apr 11, 2025
8e4387e
feat: etl schedules script work, backend and frontend null checks for…
Apr 15, 2025
a112be9
chore: merge etl changes
Apr 15, 2025
66b2eab
chore: merge develop
Apr 15, 2025
14d1a42
chore: merge develop
Apr 18, 2025
9069279
feat: organization snapshots, fuel supply fixes, summary work
Apr 19, 2025
643f007
feat: orphaned allocation agreements, test fixes
Apr 22, 2025
43a119c
chore: merge develop
Apr 22, 2025
2a83fc0
fix: test fixes
Apr 23, 2025
f19c60b
fix: migration order
Apr 23, 2025
c50f365
chore: temp cors fix
Apr 23, 2025
877d7ee
chore: merge develop
Apr 29, 2025
39e3d89
feat: legacy labels and exclusion reports
Apr 30, 2025
0b2c524
Merge pull request #2939 from bcgov/release-v1.1.0
AlexZorkin Jun 20, 2025
7a61b66
Merge pull request #2943 from bcgov/release-v1.1.0
AlexZorkin Jun 20, 2025
700bf8e
Merge pull request #2950 from bcgov/release-v1.1.0
AlexZorkin Jun 20, 2025
874e6b9
feat: added python based migrations for tfrs shutdown
Jul 2, 2025
478d100
fix: compliance summary validation
Jul 3, 2025
e0bfb4e
feat: legacy report support for 2013-2018 reports
Jul 11, 2025
b9a6755
fix: test updates
Jul 11, 2025
f5e75a8
Merge branch 'develop' into feat/alex-2013-2018-compliance-reports-2616
AlexZorkin Jul 11, 2025
269925f
feat: cors exceptions for dev pr builds
Jul 11, 2025
b7a39c9
chore: upgraded postgres version to v17 for pr builds to match other …
Jul 11, 2025
907fbd4
fix: postgres version to 17.0
Jul 11, 2025
5342d40
fix: more specific image tag
Jul 11, 2025
4ae73e4
Merge branch 'develop' into feat/alex-2013-2018-compliance-reports-2616
AlexZorkin Jul 11, 2025
87c991b
Merge branch 'develop' into feat/alex-2013-2018-compliance-reports-2616
AlexZorkin Jul 11, 2025
b091538
chore: merge develop
Jul 12, 2025
9b326c1
Merge branch 'develop' into feat/alex-2013-2018-compliance-reports-2616
prv-proton Jul 15, 2025
922ee4a
feat: enhanced data transfer scripts
Jul 15, 2025
f6951df
fix: exception handler import
Jul 15, 2025
7c033cd
feat: manual deployment to dev script
Jul 16, 2025
3a6ab9e
chore: merge develop
Jul 16, 2025
6067645
Merge branch 'develop' into feat/alex-2013-2018-compliance-reports-2616
AlexZorkin Jul 16, 2025
d29b428
Merge branch 'develop' into feat/alex-2013-2018-compliance-reports-2616
AlexZorkin Jul 16, 2025
e3cc0aa
chore: removed un needed cors url
Jul 16, 2025
b0c9451
chore: migration cleanup, merge develop
Jul 16, 2025
2e64274
chore: migration order fix
Jul 16, 2025
3c51f4c
fix: frontend test fixes
Jul 16, 2025
4b886d5
chore: backend tests cleanup
Jul 16, 2025
62d3eec
fix: enum test fix
Jul 16, 2025
4764463
fix: syntax fix
Jul 16, 2025
a0c193d
feat: fuel supply and migration cleanup
Jul 18, 2025
d68c15e
fix: fuel_supply migration updates
Jul 18, 2025
aa5e45d
fix: script updates
Jul 19, 2025
3947d68
fix: allocation fix
Jul 19, 2025
d50662d
feat: migrate fuel supply fix
Jul 19, 2025
0463b27
Merge branch 'develop' into feat/alex-2013-2018-compliance-reports-2616
AlexZorkin Jul 19, 2025
b9c4667
feat: other uses migration cleanup
kevin-hashimoto Jul 21, 2025
888dbb8
fix: allocation default
Jul 22, 2025
897748b
feat: merge legacy data branch
Jul 22, 2025
760e97b
fix: allocation test fix
Jul 22, 2025
89d4a0e
Merge branch 'develop' into feat/alex-tfrs-shutdown-migrations-250702
prv-proton Jul 22, 2025
3895ef5
Merge pull request #3023 from bcgov/feat/kevin-2990
kevin-hashimoto Jul 22, 2025
268f2bc
Feat: LCFS (TFRS Shutdown) - Complete Migration from TFRS Snapshot Fo…
Jul 24, 2025
4e74ce8
fix review comments
Jul 24, 2025
133ed40
.
Jul 24, 2025
ccf6d13
Merge pull request #3029 from bcgov/feat/prashanth-tfrs-migration-sum…
prv-proton Jul 25, 2025
2737fcf
chore: merge develop
Aug 7, 2025
666036c
feat: updated migrations for exclusion report chains, and summary lin…
Aug 7, 2025
73b3ea4
chore: migration order fixes
Aug 8, 2025
2e91cde
fix: migration data patch
Aug 8, 2025
aeef58c
chore: merge develop
Aug 8, 2025
2475158
Merge branch 'feat/alex-tfrs-shutdown-migrations-250702' into feat/al…
AlexZorkin Aug 8, 2025
7736f14
Merge pull request #3112 from bcgov/feat/alex-tfrs-shutdown-250807
AlexZorkin Aug 8, 2025
a3ce4c4
chore: merge develop
Aug 11, 2025
612f971
fix: migration order update
Aug 11, 2025
6bcefbd
fix: has_early_issuance ref
Aug 11, 2025
e22bff3
fix: migration order metabase fixes
Aug 12, 2025
a83c87c
fix: org schema defaults
Aug 12, 2025
752cd2c
fix: org values
Aug 12, 2025
6d245b7
fix: removed non existent fields from sql view
Aug 15, 2025
55223e3
Merge branch 'develop' into feat/alex-tfrs-shutdown-migrations-250702
AlexZorkin Aug 15, 2025
f0bc37c
fix: migration order
Aug 15, 2025
777433c
fix: migration sql update
Aug 15, 2025
ce5c45b
chore: merge develop
Aug 15, 2025
c0f7b22
chore: merge develop
Sep 3, 2025
fcddb43
fix: migration order
Sep 3, 2025
70cd239
chore: merge update with develop and test updates
Sep 3, 2025
ee34231
fix: test updates
Sep 4, 2025
8b1e251
chore: merge develop
AlexZorkin Nov 13, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/pr-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ jobs:
shell: bash {0}
run: |
cd lcfs/charts/lcfs-postgres-pr
helm -n ${{ env.DEV_NAMESPACE }} -f ./values-dev-pr.yaml upgrade --install lcfs-postgres-dev-${{ env.PR_NUMBER }} oci://registry-1.docker.io/bitnamicharts/postgresql --version 15.5.17
helm -n ${{ env.DEV_NAMESPACE }} -f ./values-dev-pr.yaml upgrade --install lcfs-postgres-dev-${{ env.PR_NUMBER }} oci://registry-1.docker.io/bitnamicharts/postgresql --version 16.7.16 --set image.tag=17.0.0
cd ../lcfs-redis-pr
helm -n ${{ env.DEV_NAMESPACE }} -f ./values-dev-pr.yaml upgrade --install lcfs-redis-dev-${{ env.PR_NUMBER }} oci://registry-1.docker.io/bitnamicharts/redis --version 19.6.1
cd ../lcfs-minio-pr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
MV_NAME = "mv_credit_ledger"

CREATE_VIEW_SQL = f"""
CREATE MATERIALIZED VIEW {MV_NAME} AS
CREATE MATERIALIZED VIEW IF NOT EXISTS {MV_NAME} AS
WITH base AS (
SELECT
t.transaction_id,
Expand Down Expand Up @@ -110,11 +110,12 @@
IDX_ORG_DATE = f"{MV_NAME}_org_date_idx"

CREATE_IDX_ORG_YEAR = (
f"CREATE INDEX {IDX_ORG_YEAR} "
f"CREATE INDEX IF NOT EXISTS {IDX_ORG_YEAR} "
f"ON {MV_NAME} (organization_id, compliance_period);"
)
CREATE_IDX_ORG_DATE = (
f"CREATE INDEX {IDX_ORG_DATE} " f"ON {MV_NAME} (organization_id, update_date DESC);"
f"CREATE INDEX IF NOT EXISTS {IDX_ORG_DATE} "
f"ON {MV_NAME} (organization_id, update_date DESC);"
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
depends_on = None

# Specify which sections to execute from the SQL file
# Note: Excluded views that reference organization_early_issuance_by_year table
# as that table doesn't exist yet - will be created in migration a1b2c3d4e5f7
SECTIONS_TO_EXECUTE = [
"Compliance Reports Analytics View",
"Compliance Reports Waiting review",
Expand All @@ -36,11 +38,12 @@
"Fuel Supply Fuel Code Base View",
"Fuel Supply Base View",
"Compliance Report Fuel Supply Base View",
"Compliance Report Chained View",
"Compliance Report Base View",
"Allocation Agreement Chained View",
"Allocation Agreement Base View",
"Fuel Code Base View"
"Compliance Report Chained View", # Safe - doesn't reference organization_early_issuance_by_year
"Allocation Agreement Chained View", # Safe - doesn't reference organization_early_issuance_by_year
"Fuel Code Base View",
# Excluded until organization_early_issuance_by_year table is created:
# "Compliance Report Base View", # References organization_early_issuance_by_year
# "Allocation Agreement Base View", # Depends on Compliance Report Base View
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""

from lcfs.db.dependencies import (
create_role_if_not_exists,
execute_sql_sections,
find_and_read_sql_file,
parse_sql_sections,
Expand All @@ -23,6 +24,9 @@ def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
"""Recreate the v_compliance_report view from metabase.sql"""
try:
# Create the role if it doesn't exist
create_role_if_not_exists()

# Read the metabase.sql file
content = find_and_read_sql_file(sqlFile="metabase.sql")
sections = parse_sql_sections(content)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import sqlalchemy as sa
from alembic import op
from lcfs.db.dependencies import (
create_role_if_not_exists,
execute_sql_sections,
find_and_read_sql_file,
parse_sql_sections,
Expand All @@ -24,6 +25,9 @@
def recreate_compliance_reports_view():
"""Recreate the v_compliance_report view from metabase.sql"""
try:
# Ensure role exists before creating views
create_role_if_not_exists()

# Read the metabase.sql file
content = find_and_read_sql_file(sqlFile="metabase.sql")
sections = parse_sql_sections(content)
Expand Down
158 changes: 84 additions & 74 deletions backend/lcfs/db/migrations/versions/2025-07-10-10-10_a1b2c3d4e5f7.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,82 +34,87 @@ def upgrade() -> None:
"""
)

# Create organization_early_issuance_by_year table
op.create_table(
"organization_early_issuance_by_year",
sa.Column(
"early_issuance_by_year_id",
sa.Integer(),
autoincrement=True,
nullable=False,
comment="Unique identifier for the early issuance by year record",
),
sa.Column(
"organization_id",
sa.Integer(),
nullable=False,
comment="Foreign key to the organization",
),
sa.Column(
"compliance_period_id",
sa.Integer(),
nullable=False,
comment="Foreign key to the compliance period",
),
sa.Column(
"has_early_issuance",
sa.Boolean(),
nullable=False,
server_default=sa.text("FALSE"),
comment="True if the organization can create early issuance reports for this compliance year",
),
sa.Column(
"create_date",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=True,
comment="Date and time (UTC) when the physical record was created in the database.",
),
sa.Column(
"update_date",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=True,
comment="Date and time (UTC) when the physical record was updated in the database.",
),
sa.Column(
"create_user",
sa.String(),
nullable=True,
comment="The user who created this record in the database.",
),
sa.Column(
"update_user",
sa.String(),
nullable=True,
comment="The user who last updated this record in the database.",
),
sa.PrimaryKeyConstraint("early_issuance_by_year_id"),
sa.ForeignKeyConstraint(
["organization_id"],
["organization.organization_id"],
name="fk_organization_early_issuance_by_year_organization_id",
),
sa.ForeignKeyConstraint(
["compliance_period_id"],
["compliance_period.compliance_period_id"],
name="fk_organization_early_issuance_by_year_compliance_period_id",
),
sa.UniqueConstraint(
"organization_id",
"compliance_period_id",
name="uq_organization_early_issuance_by_year",
),
comment="Tracks early issuance reporting eligibility by organization and compliance year",
)
# Create organization_early_issuance_by_year table (check if exists first)
connection = op.get_bind()
inspector = sa.inspect(connection)

if not inspector.has_table("organization_early_issuance_by_year"):
op.create_table(
"organization_early_issuance_by_year",
sa.Column(
"early_issuance_by_year_id",
sa.Integer(),
autoincrement=True,
nullable=False,
comment="Unique identifier for the early issuance by year record",
),
sa.Column(
"organization_id",
sa.Integer(),
nullable=False,
comment="Foreign key to the organization",
),
sa.Column(
"compliance_period_id",
sa.Integer(),
nullable=False,
comment="Foreign key to the compliance period",
),
sa.Column(
"has_early_issuance",
sa.Boolean(),
nullable=False,
server_default=sa.text("FALSE"),
comment="True if the organization can create early issuance reports for this compliance year",
),
sa.Column(
"create_date",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=True,
comment="Date and time (UTC) when the physical record was created in the database.",
),
sa.Column(
"update_date",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=True,
comment="Date and time (UTC) when the physical record was updated in the database.",
),
sa.Column(
"create_user",
sa.String(),
nullable=True,
comment="The user who created this record in the database.",
),
sa.Column(
"update_user",
sa.String(),
nullable=True,
comment="The user who last updated this record in the database.",
),
sa.PrimaryKeyConstraint("early_issuance_by_year_id"),
sa.ForeignKeyConstraint(
["organization_id"],
["organization.organization_id"],
name="fk_organization_early_issuance_by_year_organization_id",
),
sa.ForeignKeyConstraint(
["compliance_period_id"],
["compliance_period.compliance_period_id"],
name="fk_organization_early_issuance_by_year_compliance_period_id",
),
sa.UniqueConstraint(
"organization_id",
"compliance_period_id",
name="uq_organization_early_issuance_by_year",
),
comment="Tracks early issuance reporting eligibility by organization and compliance year",
)

# Copy all has_early_issuance values from organization table
# to organization_early_issuance_by_year table for the current year (2025)
# Use ON CONFLICT to handle case where data already exists
op.execute(
"""
INSERT INTO organization_early_issuance_by_year (
Expand Down Expand Up @@ -148,4 +153,9 @@ def downgrade() -> None:
"""
)

op.drop_table("organization_early_issuance_by_year")
# Only drop table if it exists
connection = op.get_bind()
inspector = sa.inspect(connection)

if inspector.has_table("organization_early_issuance_by_year"):
op.drop_table("organization_early_issuance_by_year")
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
depends_on = None

# Specify which sections to execute from the SQL file
# These sections create the views that were excluded from the earlier migration
# because they reference organization_early_issuance_by_year table
SECTIONS_TO_EXECUTE = [
"Compliance Report Base View With Early Issuance By Year",
"Allocation Agreement Base View With Early Issuance By Year",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import sqlalchemy as sa
from alembic import op
from sqlalchemy import inspect

# revision identifiers, used by Alembic.
revision = "3eb97134895a"
Expand All @@ -17,17 +18,33 @@


def upgrade() -> None:
op.add_column(
"compliance_report",
sa.Column(
"is_non_assessment",
sa.Boolean(),
nullable=False,
server_default="false",
comment="Flag indicating if report is not subject to assessment under the Low Carbon Fuels Act",
),
)
# Check if the column already exists before adding it
conn = op.get_bind()
inspector = inspect(conn)
columns = [col['name'] for col in inspector.get_columns('compliance_report')]

if 'is_non_assessment' not in columns:
op.add_column(
"compliance_report",
sa.Column(
"is_non_assessment",
sa.Boolean(),
nullable=False,
server_default="false",
comment="Flag indicating if report is not subject to assessment under the Low Carbon Fuels Act",
),
)
else:
print("Column 'is_non_assessment' already exists in compliance_report table, skipping...")


def downgrade() -> None:
op.drop_column("compliance_report", "is_non_assessment")
# Check if the column exists before dropping it
conn = op.get_bind()
inspector = inspect(conn)
columns = [col['name'] for col in inspector.get_columns('compliance_report')]

if 'is_non_assessment' in columns:
op.drop_column("compliance_report", "is_non_assessment")
else:
print("Column 'is_non_assessment' does not exist in compliance_report table, skipping...")
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@

# Sections to recreate after altering columns
SECTIONS_TO_EXECUTE = [
"Allocation Agreement Base View",
"Compliance Reports Analytics View", # Must come first - dependency for Fuel Export Analytics Base View
"Allocation Agreement Chained View",
"Allocation Agreement Base View With Early Issuance By Year",
"Fuel Export Analytics Base View",
"Fuel Supply Analytics Base View",
"Fuel Supply Base View",
Expand Down Expand Up @@ -362,6 +364,7 @@ def upgrade() -> None:
# Using CASCADE to drop dependent views automatically
op.execute("DROP MATERIALIZED VIEW IF EXISTS mv_credit_ledger CASCADE;")
op.execute("DROP MATERIALIZED VIEW IF EXISTS mv_transaction_aggregate CASCADE;")
op.execute("DROP VIEW IF EXISTS vw_allocation_agreement_chained CASCADE;")
op.execute("DROP VIEW IF EXISTS vw_allocation_agreement_base CASCADE;")
op.execute("DROP VIEW IF EXISTS vw_fuel_export_analytics_base CASCADE;")
op.execute("DROP VIEW IF EXISTS vw_fuel_supply_analytics_base CASCADE;")
Expand Down Expand Up @@ -532,6 +535,7 @@ def downgrade() -> None:
# Drop views and materialized views before altering columns back
op.execute("DROP MATERIALIZED VIEW IF EXISTS mv_credit_ledger CASCADE;")
op.execute("DROP MATERIALIZED VIEW IF EXISTS mv_transaction_aggregate CASCADE;")
op.execute("DROP VIEW IF EXISTS vw_allocation_agreement_chained CASCADE;")
op.execute("DROP VIEW IF EXISTS vw_allocation_agreement_base CASCADE;")
op.execute("DROP VIEW IF EXISTS vw_fuel_export_analytics_base CASCADE;")
op.execute("DROP VIEW IF EXISTS vw_fuel_supply_analytics_base CASCADE;")
Expand Down
Loading
Loading