From b7504d1947c31172dfadfd4c685ccae2c61b2712 Mon Sep 17 00:00:00 2001 From: Emmanuel Raviart Date: Sun, 12 May 2024 23:36:27 +0200 Subject: [PATCH] Improve format of liens in database --- package-lock.json | 194 +++++++++++----------- package.json | 2 +- src/lib/legal/index.ts | 3 + src/lib/legal/jorf.ts | 2 +- src/lib/legal/legi.ts | 4 +- src/lib/legal/shared.ts | 2 + src/lib/server/auditors/config.ts | 5 +- src/lib/server/databases/configuration.ts | 24 ++- src/lib/server/databases/index.ts | 2 +- src/scripts/index_liens.ts | 14 +- 10 files changed, 146 insertions(+), 106 deletions(-) diff --git a/package-lock.json b/package-lock.json index fbb16bf..53911c8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -35,7 +35,7 @@ "autoprefixer": "^10.4.7", "daisyui": "^4.4.22", "dotenv": "^16.0.1", - "eslint": "^8.16.0", + "eslint": "^8.57.0", "eslint-config-prettier": "^9.0.0", "eslint-plugin-svelte": "^2.28.0", "fs-extra": "^11.1.0", @@ -1173,22 +1173,22 @@ } }, "node_modules/@tricoteuses/assemblee/node_modules/glob": { - "version": "10.3.12", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.12.tgz", - "integrity": "sha512-TCNv8vJ+xz4QiqTpfOJA7HvYv+tNIRHKfUWw/q+v2jdgN4ebz+KY9tGx5J4rHP0o84mNP+ApH66HRX8us3Khqg==", + "version": "10.3.15", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.15.tgz", + "integrity": "sha512-0c6RlJt1TICLyvJYIApxb8GsXoai0KUP7AxKKAtsYXdgJR1mGEUa7DgwShbdk1nly0PYoZj01xd4hzbq3fsjpw==", "dev": true, "dependencies": { "foreground-child": "^3.1.0", "jackspeak": "^2.3.6", "minimatch": "^9.0.1", "minipass": "^7.0.4", - "path-scurry": "^1.10.2" + "path-scurry": "^1.11.0" }, "bin": { "glob": "dist/esm/bin.mjs" }, "engines": { - "node": ">=16 || 14 >=14.17" + "node": ">=16 || 14 >=14.18" }, "funding": { "url": "https://github.com/sponsors/isaacs" @@ -1382,6 +1382,58 @@ } } }, + "node_modules/@typescript-eslint/eslint-plugin/node_modules/@typescript-eslint/type-utils": { + "version": "7.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.8.0.tgz", + "integrity": "sha512-H70R3AefQDQpz9mGv13Uhi121FNMh+WEaRqcXTX09YEDky21km4dV1ZXJIp8QjXc4ZaVkXVdohvWDzbnbHDS+A==", + "dev": true, + "dependencies": { + "@typescript-eslint/typescript-estree": "7.8.0", + "@typescript-eslint/utils": "7.8.0", + "debug": "^4.3.4", + "ts-api-utils": "^1.3.0" + }, + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.56.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/eslint-plugin/node_modules/@typescript-eslint/utils": { + "version": "7.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.8.0.tgz", + "integrity": "sha512-L0yFqOCflVqXxiZyXrDr80lnahQfSOfc9ELAAZ75sqicqp2i36kEZZGuUymHNFoYOqxRT05up760b4iGsl02nQ==", + "dev": true, + "dependencies": { + "@eslint-community/eslint-utils": "^4.4.0", + "@types/json-schema": "^7.0.15", + "@types/semver": "^7.5.8", + "@typescript-eslint/scope-manager": "7.8.0", + "@typescript-eslint/types": "7.8.0", + "@typescript-eslint/typescript-estree": "7.8.0", + "semver": "^7.6.0" + }, + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.56.0" + } + }, "node_modules/@typescript-eslint/parser": { "version": "7.8.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.8.0.tgz", @@ -1427,33 +1479,6 @@ "url": "https://opencollective.com/typescript-eslint" } }, - "node_modules/@typescript-eslint/type-utils": { - "version": "7.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.8.0.tgz", - "integrity": "sha512-H70R3AefQDQpz9mGv13Uhi121FNMh+WEaRqcXTX09YEDky21km4dV1ZXJIp8QjXc4ZaVkXVdohvWDzbnbHDS+A==", - "dev": true, - "dependencies": { - "@typescript-eslint/typescript-estree": "7.8.0", - "@typescript-eslint/utils": "7.8.0", - "debug": "^4.3.4", - "ts-api-utils": "^1.3.0" - }, - "engines": { - "node": "^18.18.0 || >=20.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "eslint": "^8.56.0" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } - } - }, "node_modules/@typescript-eslint/types": { "version": "7.8.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.8.0.tgz", @@ -1495,31 +1520,6 @@ } } }, - "node_modules/@typescript-eslint/utils": { - "version": "7.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.8.0.tgz", - "integrity": "sha512-L0yFqOCflVqXxiZyXrDr80lnahQfSOfc9ELAAZ75sqicqp2i36kEZZGuUymHNFoYOqxRT05up760b4iGsl02nQ==", - "dev": true, - "dependencies": { - "@eslint-community/eslint-utils": "^4.4.0", - "@types/json-schema": "^7.0.15", - "@types/semver": "^7.5.8", - "@typescript-eslint/scope-manager": "7.8.0", - "@typescript-eslint/types": "7.8.0", - "@typescript-eslint/typescript-estree": "7.8.0", - "semver": "^7.6.0" - }, - "engines": { - "node": "^18.18.0 || >=20.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "eslint": "^8.56.0" - } - }, "node_modules/@typescript-eslint/visitor-keys": { "version": "7.8.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.8.0.tgz", @@ -1926,9 +1926,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001616", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001616.tgz", - "integrity": "sha512-RHVYKov7IcdNjVHJFNY/78RdG4oGVjbayxv8u5IO74Wv7Hlq4PnJE6mo/OjFijjVFNy5ijnCt6H3IIo4t+wfEw==", + "version": "1.0.30001617", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001617.tgz", + "integrity": "sha512-mLyjzNI9I+Pix8zwcrpxEbGlfqOkF9kM3ptzmKNw5tizSyYwMe+nGLTqMK9cO+0E+Bh6TsBxNAaHWEM8xwSsmA==", "dev": true, "funding": [ { @@ -2515,9 +2515,9 @@ "dev": true }, "node_modules/electron-to-chromium": { - "version": "1.4.759", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.759.tgz", - "integrity": "sha512-qZJc+zsuI+/5UjOSFnpkJBwwLMH1AZgyKqJ7LUNnRsB7v/cDjMu9DvXgp9kH6PTTZxjnPXGp2Uhurw+2Ll4Hjg==", + "version": "1.4.763", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.763.tgz", + "integrity": "sha512-k4J8NrtJ9QrvHLRo8Q18OncqBCB7tIUyqxRcJnlonQ0ioHKYB988GcDFF3ZePmnb8eHEopDs/wPHR/iGAFgoUQ==", "dev": true }, "node_modules/emoji-regex": { @@ -2725,9 +2725,9 @@ } }, "node_modules/eslint-plugin-svelte": { - "version": "2.38.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-svelte/-/eslint-plugin-svelte-2.38.0.tgz", - "integrity": "sha512-IwwxhHzitx3dr0/xo0z4jjDlb2AAHBPKt+juMyKKGTLlKi1rZfA4qixMwnveU20/JTHyipM6keX4Vr7LZFYc9g==", + "version": "2.39.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-svelte/-/eslint-plugin-svelte-2.39.0.tgz", + "integrity": "sha512-FXktBLXsrxbA+6ZvJK2z/sQOrUKyzSg3fNWK5h0reSCjr2fjAsc9ai/s/JvSl4Hgvz3nYVtTIMwarZH5RcB7BA==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", @@ -2735,13 +2735,13 @@ "debug": "^4.3.4", "eslint-compat-utils": "^0.5.0", "esutils": "^2.0.3", - "known-css-properties": "^0.30.0", + "known-css-properties": "^0.31.0", "postcss": "^8.4.38", "postcss-load-config": "^3.1.4", "postcss-safe-parser": "^6.0.0", "postcss-selector-parser": "^6.0.16", "semver": "^7.6.0", - "svelte-eslint-parser": ">=0.35.0 <1.0.0" + "svelte-eslint-parser": ">=0.36.0 <1.0.0" }, "engines": { "node": "^14.17.0 || >=16.0.0" @@ -3348,9 +3348,9 @@ } }, "node_modules/get-tsconfig": { - "version": "4.7.4", - "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.7.4.tgz", - "integrity": "sha512-ofbkKj+0pjXjhejr007J/fLf+sW+8H7K5GCm+msC8q3IpvgjobpyPqSRFemNyIMxklC0zeJpi7VDFna19FacvQ==", + "version": "4.7.5", + "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.7.5.tgz", + "integrity": "sha512-ZCuZCnlqNzjb4QprAzXKdpp/gh6KTxSJuw3IBsPnV/7fV4NxC9ckB+vPTt8w7fJA0TaSD7c55BR47JD6MEDyDw==", "dev": true, "dependencies": { "resolve-pkg-maps": "^1.0.0" @@ -4154,9 +4154,9 @@ } }, "node_modules/known-css-properties": { - "version": "0.30.0", - "resolved": "https://registry.npmjs.org/known-css-properties/-/known-css-properties-0.30.0.tgz", - "integrity": "sha512-VSWXYUnsPu9+WYKkfmJyLKtIvaRJi1kXUqVmBACORXZQxT5oZDsoZ2vQP+bQFDnWtpI/4eq3MLoRMjI2fnLzTQ==", + "version": "0.31.0", + "resolved": "https://registry.npmjs.org/known-css-properties/-/known-css-properties-0.31.0.tgz", + "integrity": "sha512-sBPIUGTNF0czz0mwGGUoKKJC8Q7On1GPbCSFPfyEsfHb2DyBG0Y4QtV+EVWpINSaiGKZblDNuF5AezxSgOhesQ==", "dev": true }, "node_modules/levn": { @@ -4359,9 +4359,9 @@ } }, "node_modules/minipass": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.0.tgz", - "integrity": "sha512-oGZRv2OT1lO2UF1zUcwdTb3wqUwI0kBGTgt/T7OdSj6M6N5m3o5uPf0AIW6lVxGGoiWUR7e2AwTE+xiwK8WQig==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.1.tgz", + "integrity": "sha512-UZ7eQ+h8ywIRAW1hIEl2AqdwzJucU/Kp59+8kkZeSvafXhZjul247BvIJjEVFVeON6d7lM46XX1HXCduKAS8VA==", "dev": true, "engines": { "node": ">=16 || 14 >=14.17" @@ -4797,16 +4797,16 @@ "dev": true }, "node_modules/path-scurry": { - "version": "1.10.2", - "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.10.2.tgz", - "integrity": "sha512-7xTavNy5RQXnsjANvVvMkEjvloOinkAjv/Z6Ildz9v2RinZ4SBKTWFOVRbaF8p0vpHnyjV/UwNDdKuUv6M5qcA==", + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.11.1.tgz", + "integrity": "sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==", "dev": true, "dependencies": { "lru-cache": "^10.2.0", "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0" }, "engines": { - "node": ">=16 || 14 >=14.17" + "node": ">=16 || 14 >=14.18" }, "funding": { "url": "https://github.com/sponsors/isaacs" @@ -5636,9 +5636,9 @@ } }, "node_modules/semver": { - "version": "7.6.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.1.tgz", - "integrity": "sha512-f/vbBsu+fOiYt+lmwZV0rVwJScl46HppnOA1ZvIuBWKOTlllpyJ3bfVax76/OrhCH38dyxoDIA8K7uB963IYgA==", + "version": "7.6.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.2.tgz", + "integrity": "sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w==", "dev": true, "bin": { "semver": "bin/semver.js" @@ -5963,22 +5963,22 @@ } }, "node_modules/sucrase/node_modules/glob": { - "version": "10.3.12", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.12.tgz", - "integrity": "sha512-TCNv8vJ+xz4QiqTpfOJA7HvYv+tNIRHKfUWw/q+v2jdgN4ebz+KY9tGx5J4rHP0o84mNP+ApH66HRX8us3Khqg==", + "version": "10.3.15", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.15.tgz", + "integrity": "sha512-0c6RlJt1TICLyvJYIApxb8GsXoai0KUP7AxKKAtsYXdgJR1mGEUa7DgwShbdk1nly0PYoZj01xd4hzbq3fsjpw==", "dev": true, "dependencies": { "foreground-child": "^3.1.0", "jackspeak": "^2.3.6", "minimatch": "^9.0.1", "minipass": "^7.0.4", - "path-scurry": "^1.10.2" + "path-scurry": "^1.11.0" }, "bin": { "glob": "dist/esm/bin.mjs" }, "engines": { - "node": ">=16 || 14 >=14.17" + "node": ">=16 || 14 >=14.18" }, "funding": { "url": "https://github.com/sponsors/isaacs" @@ -6056,9 +6056,9 @@ } }, "node_modules/svelte-eslint-parser": { - "version": "0.35.0", - "resolved": "https://registry.npmjs.org/svelte-eslint-parser/-/svelte-eslint-parser-0.35.0.tgz", - "integrity": "sha512-CtbPseajW0gjwEvHiuzYJkPDjAcHz2FaHt540j6RVYrZgnE6xWkzUBodQ4I3nV+G5AS0Svt8K6aIA/CIU9xT2Q==", + "version": "0.36.0", + "resolved": "https://registry.npmjs.org/svelte-eslint-parser/-/svelte-eslint-parser-0.36.0.tgz", + "integrity": "sha512-/6YmUSr0FAVxW8dXNdIMydBnddPMHzaHirAZ7RrT21XYdgGGZMh0LQG6CZsvAFS4r2Y4ItUuCQc8TQ3urB30mQ==", "dev": true, "dependencies": { "eslint-scope": "^7.2.2", @@ -6074,7 +6074,7 @@ "url": "https://github.com/sponsors/ota-meshi" }, "peerDependencies": { - "svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.112" + "svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.115" }, "peerDependenciesMeta": { "svelte": { @@ -6432,9 +6432,9 @@ "dev": true }, "node_modules/tsx": { - "version": "4.9.3", - "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.9.3.tgz", - "integrity": "sha512-czVbetlILiyJZI5zGlj2kw9vFiSeyra9liPD4nG+Thh4pKTi0AmMEQ8zdV/L2xbIVKrIqif4sUNrsMAOksx9Zg==", + "version": "4.10.1", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.10.1.tgz", + "integrity": "sha512-G+CcyTOopwhuI81FU+KpzGN5UBhHgGEDlGt8mHAXKxv8pDGr6WI7hI7aRjTRol5WzFVsSNuzl3ekCZ0eLIJlEQ==", "dev": true, "dependencies": { "esbuild": "~0.20.2", diff --git a/package.json b/package.json index 7470dbc..103ff6d 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "autoprefixer": "^10.4.7", "daisyui": "^4.4.22", "dotenv": "^16.0.1", - "eslint": "^8.16.0", + "eslint": "^8.57.0", "eslint-config-prettier": "^9.0.0", "eslint-plugin-svelte": "^2.28.0", "fs-extra": "^11.1.0", diff --git a/src/lib/legal/index.ts b/src/lib/legal/index.ts index 91ba69a..a69eab0 100644 --- a/src/lib/legal/index.ts +++ b/src/lib/legal/index.ts @@ -49,6 +49,7 @@ export { type JorfTextelrNature, type JorfTextelrOrigine, type JorfTexteVersion, + type JorfTexteVersionLien, type JorfTexteVersionLienNature, type JorfTexteVersionLienType, type JorfTexteVersionNature, @@ -80,6 +81,7 @@ export { allLegiTexteVersionOrigines, type LegiArticle, type LegiArticleEtat, + type LegiArticleLien, type LegiArticleLienArticleOrigine, type LegiArticleLienNature, type LegiArticleLienType, @@ -99,6 +101,7 @@ export { type LegiTextelrOrigine, type LegiTexteVersion, type LegiTexteVersionEtat, + type LegiTexteVersionLien, type LegiTexteVersionLienNature, type LegiTexteVersionLienType, type LegiTexteVersionNature, diff --git a/src/lib/legal/jorf.ts b/src/lib/legal/jorf.ts index 38c8020..c0cf121 100644 --- a/src/lib/legal/jorf.ts +++ b/src/lib/legal/jorf.ts @@ -338,7 +338,7 @@ export interface JorfTexteVersion { export interface JorfTexteVersionLien { "#text"?: string - "@cidtexte"?: string + "@cidtexte"?: string // Present if and only if @id is present "@datesignatexte"?: string "@id"?: string "@naturetexte"?: JorfTexteVersionLienNature diff --git a/src/lib/legal/legi.ts b/src/lib/legal/legi.ts index 3eb6471..ba65161 100644 --- a/src/lib/legal/legi.ts +++ b/src/lib/legal/legi.ts @@ -68,7 +68,7 @@ export type LegiArticleEtat = (typeof allLegiArticleEtats)[number] export interface LegiArticleLien { "#text"?: string - "@cidtexte"?: string + "@cidtexte"?: string // Present if and only if @id is present "@datesignatexte"?: string "@id"?: string "@naturetexte"?: LegiArticleLienNature @@ -320,7 +320,7 @@ export type LegiTexteVersionEtat = (typeof allLegiTexteVersionEtats)[number] export interface LegiTexteVersionLien { "#text"?: string - "@cidtexte"?: string + "@cidtexte"?: string // Present if and only if @id is present "@datesignatexte"?: string "@id"?: string "@naturetexte"?: LegiTexteVersionLienNature diff --git a/src/lib/legal/shared.ts b/src/lib/legal/shared.ts index d70b97a..fd38378 100644 --- a/src/lib/legal/shared.ts +++ b/src/lib/legal/shared.ts @@ -5,6 +5,7 @@ export const allSens = ["cible", "source"] as const export interface ArticleLienDb { article_id: string cible: boolean + cidtexte: string | null id: string typelien: string } @@ -12,6 +13,7 @@ export interface ArticleLienDb { export interface TexteVersionLienDb { texte_version_id: string cible: boolean + cidtexte: string | null id: string typelien: string } diff --git a/src/lib/server/auditors/config.ts b/src/lib/server/auditors/config.ts index 5321af0..b70e4f3 100644 --- a/src/lib/server/auditors/config.ts +++ b/src/lib/server/auditors/config.ts @@ -1,11 +1,12 @@ import { - type Audit, + auditEmptyToNull, auditInteger, auditRequire, auditStringToNumber, auditTest, auditTrimString, cleanAudit, + type Audit, } from "@auditors/core" export function auditConfig( @@ -48,6 +49,7 @@ export function auditConfig( errors, remainingKeys, auditTrimString, + auditEmptyToNull, auditRequire, ) @@ -77,6 +79,7 @@ export function auditDb( errors, remainingKeys, auditTrimString, + auditEmptyToNull, auditRequire, ) } diff --git a/src/lib/server/databases/configuration.ts b/src/lib/server/databases/configuration.ts index 97b61aa..775244f 100644 --- a/src/lib/server/databases/configuration.ts +++ b/src/lib/server/databases/configuration.ts @@ -95,6 +95,15 @@ export async function configureDatabase() { ` } + if (version.number < 10) { + await db` + DROP TABLE article_lien + ` + await db` + DROP TABLE texte_version_lien + ` + } + // Types // Tables @@ -122,6 +131,7 @@ export async function configureDatabase() { CREATE TABLE IF NOT EXISTS article_lien ( article_id char(20) NOT NULL REFERENCES article(id) ON DELETE CASCADE, cible boolean, + cidtexte char(20), id char(20) NOT NULL, typelien text NOT NULL, PRIMARY KEY (article_id, cible, typelien, id) @@ -196,6 +206,7 @@ export async function configureDatabase() { CREATE TABLE IF NOT EXISTS texte_version_lien ( texte_version_id char(20) NOT NULL REFERENCES texte_version(id) ON DELETE CASCADE, cible boolean, + cidtexte char(20), id char(20) NOT NULL, typelien text NOT NULL, PRIMARY KEY (texte_version_id, cible, typelien, id) @@ -303,7 +314,11 @@ export async function configureDatabase() { // ` await db` - CREATE INDEX IF NOT EXISTS article_lien_reverse_key + CREATE INDEX IF NOT EXISTS article_lien_cidtext_reverse_key + ON article_lien (cidtexte, cible, typelien) + ` + await db` + CREATE INDEX IF NOT EXISTS article_lien_id_reverse_key ON article_lien (id, cible, typelien) ` @@ -323,7 +338,12 @@ export async function configureDatabase() { ` await db` - CREATE INDEX IF NOT EXISTS texte_version_lien_reverse_key + CREATE INDEX IF NOT EXISTS texte_version_lien_cidtext_reverse_key + ON texte_version_lien (cidtexte, cible, typelien) + ` + + await db` + CREATE INDEX IF NOT EXISTS texte_version_lien_id_reverse_key ON texte_version_lien (id, cible, typelien) ` diff --git a/src/lib/server/databases/index.ts b/src/lib/server/databases/index.ts index 1ccce2c..494aec1 100644 --- a/src/lib/server/databases/index.ts +++ b/src/lib/server/databases/index.ts @@ -23,7 +23,7 @@ export const db = postgres({ port: config.db.port, user: config.db.user, }) -export const versionNumber = 9 +export const versionNumber = 10 /// Check that assemblee database exists and is up to date. export async function checkAssembleeDb(): Promise { diff --git a/src/scripts/index_liens.ts b/src/scripts/index_liens.ts index 719b7a2..b4343e6 100644 --- a/src/scripts/index_liens.ts +++ b/src/scripts/index_liens.ts @@ -36,11 +36,12 @@ async function indexLiens(): Promise { await db< { cible: boolean + cidtexte: string | null id: string typelien: LegiArticleLienType }[] >` - SELECT id, cible, typelien + SELECT cible, cidtexte, id, typelien FROM article_lien WHERE article_id = ${id} ` @@ -54,6 +55,7 @@ async function indexLiens(): Promise { existingLienByHash.delete( objectHash({ cible: lien["@sens"] === "cible", + cidtexte: lien["@cidtexte"] ?? null, id: lien["@id"], typelien: lien["@typelien"], }), @@ -62,11 +64,13 @@ async function indexLiens(): Promise { INSERT INTO article_lien ( article_id, cible, + cidtexte, id, typelien ) VALUES ( ${id}, ${lien["@sens"] === "cible"}, + ${lien["@cidtexte"] ?? null}, ${lien["@id"]}, ${lien["@typelien"]} ) @@ -77,6 +81,7 @@ async function indexLiens(): Promise { for (const { cible, + cidtexte, id: linkedId, typelien, } of existingLienByHash.values()) { @@ -85,6 +90,7 @@ async function indexLiens(): Promise { WHERE article_id = ${id} AND cible = ${cible} + AND cidtexte = ${cidtexte} AND id = ${linkedId} AND typelien = ${typelien} ` @@ -114,6 +120,7 @@ async function indexLiens(): Promise { await db< { cible: boolean + cidtexte: string | null id: string typelien: JorfTexteVersionLienType | LegiTexteVersionLienType }[] @@ -132,6 +139,7 @@ async function indexLiens(): Promise { existingLienByHash.delete( objectHash({ cible: lien["@sens"] === "cible", + cidtexte: lien["@cidtexte"] ?? null, id: lien["@id"], typelien: lien["@typelien"], }), @@ -140,11 +148,13 @@ async function indexLiens(): Promise { INSERT INTO texte_version_lien ( texte_version_id, cible, + cidtexte, id, typelien ) VALUES ( ${id}, ${lien["@sens"] === "cible"}, + ${lien["@cidtexte"] ?? null}, ${lien["@id"]}, ${lien["@typelien"]} ) @@ -155,6 +165,7 @@ async function indexLiens(): Promise { for (const { cible, + cidtexte, id: linkedId, typelien, } of existingLienByHash.values()) { @@ -163,6 +174,7 @@ async function indexLiens(): Promise { WHERE texte_version_id_id = ${id} AND cible = ${cible} + AND cidtexte = ${cidtexte} AND id = ${linkedId} AND typelien = ${typelien} `