Skip to content

Commit

Permalink
fix: exclue les versions supprimées de l'index unique
Browse files Browse the repository at this point in the history
Signed-off-by: Maud Royer <hello@maudroyer.fr>
  • Loading branch information
jillro committed Jul 8, 2024
1 parent 534811b commit a5296e9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/providers/cartobio.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async function createOrUpdateOperatorRecord (record, context = {}, customClient)
(numerobio, oc_id, oc_label, created_at, metadata, certification_state, certification_date_debut, certification_date_fin, audit_history, audit_date, audit_notes, version_name)
VALUES ($1, $2, $3, $4, $5, $6, nullif($7, '')::date, nullif($8, '')::date, jsonb_build_array($9::jsonb),
nullif($10, '')::date, $11, COALESCE($12, 'Version créée le ' || to_char(now(), 'DD/MM/YYYY')))
ON CONFLICT (numerobio, audit_date)
ON CONFLICT (numerobio, audit_date) WHERE cartobio_operators.deleted_at IS NULL
DO UPDATE
SET (oc_id, oc_label, updated_at, metadata, certification_state, certification_date_debut, certification_date_fin, audit_history, audit_notes, version_name)
= ($2, $3, $4, $5, coalesce($6, cartobio_operators.certification_state),
Expand Down
32 changes: 32 additions & 0 deletions migrations/20240708101313-audit-date-constraint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

var dbm;
var type;
var seed;

/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function(options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
};

exports.up = async function(db) {
await db.removeIndex('cartobio_operators', 'cartobio_operators_numerobio_audit_date_idx')
await db.runSql(/* sql */`
CREATE UNIQUE INDEX cartobio_operators_numerobio_audit_date_idx
ON "cartobio_operators" ("numerobio", "audit_date") WHERE cartobio_operators.deleted_at IS NULL
`)
};

exports.down = async function(db) {
await db.removeIndex('cartobio_operators', 'cartobio_operators_numerobio_audit_date_idx')
await db.addIndex('cartobio_operators', 'cartobio_operators_numerobio_audit_date_idx', ['numerobio', 'audit_date'], true);
};

exports._meta = {
"version": 1
};

0 comments on commit a5296e9

Please sign in to comment.