Skip to content

Commit

Permalink
Merge branch 'release-0.2.0' into LCFS-1654-Protect-Routes-Compliance…
Browse files Browse the repository at this point in the history
…Reports
  • Loading branch information
areyeslo authored Jan 17, 2025
2 parents d793d7c + 1a52e70 commit 94a7751
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""add marine end use
Revision ID: 998929392c8b
Revises: 5bc0ef48739a
Create Date: 2025-01-07 19:35:00.064999
"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "998929392c8b"
down_revision = "5bc0ef48739a"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.execute(
"""
INSERT INTO end_use_type (end_use_type_id, type, intended_use)
VALUES (25, 'Marine', TRUE)
ON CONFLICT (end_use_type_id) DO NOTHING;
"""
)
# Energy Effectiveness Ratios
op.execute(
"""
INSERT INTO energy_effectiveness_ratio (
eer_id, fuel_category_id, fuel_type_id, end_use_type_id, ratio, effective_status
)
VALUES (44, 2, 3, 25, 2.5, TRUE)
ON CONFLICT (eer_id) DO NOTHING;
"""
)


def downgrade() -> None:
op.execute(
"""
DELETE FROM energy_effectiveness_ratio
WHERE eer_id = 44;
"""
)
op.execute(
"""
DELETE FROM end_use_type
WHERE end_use_type_id = 25;
"""
)
Binary file modified etl/database/nifi-registry-primary.mv.db
Binary file not shown.
Binary file modified etl/nifi/conf/flow.json.gz
Binary file not shown.
Binary file modified etl/nifi/conf/flow.xml.gz
Binary file not shown.
73 changes: 53 additions & 20 deletions etl/nifi_scripts/clean_ups.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import java.sql.Connection
import java.sql.PreparedStatement
import java.sql.ResultSet
import groovy.json.JsonSlurper
import java.sql.SQLException

log.warn('**** STARTING TRANSFER UPDATE SQL ****')

Expand All @@ -14,39 +13,73 @@ def updateTransferEffectiveDateSQL = """
AND update_date::date = transaction_effective_date::date; -- On the same day as transaction_effective_date
"""

// Fetch connections to both source and destination databases
// Replace the UUIDs with your actual Controller Service identifiers
// For this UPDATE, only the destination database connection is required
def destinationDbcpService = context.controllerServiceLookup.getControllerService('3244bf63-0192-1000-ffff-ffffc8ec6d93')
// Cleanup queries
def cleanUpQueries = [
"""
-- 105
UPDATE "transaction"
SET compliance_units = -6994
WHERE transaction_id = 1491;
""",
"""
-- 273
UPDATE compliance_report
SET transaction_id = null
WHERE compliance_report_id = 764;
""",
"""
DELETE FROM "transaction"
WHERE transaction_id = 1920;
"""
]

// Initialize database connections
// Fetch connection to the destination database
def destinationDbcpService = context.controllerServiceLookup.getControllerService('3244bf63-0192-1000-ffff-ffffc8ec6d93')
Connection destinationConn = null

try {
// Get a connection from the Destination DBCP Connection Pool
// Obtain a connection from the Destination DBCP Connection Pool
destinationConn = destinationDbcpService.getConnection()
destinationConn.setAutoCommit(false) // Begin transaction

// Step 1: Execute the UPDATE statement
PreparedStatement updateStmt = destinationConn.prepareStatement(updateTransferEffectiveDateSQL)

// Execute the UPDATE statement
int rowsUpdated = updateStmt.executeUpdate()
// Step 1: Execute the UPDATE on public.transfer
try (PreparedStatement updateStmt = destinationConn.prepareStatement(updateTransferEffectiveDateSQL)) {
int rowsUpdated = updateStmt.executeUpdate()
log.info("Successfully executed UPDATE on 'public.transfer'. Rows affected: ${rowsUpdated}")
}

log.info("Successfully executed UPDATE on 'public.transfer'. Rows affected: ${rowsUpdated}")
// Step 2: Execute the cleanup queries in sequence
cleanUpQueries.each { query ->
try (PreparedStatement stmt = destinationConn.prepareStatement(query)) {
stmt.executeUpdate()
}
}
log.info("Cleanup queries executed successfully.")

// Close the UPDATE statement
updateStmt.close()
// Commit transaction
destinationConn.commit()
log.info("Transaction committed successfully.")

} catch (Exception e) {
log.error('Error occurred while executing TRANSFER UPDATE SQL', e)
throw new ProcessException(e)
// Rollback transaction on error
if (destinationConn != null) {
try {
destinationConn.rollback()
log.warn("Transaction rolled back due to error.")
} catch (SQLException rollbackEx) {
log.error("Error occurred during transaction rollback", rollbackEx)
}
}
log.error('Error occurred during SQL operations', e)
throw new RuntimeException(e)
} finally {
// Ensure the connection is closed
if (destinationConn != null) {
try {
destinationConn.close()
} catch (SQLException ignore) {
// Ignored
log.info("Database connection closed.")
} catch (SQLException closeEx) {
log.warn("Error occurred while closing the database connection", closeEx)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/Dockerfile.openshift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM artifacts.developer.gov.bc.ca/docker-remote/node:20 as builder
FROM artifacts.developer.gov.bc.ca/docker-remote/node:20.18.1 as builder
ENV NODE_ENV=production
WORKDIR /usr/src/app
COPY ./ ./
Expand Down

0 comments on commit 94a7751

Please sign in to comment.