Accept empty nature in TEXTE_VERSION

This commit is contained in:
Emmanuel 2023-02-14 18:22:07 +01:00
parent a01f47b004
commit f872e3904f
2 changed files with 11 additions and 8 deletions

View file

@ -55,6 +55,13 @@ export async function configureDatabase() {
`
}
if (version.number < 4) {
await db`
ALTER TABLE IF EXISTS texte_version
ALTER COLUMN nature DROP NOT NULL
`
}
// Types
// Tables
@ -122,7 +129,7 @@ export async function configureDatabase() {
CREATE TABLE IF NOT EXISTS texte_version (
id char(20) PRIMARY KEY,
data jsonb NOT NULL,
nature text NOT NULL,
nature text,
text_search tsvector NOT NULL
)
`
@ -160,19 +167,15 @@ export async function configureDatabase() {
Array<{ data: TexteVersion; id: string; nature: string }>
>`SELECT data, id, nature FROM texte_version`.cursor(100)) {
for (const { data, id, nature } of rows) {
if (data.META.META_COMMUN.NATURE !== nature) {
if ((data.META.META_COMMUN.NATURE ?? null) !== nature) {
await db`
UPDATE texte_version
SET nature = ${data.META.META_COMMUN.NATURE}
SET nature = ${data.META.META_COMMUN.NATURE ?? null}
WHERE id = ${id}
`
}
}
}
await db`
ALTER TABLE texte_version
ALTER COLUMN nature SET NOT NULL
`
// Fill "text_search" column of table texte_version.
for await (const rows of db<

View file

@ -14,7 +14,7 @@ export const db = postgres({
port: config.db.port,
user: config.db.user,
})
export const versionNumber = 3
export const versionNumber = 4
/// Check that database exists and is up to date.
export async function checkDb(): Promise<void> {