Skip to content

Commit

Permalink
Merge pull request #1503 from betagouv/hotfix/hydrate-field-order
Browse files Browse the repository at this point in the history
[Hotfix] hydrate field order
  • Loading branch information
jonathanfallon authored Sep 23, 2021
2 parents 04f84f0 + c871765 commit 9cb5302
Show file tree
Hide file tree
Showing 6 changed files with 264 additions and 7 deletions.
8 changes: 8 additions & 0 deletions api/db/migrations/20210923075129-fix_hydrate_trip_fn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

var { createMigration } = require('../helpers/createMigration');
var { setup, up, down } = createMigration(['trip/20210923075129_fix_hydrate_trip_fn'], __dirname);

exports.setup = setup;
exports.up = up;
exports.down = down;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- NOTHING TO DO
226 changes: 226 additions & 0 deletions api/db/migrations/trip/20210923075129_fix_hydrate_trip_fn.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
CREATE OR REPLACE FUNCTION hydrate_trip_from_carpool() RETURNS TRIGGER AS $$
BEGIN
INSERT INTO trip.list (
operator_id,
start_territory_id,
end_territory_id,
applied_policies,
journey_id,
trip_id,
journey_start_datetime,
journey_start_weekday,
journey_start_dayhour,
journey_start_lon,
journey_start_lat,
journey_start_insee,
journey_start_postalcode,
journey_start_department,
journey_start_town,
journey_start_towngroup,
journey_start_country,
journey_end_datetime,
journey_end_lon,
journey_end_lat,
journey_end_insee,
journey_end_postalcode,
journey_end_department,
journey_end_town,
journey_end_towngroup,
journey_end_country,
journey_distance,
journey_distance_anounced,
journey_distance_calculated,
journey_duration,
journey_duration_anounced,
journey_duration_calculated,
operator,
operator_class,
operator_journey_id,
operator_passenger_id,
operator_driver_id,
passenger_id,
passenger_card,
passenger_over_18,
passenger_seats,
passenger_contribution,
passenger_incentive_raw,
passenger_incentive_rpc_raw,
passenger_incentive_rpc_sum,
passenger_incentive_rpc_financial_sum,
driver_id,
driver_card,
driver_revenue,
driver_incentive_raw,
driver_incentive_rpc_raw,
driver_incentive_rpc_sum,
driver_incentive_rpc_financial_sum,
status
) SELECT
operator_id,
start_territory_id,
end_territory_id,
applied_policies,
journey_id,
trip_id,
journey_start_datetime,
journey_start_weekday,
journey_start_dayhour,
journey_start_lon,
journey_start_lat,
journey_start_insee,
journey_start_postalcode,
journey_start_department,
journey_start_town,
journey_start_towngroup,
journey_start_country,
journey_end_datetime,
journey_end_lon,
journey_end_lat,
journey_end_insee,
journey_end_postalcode,
journey_end_department,
journey_end_town,
journey_end_towngroup,
journey_end_country,
journey_distance,
journey_distance_anounced,
journey_distance_calculated,
journey_duration,
journey_duration_anounced,
journey_duration_calculated,
operator,
operator_class,
operator_journey_id,
operator_passenger_id,
operator_driver_id,
passenger_id,
passenger_card,
passenger_over_18,
passenger_seats,
passenger_contribution,
passenger_incentive_raw,
passenger_incentive_rpc_raw,
passenger_incentive_rpc_sum,
passenger_incentive_rpc_financial_sum,
driver_id,
driver_card,
driver_revenue,
driver_incentive_raw,
driver_incentive_rpc_raw,
driver_incentive_rpc_sum,
driver_incentive_rpc_financial_sum,
status
FROM trip.list_view WHERE journey_id = NEW.acquisition_id
ON CONFLICT (journey_id)
DO UPDATE SET (
operator_id,
start_territory_id,
end_territory_id,
applied_policies,
trip_id,
journey_start_datetime,
journey_start_weekday,
journey_start_dayhour,
journey_start_lon,
journey_start_lat,
journey_start_insee,
journey_start_postalcode,
journey_start_department,
journey_start_town,
journey_start_towngroup,
journey_start_country,
journey_end_datetime,
journey_end_lon,
journey_end_lat,
journey_end_insee,
journey_end_postalcode,
journey_end_department,
journey_end_town,
journey_end_towngroup,
journey_end_country,
journey_distance,
journey_distance_anounced,
journey_distance_calculated,
journey_duration,
journey_duration_anounced,
journey_duration_calculated,
operator,
operator_class,
operator_journey_id,
operator_passenger_id,
operator_driver_id,
passenger_id,
passenger_card,
passenger_over_18,
passenger_seats,
passenger_contribution,
passenger_incentive_raw,
passenger_incentive_rpc_raw,
passenger_incentive_rpc_sum,
passenger_incentive_rpc_financial_sum,
driver_id,
driver_card,
driver_revenue,
driver_incentive_raw,
driver_incentive_rpc_raw,
driver_incentive_rpc_sum,
driver_incentive_rpc_financial_sum,
status
) = (
excluded.operator_id,
excluded.start_territory_id,
excluded.end_territory_id,
excluded.applied_policies,
excluded.trip_id,
excluded.journey_start_datetime,
excluded.journey_start_weekday,
excluded.journey_start_dayhour,
excluded.journey_start_lon,
excluded.journey_start_lat,
excluded.journey_start_insee,
excluded.journey_start_postalcode,
excluded.journey_start_department,
excluded.journey_start_town,
excluded.journey_start_towngroup,
excluded.journey_start_country,
excluded.journey_end_datetime,
excluded.journey_end_lon,
excluded.journey_end_lat,
excluded.journey_end_insee,
excluded.journey_end_postalcode,
excluded.journey_end_department,
excluded.journey_end_town,
excluded.journey_end_towngroup,
excluded.journey_end_country,
excluded.journey_distance,
excluded.journey_distance_anounced,
excluded.journey_distance_calculated,
excluded.journey_duration,
excluded.journey_duration_anounced,
excluded.journey_duration_calculated,
excluded.operator,
excluded.operator_class,
excluded.operator_journey_id,
excluded.operator_passenger_id,
excluded.operator_driver_id,
excluded.passenger_id,
excluded.passenger_card,
excluded.passenger_over_18,
excluded.passenger_seats,
excluded.passenger_contribution,
excluded.passenger_incentive_raw,
excluded.passenger_incentive_rpc_raw,
excluded.passenger_incentive_rpc_sum,
excluded.passenger_incentive_rpc_financial_sum,
excluded.driver_id,
excluded.driver_card,
excluded.driver_revenue,
excluded.driver_incentive_raw,
excluded.driver_incentive_rpc_raw,
excluded.driver_incentive_rpc_sum,
excluded.driver_incentive_rpc_financial_sum,
excluded.status
);
RETURN NULL;
END;
$$ language plpgsql;
17 changes: 14 additions & 3 deletions api/pm2-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
"args": "http 8080",
"cwd": "dist",
"watch_delay": 1000,
"watch": ["../../ilos", "../../proxy", "../../providers", "../../services"],
"ignore_watch": ["node_modules", "src"]
}
"watch": [
"../../ilos/*/dist/**/*.js",
"../../proxy/dist/**/*.js",
"../../providers/*/dist/**/*.js",
"../../services/*/dist/**/*.js"
],
"ignore_watch": [
"node_modules",
"src"
],
"env": {
"NODE_OPTIONS": "--trace-warnings"
}
}
17 changes: 14 additions & 3 deletions api/pm2-worker.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
"args": "queue redis://redis:6379",
"cwd": "dist",
"watch_delay": 1000,
"watch": ["../../ilos", "../../proxy", "../../providers", "../../services"],
"ignore_watch": ["node_modules", "src"]
}
"watch": [
"../../ilos/*/dist/**/*.js",
"../../proxy/dist/**/*.js",
"../../providers/*/dist/**/*.js",
"../../services/*/dist/**/*.js"
],
"ignore_watch": [
"node_modules",
"src"
],
"env": {
"NODE_OPTIONS": "--trace-warnings"
}
}
2 changes: 1 addition & 1 deletion docker/lint/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
sourceType: 'module', // Allows for the use of imports
},
// some JS converted to TS. needs to be cleaned up
ignorePatterns: ['dist', 'api/providers/qrcode/src/lib/*', '**/ava.*.cjs'],
ignorePatterns: ['dist', 'api/providers/qrcode/src/lib/*', '**/ava.*.cjs', 'api/db'],
rules: {
semi: ['error', 'always'],
'prettier/prettier': [
Expand Down

0 comments on commit 9cb5302

Please sign in to comment.