Add field nature_et_num to texte_version
This commit is contained in:
parent
2946026c02
commit
b1f68396c0
3 changed files with 40 additions and 3 deletions
|
@ -88,6 +88,13 @@ export async function configureDatabase() {
|
|||
`
|
||||
}
|
||||
|
||||
if (version.number < 8) {
|
||||
await db`
|
||||
ALTER TABLE IF EXISTS texte_version
|
||||
ADD COLUMN IF NOT EXISTS nature_et_num text
|
||||
`
|
||||
}
|
||||
|
||||
// Types
|
||||
|
||||
// Tables
|
||||
|
@ -160,6 +167,7 @@ export async function configureDatabase() {
|
|||
commission_fond_assemblee_uid text,
|
||||
est_texte_principal boolean,
|
||||
nature text,
|
||||
nature_et_num text,
|
||||
text_search tsvector NOT NULL
|
||||
)
|
||||
`
|
||||
|
@ -244,6 +252,26 @@ export async function configureDatabase() {
|
|||
`
|
||||
}
|
||||
|
||||
if (version.number < 8) {
|
||||
// Fill "nature_et_num" column of table texte_version;
|
||||
for await (const rows of db<
|
||||
Array<{ data: TexteVersion; id: string }>
|
||||
>`SELECT data, id FROM texte_version`.cursor(100)) {
|
||||
for (const { data, id } of rows) {
|
||||
const natureEtNum =
|
||||
data.META.META_COMMUN.NATURE !== undefined &&
|
||||
data.META.META_SPEC.META_TEXTE_CHRONICLE.NUM !== undefined
|
||||
? `${data.META.META_COMMUN.NATURE.toUpperCase()}.${data.META.META_SPEC.META_TEXTE_CHRONICLE.NUM}`
|
||||
: null
|
||||
await db`
|
||||
UPDATE texte_version
|
||||
SET nature_et_num = ${natureEtNum}
|
||||
WHERE id = ${id}
|
||||
`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add indexes once every table and column exists.
|
||||
|
||||
await db`
|
||||
|
@ -257,8 +285,8 @@ export async function configureDatabase() {
|
|||
`
|
||||
|
||||
await db`
|
||||
CREATE INDEX IF NOT EXISTS texte_version_nature_key
|
||||
ON texte_version (nature)
|
||||
CREATE INDEX IF NOT EXISTS texte_version_nature_et_num_key
|
||||
ON texte_version (nature_et_num)
|
||||
`
|
||||
|
||||
// await db`
|
||||
|
|
|
@ -23,7 +23,7 @@ export const db = postgres({
|
|||
port: config.db.port,
|
||||
user: config.db.user,
|
||||
})
|
||||
export const versionNumber = 7
|
||||
export const versionNumber = 8
|
||||
|
||||
/// Check that assemblee database exists and is up to date.
|
||||
export async function checkAssembleeDb(): Promise<void> {
|
||||
|
|
|
@ -355,16 +355,24 @@ async function importJorf(
|
|||
texteVersion.META.META_SPEC.META_TEXTE_VERSION.TITRE,
|
||||
texteVersion.META.META_SPEC.META_TEXTE_VERSION.TITREFULL,
|
||||
].filter((text) => text !== undefined)
|
||||
const natureEtNum =
|
||||
texteVersion.META.META_COMMUN.NATURE !== undefined &&
|
||||
texteVersion.META.META_SPEC.META_TEXTE_CHRONICLE.NUM !==
|
||||
undefined
|
||||
? `${texteVersion.META.META_COMMUN.NATURE.toUpperCase()}.${texteVersion.META.META_SPEC.META_TEXTE_CHRONICLE.NUM}`
|
||||
: null
|
||||
await db`
|
||||
INSERT INTO texte_version (
|
||||
id,
|
||||
data,
|
||||
nature,
|
||||
nature_et_num,
|
||||
text_search
|
||||
) VALUES (
|
||||
${texteVersion.META.META_COMMUN.ID},
|
||||
${db.json(texteVersion as unknown as JSONValue)},
|
||||
${texteVersion.META.META_COMMUN.NATURE ?? null},
|
||||
${natureEtNum},
|
||||
setweight(to_tsvector('french', ${textAFragments.join(
|
||||
" ",
|
||||
)}), 'A')
|
||||
|
@ -373,6 +381,7 @@ async function importJorf(
|
|||
DO UPDATE SET
|
||||
data = ${db.json(texteVersion as unknown as JSONValue)},
|
||||
nature = ${texteVersion.META.META_COMMUN.NATURE ?? null},
|
||||
nature_et_num = ${natureEtNum}
|
||||
text_search = setweight(to_tsvector('french', ${textAFragments.join(
|
||||
" ",
|
||||
)}), 'A')
|
||||
|
|
Loading…
Reference in a new issue