Release / release-apk (push) Successful in 8m58s
Release / release-docker (push) Successful in 3m47s
CI / docker (push) Successful in 7s
CI / lint-backend (push) Successful in 1m44s
CI / lint-mobile (push) Failing after 18m59s
CI / test-backend (push) Successful in 2m12s
CI / test-mobile (push) Successful in 8m50s
CI / build-backend (push) Successful in 45s
Backend : resource_previews (000024), GET /files/:id/preview (JPEG
512, images pur Go, PDF page 1 via pdftoppm + poppler au Dockerfile,
cache régénéré sur changement, 404 NO_PREVIEW sinon), POST /export
{password 8+} -> zip AES-256 streamé (fichiers vifs possédés +
manifest.json avec faits, metadata-only sans octets). Deps :
alexmullins/zip, x/image directs. Tests service + handlers + migrations.
Mobile : vignettes distantes (une requête/session puis cache WebP
versionné, garde tried, icône sinon), FileThumbnail cloud-only,
export (mot de passe jamais persisté, cache + partage FileProvider),
bouton Partager ACTION_SEND. Impression papier reportée V4. FR/EN.
Contrat docs/api-v1.md, V3.md (S7 livré, V3 close), AGENTS.md,
VERSION 1.2.0 + CHANGELOG.
531 lines
19 KiB
Go
531 lines
19 KiB
Go
package db
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
"net/url"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/lib/pq"
|
|
)
|
|
|
|
const defaultTestDatabaseURL = "postgres://kazier:kazier@localhost:5432/kazier_migrations_test?sslmode=disable"
|
|
|
|
func testDatabaseURL(t *testing.T) string {
|
|
t.Helper()
|
|
url := TestDatabaseURL(defaultTestDatabaseURL)
|
|
if err := ensureTestDatabaseExists(url); err != nil {
|
|
t.Fatalf("ensure database: %v", err)
|
|
}
|
|
conn, err := sql.Open("postgres", url)
|
|
if err != nil {
|
|
t.Fatalf("open: %v", err)
|
|
}
|
|
defer conn.Close()
|
|
if err := conn.Ping(); err != nil {
|
|
t.Skipf("postgres indisponible (%v) — lancez `docker compose up postgres -d`", err)
|
|
}
|
|
return url
|
|
}
|
|
|
|
// ensureTestDatabaseExists crée la base de tests du package quand Postgres est
|
|
// joignable mais que la base n'est pas encore provisionnée (service CI frais,
|
|
// volume local vierge). Le probing de disponibilité et le skip restent le rôle
|
|
// du Ping de testDatabaseURL.
|
|
func ensureTestDatabaseExists(databaseURL string) error {
|
|
parsed, err := url.Parse(databaseURL)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
dbName := strings.TrimPrefix(parsed.Path, "/")
|
|
if dbName == "" {
|
|
return nil
|
|
}
|
|
maintenance := *parsed
|
|
maintenance.Path = "/postgres"
|
|
conn, err := sql.Open("postgres", maintenance.String())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer conn.Close()
|
|
if err := conn.Ping(); err != nil {
|
|
return nil // Postgres down : le Ping du test skippera
|
|
}
|
|
var exists bool
|
|
if err := conn.QueryRow(`SELECT EXISTS(SELECT 1 FROM pg_database WHERE datname = $1)`, dbName).Scan(&exists); err != nil {
|
|
return err
|
|
}
|
|
if !exists {
|
|
if _, err := conn.Exec(fmt.Sprintf(`CREATE DATABASE %s`, pq.QuoteIdentifier(dbName))); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func resetSchema(t *testing.T, url string) {
|
|
t.Helper()
|
|
conn, err := sql.Open("postgres", url)
|
|
if err != nil {
|
|
t.Fatalf("open: %v", err)
|
|
}
|
|
defer conn.Close()
|
|
if _, err := conn.Exec(`DROP SCHEMA public CASCADE; CREATE SCHEMA public;`); err != nil {
|
|
t.Fatalf("reset schema: %v", err)
|
|
}
|
|
}
|
|
|
|
func tableNames(t *testing.T, conn *sql.DB) map[string]bool {
|
|
t.Helper()
|
|
rows, err := conn.Query(`
|
|
SELECT table_name FROM information_schema.tables
|
|
WHERE table_schema = 'public' AND table_type = 'BASE TABLE'`)
|
|
if err != nil {
|
|
t.Fatalf("list tables: %v", err)
|
|
}
|
|
defer rows.Close()
|
|
names := map[string]bool{}
|
|
for rows.Next() {
|
|
var name string
|
|
if err := rows.Scan(&name); err != nil {
|
|
t.Fatalf("scan: %v", err)
|
|
}
|
|
names[name] = true
|
|
}
|
|
return names
|
|
}
|
|
|
|
func assertTables(t *testing.T, conn *sql.DB, expected ...string) {
|
|
t.Helper()
|
|
got := tableNames(t, conn)
|
|
for _, table := range expected {
|
|
if !got[table] {
|
|
t.Errorf("table manquante après migrate up : %s", table)
|
|
}
|
|
}
|
|
}
|
|
|
|
func assertHexCheck(t *testing.T, conn *sql.DB, table, column string) {
|
|
t.Helper()
|
|
var def string
|
|
err := conn.QueryRow(`
|
|
SELECT pg_get_constraintdef(c.oid)
|
|
FROM pg_constraint c
|
|
JOIN pg_class t ON t.oid = c.conrelid
|
|
WHERE t.relname = $1 AND c.contype = 'c'
|
|
AND pg_get_constraintdef(c.oid) LIKE '%' || $2 || '%'`,
|
|
table, column).Scan(&def)
|
|
if err != nil {
|
|
t.Fatalf("contrainte CHECK(hex) manquante sur %s.%s: %v", table, column, err)
|
|
}
|
|
if !strings.Contains(def, "^[0-9a-f]{32}$") {
|
|
t.Errorf("CHECK %s.%s attendu avec pattern 32-hex, obtenu : %s", table, column, def)
|
|
}
|
|
}
|
|
|
|
func TestMigrationsUpDown(t *testing.T) {
|
|
url := testDatabaseURL(t)
|
|
resetSchema(t, url)
|
|
|
|
if err := MigrateDatabase(url); err != nil {
|
|
t.Fatalf("migrate up: %v", err)
|
|
}
|
|
|
|
conn, err := sql.Open("postgres", url)
|
|
if err != nil {
|
|
t.Fatalf("open: %v", err)
|
|
}
|
|
defer conn.Close()
|
|
if err := conn.Ping(); err != nil {
|
|
t.Fatalf("ping: %v", err)
|
|
}
|
|
|
|
assertTables(t, conn, "users", "devices", "resources", "operations", "ocr_jobs", "schema_migrations")
|
|
|
|
assertHexCheck(t, conn, "devices", "device_id")
|
|
assertHexCheck(t, conn, "resources", "resource_id")
|
|
assertHexCheck(t, conn, "ocr_jobs", "job_id")
|
|
assertHexCheck(t, conn, "users", "id")
|
|
|
|
// --- 000006 : identité utilisateur ----------------------------------
|
|
usersColumns := []string{"username", "username_normalized", "password_hash", "is_admin"}
|
|
for _, col := range usersColumns {
|
|
var tpe string
|
|
err = conn.QueryRow(`
|
|
SELECT data_type FROM information_schema.columns
|
|
WHERE table_schema = 'public' AND table_name = 'users' AND column_name = $1`, col).Scan(&tpe)
|
|
if err != nil {
|
|
t.Errorf("colonne users.%s manquante: %v", col, err)
|
|
}
|
|
}
|
|
|
|
// username_unique : index UNIQUE partiel sur username_normalized
|
|
var usernameUnique int
|
|
err = conn.QueryRow(`
|
|
SELECT COUNT(*) FROM pg_index i
|
|
JOIN pg_class t ON t.oid = i.indrelid
|
|
WHERE t.relname = 'users' AND i.indisunique
|
|
AND ARRAY(SELECT a.attname FROM unnest(i.indkey) WITH ORDINALITY k(attnum, ord)
|
|
JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = k.attnum
|
|
ORDER BY k.ord)::text[] = ARRAY['username_normalized']`).Scan(&usernameUnique)
|
|
if err != nil {
|
|
t.Fatalf("unique username_normalized: %v", err)
|
|
}
|
|
if usernameUnique == 0 {
|
|
t.Error("contrainte UNIQUE(username_normalized) manquante sur users")
|
|
}
|
|
|
|
// idx_users_email a disparu (unicité V1 = username, jamais email)
|
|
var emailIdx int
|
|
err = conn.QueryRow(`
|
|
SELECT COUNT(*) FROM pg_index i
|
|
JOIN pg_class t ON t.oid = i.indrelid
|
|
WHERE t.relname = 'users' AND i.indisunique
|
|
AND ARRAY(SELECT a.attname FROM unnest(i.indkey) WITH ORDINALITY k(attnum, ord)
|
|
JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = k.attnum
|
|
ORDER BY k.ord)::text[] = ARRAY['email']`).Scan(&emailIdx)
|
|
if err != nil {
|
|
t.Fatalf("email idx: %v", err)
|
|
}
|
|
if emailIdx != 0 {
|
|
t.Error("index UNIQUE(email) ne doit plus exister après 000006")
|
|
}
|
|
|
|
// --- 000007 : ownership ressources user ------------------------------
|
|
var plc string
|
|
err = conn.QueryRow(`
|
|
SELECT data_type FROM information_schema.columns
|
|
WHERE table_schema = 'public' AND table_name = 'resources' AND column_name = 'user_id'`).Scan(&plc)
|
|
if err != nil {
|
|
t.Errorf("colonne resources.user_id manquante après 000007: %v", err)
|
|
}
|
|
|
|
var resourceFkToUsers int
|
|
err = conn.QueryRow(`
|
|
SELECT COUNT(*) FROM pg_constraint c
|
|
JOIN pg_class t ON t.oid = c.conrelid
|
|
JOIN pg_class r ON r.oid = c.confrelid
|
|
WHERE t.relname = 'resources' AND r.relname = 'users' AND c.contype = 'f'
|
|
AND pg_get_constraintdef(c.oid) LIKE '%user_id%'`).Scan(&resourceFkToUsers)
|
|
if err != nil {
|
|
t.Fatalf("FK resources→users: %v", err)
|
|
}
|
|
if resourceFkToUsers == 0 {
|
|
t.Error("FK resources.user_id → users(id) manquante après 000007")
|
|
}
|
|
|
|
// --- 000007 : migration douce (#10) ----------------------------------
|
|
// user_id NULLABLE (orphelines conservées, pas de DELETE FROM resources).
|
|
var userIDNullable string
|
|
err = conn.QueryRow(`
|
|
SELECT is_nullable FROM information_schema.columns
|
|
WHERE table_schema = 'public' AND table_name = 'resources' AND column_name = 'user_id'`).Scan(&userIDNullable)
|
|
if err != nil {
|
|
t.Fatalf("resources.user_id nullabilité: %v", err)
|
|
}
|
|
if userIDNullable != "YES" {
|
|
t.Error("resources.user_id doit être NULLABLE après 000007 (migration douce, orphelines)")
|
|
}
|
|
|
|
// --- 000011 : index snapshot delta (LOT 4) -----------------------------
|
|
var ownerUpdatedIdx int
|
|
err = conn.QueryRow(`
|
|
SELECT COUNT(*) FROM pg_index i
|
|
JOIN pg_class t ON t.oid = i.indrelid
|
|
WHERE t.relname = 'resources' AND i.indisvalid
|
|
AND pg_get_indexdef(i.indexrelid) LIKE '%idx_resources_owner_updated_active%'`).Scan(&ownerUpdatedIdx)
|
|
if err != nil {
|
|
t.Fatalf("000011 index: %v", err)
|
|
}
|
|
if ownerUpdatedIdx == 0 {
|
|
t.Error("index idx_resources_owner_updated_active manquant après 000011")
|
|
}
|
|
|
|
// operation_id outbox = UUID 32-hex client-generated — cf. docs/api-v1.md §6.1
|
|
var opType string
|
|
err = conn.QueryRow(`
|
|
SELECT data_type FROM information_schema.columns
|
|
WHERE table_schema = 'public' AND table_name = 'operations' AND column_name = 'operation_id'`).Scan(&opType)
|
|
if err != nil {
|
|
t.Fatalf("operation_id type: %v", err)
|
|
}
|
|
if opType != "text" {
|
|
t.Errorf("operation_id attendu text, got %s", opType)
|
|
}
|
|
assertHexCheck(t, conn, "operations", "operation_id")
|
|
|
|
var resourceTypeCheck int
|
|
err = conn.QueryRow(`
|
|
SELECT COUNT(*) FROM pg_constraint c
|
|
JOIN pg_class t ON t.oid = c.conrelid
|
|
WHERE t.relname = 'resources'
|
|
AND pg_get_constraintdef(c.oid) LIKE '%''file''%'
|
|
AND pg_get_constraintdef(c.oid) LIKE '%''folder''%'`).Scan(&resourceTypeCheck)
|
|
if err != nil {
|
|
t.Fatalf("check type resources: %v", err)
|
|
}
|
|
if resourceTypeCheck == 0 {
|
|
t.Error("CHECK (type IN ('file','folder')) manquant sur resources")
|
|
}
|
|
|
|
var opUnique int
|
|
err = conn.QueryRow(`
|
|
SELECT COUNT(*) FROM pg_index i
|
|
JOIN pg_class t ON t.oid = i.indrelid
|
|
WHERE t.relname = 'operations' AND i.indisunique
|
|
AND ARRAY(SELECT a.attname FROM unnest(i.indkey) WITH ORDINALITY k(attnum, ord)
|
|
JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = k.attnum
|
|
ORDER BY k.ord)::text[] = ARRAY['device_id','operation_id']`).Scan(&opUnique)
|
|
if err != nil {
|
|
t.Fatalf("unique operations: %v", err)
|
|
}
|
|
if opUnique == 0 {
|
|
t.Error("contrainte UNIQUE(device_id, operation_id) manquante sur operations")
|
|
}
|
|
|
|
// --- 000009 : shares + share_links ------------------------------------
|
|
assertTables(t, conn, "users", "devices", "resources", "operations", "ocr_jobs", "shares", "share_links", "schema_migrations")
|
|
|
|
assertHexCheck(t, conn, "shares", "id")
|
|
assertHexCheck(t, conn, "share_links", "id")
|
|
|
|
// shares access CHECK
|
|
var sharesAccessCheck int
|
|
err = conn.QueryRow(`
|
|
SELECT COUNT(*) FROM pg_constraint c
|
|
JOIN pg_class t ON t.oid = c.conrelid
|
|
WHERE t.relname = 'shares'
|
|
AND pg_get_constraintdef(c.oid) LIKE '%viewer%'
|
|
AND pg_get_constraintdef(c.oid) LIKE '%editor%'`).Scan(&sharesAccessCheck)
|
|
if err != nil {
|
|
t.Fatalf("check shares access: %v", err)
|
|
}
|
|
if sharesAccessCheck == 0 {
|
|
t.Error("CHECK (access IN ('viewer','commenter','editor')) manquant sur shares")
|
|
}
|
|
|
|
// shares unique partiel (resource_id, grantee_user_id) WHERE revoked_at IS NULL
|
|
var sharesActiveIdx int
|
|
err = conn.QueryRow(`
|
|
SELECT COUNT(*) FROM pg_index i
|
|
JOIN pg_class t ON t.oid = i.indrelid
|
|
WHERE t.relname = 'shares' AND i.indisunique
|
|
AND i.indpred IS NOT NULL`).Scan(&sharesActiveIdx)
|
|
if err != nil {
|
|
t.Fatalf("shares active index: %v", err)
|
|
}
|
|
if sharesActiveIdx == 0 {
|
|
t.Error("index unique partiel (resource_id, grantee_user_id) WHERE revoked_at IS NULL manquant sur shares")
|
|
}
|
|
|
|
// share_links token unique partiel
|
|
var linksTokenIdx int
|
|
err = conn.QueryRow(`
|
|
SELECT COUNT(*) FROM pg_index i
|
|
JOIN pg_class t ON t.oid = i.indrelid
|
|
WHERE t.relname = 'share_links' AND i.indisunique
|
|
AND i.indpred IS NOT NULL`).Scan(&linksTokenIdx)
|
|
if err != nil {
|
|
t.Fatalf("share_links token index: %v", err)
|
|
}
|
|
if linksTokenIdx == 0 {
|
|
t.Error("index unique partiel (id) WHERE revoked_at IS NULL manquant sur share_links")
|
|
}
|
|
|
|
// --- 000014 : has_content + 000015 : placements -------------------------
|
|
var hasContentCol int
|
|
err = conn.QueryRow(`
|
|
SELECT COUNT(*) FROM information_schema.columns
|
|
WHERE table_schema = 'public' AND table_name = 'resources' AND column_name = 'has_content'`).Scan(&hasContentCol)
|
|
if err != nil {
|
|
t.Fatalf("has_content column: %v", err)
|
|
}
|
|
if hasContentCol == 0 {
|
|
t.Error("colonne resources.has_content manquante après 000014")
|
|
}
|
|
|
|
assertTables(t, conn, "users", "devices", "resources", "operations", "ocr_jobs", "shares", "share_links", "storage_locations", "resource_placements", "schema_migrations")
|
|
|
|
assertHexCheck(t, conn, "storage_locations", "id")
|
|
assertHexCheck(t, conn, "storage_locations", "device_id")
|
|
assertHexCheck(t, conn, "groups", "id")
|
|
|
|
// shares XOR : exactement une cible (user ou groupe).
|
|
var xorCheck int
|
|
err = conn.QueryRow(`
|
|
SELECT COUNT(*) FROM pg_constraint c
|
|
JOIN pg_class t ON t.oid = c.conrelid
|
|
WHERE t.relname = 'shares'
|
|
AND pg_get_constraintdef(c.oid) LIKE '%grantee_user_id%'
|
|
AND pg_get_constraintdef(c.oid) LIKE '%grantee_group_id%'`).Scan(&xorCheck)
|
|
if err != nil {
|
|
t.Fatalf("shares xor check: %v", err)
|
|
}
|
|
if xorCheck == 0 {
|
|
t.Error("CHECK XOR (grantee_user_id / grantee_group_id) manquant sur shares après 000016")
|
|
}
|
|
|
|
// --- 000016 : groupes + cible groupe sur shares -------------------------
|
|
assertTables(t, conn, "users", "devices", "resources", "operations", "ocr_jobs", "shares", "share_links", "storage_locations", "resource_placements", "groups", "group_members", "schema_migrations")
|
|
|
|
// --- 000017 : corbeille (index partiel deleted_at) ----------------------
|
|
var trashedIdx int
|
|
err = conn.QueryRow(`
|
|
SELECT COUNT(*) FROM pg_index i
|
|
JOIN pg_class t ON t.oid = i.indrelid
|
|
WHERE t.relname = 'resources' AND i.indisvalid
|
|
AND pg_get_indexdef(i.indexrelid) LIKE '%idx_resources_trashed_active%'`).Scan(&trashedIdx)
|
|
if err != nil {
|
|
t.Fatalf("000017 index: %v", err)
|
|
}
|
|
if trashedIdx == 0 {
|
|
t.Error("index idx_resources_trashed_active manquant après 000017")
|
|
}
|
|
|
|
// --- 000018 : versions --------------------------------------------------
|
|
assertTables(t, conn, "users", "devices", "resources", "operations", "ocr_jobs", "shares", "share_links", "storage_locations", "resource_placements", "groups", "group_members", "resource_versions", "schema_migrations")
|
|
|
|
assertHexCheck(t, conn, "resource_versions", "id")
|
|
|
|
var versionUniq int
|
|
err = conn.QueryRow(`
|
|
SELECT COUNT(*) FROM pg_index i
|
|
JOIN pg_class t ON t.oid = i.indrelid
|
|
WHERE t.relname = 'resource_versions' AND i.indisunique
|
|
AND ARRAY(SELECT a.attname FROM unnest(i.indkey) WITH ORDINALITY k(attnum, ord)
|
|
JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = k.attnum
|
|
ORDER BY k.ord)::text[] = ARRAY['resource_id','version_no']`).Scan(&versionUniq)
|
|
if err != nil {
|
|
t.Fatalf("versions unique: %v", err)
|
|
}
|
|
if versionUniq == 0 {
|
|
t.Error("contrainte UNIQUE(resource_id, version_no) manquante sur resource_versions après 000018")
|
|
}
|
|
|
|
// --- 000019 : faits génériques -----------------------------------------
|
|
assertTables(t, conn, "users", "devices", "resources", "operations", "ocr_jobs", "shares", "share_links", "storage_locations", "resource_placements", "groups", "group_members", "resource_versions", "resource_facts", "schema_migrations")
|
|
|
|
assertHexCheck(t, conn, "resource_facts", "id")
|
|
|
|
var factTypeCheck int
|
|
err = conn.QueryRow(`
|
|
SELECT COUNT(*) FROM pg_constraint c
|
|
JOIN pg_class t ON t.oid = c.conrelid
|
|
WHERE t.relname = 'resource_facts'
|
|
AND pg_get_constraintdef(c.oid) LIKE '%doc_type%'
|
|
AND pg_get_constraintdef(c.oid) LIKE '%due_date%'`).Scan(&factTypeCheck)
|
|
if err != nil {
|
|
t.Fatalf("check resource_facts.fact_type: %v", err)
|
|
}
|
|
if factTypeCheck == 0 {
|
|
t.Error("CHECK fact_type manquant sur resource_facts après 000019")
|
|
}
|
|
|
|
// --- 000020 : plein-texte ----------------------------------------------
|
|
var tsvCol int
|
|
err = conn.QueryRow(`
|
|
SELECT COUNT(*) FROM information_schema.columns
|
|
WHERE table_schema = 'public' AND table_name = 'resources' AND column_name = 'search_tsv'`).Scan(&tsvCol)
|
|
if err != nil {
|
|
t.Fatalf("search_tsv column: %v", err)
|
|
}
|
|
if tsvCol == 0 {
|
|
t.Error("colonne resources.search_tsv manquante après 000020")
|
|
}
|
|
|
|
var tsvIdx int
|
|
err = conn.QueryRow(`
|
|
SELECT COUNT(*) FROM pg_index i
|
|
JOIN pg_class t ON t.oid = i.indrelid
|
|
WHERE t.relname = 'resources' AND i.indisvalid
|
|
AND pg_get_indexdef(i.indexrelid) LIKE '%idx_resources_search_tsv%'`).Scan(&tsvIdx)
|
|
if err != nil {
|
|
t.Fatalf("000020 index: %v", err)
|
|
}
|
|
if tsvIdx == 0 {
|
|
t.Error("index idx_resources_search_tsv manquant après 000020")
|
|
}
|
|
|
|
// --- 000021 : graphe documentaire ----------------------------------------
|
|
assertTables(t, conn, "users", "devices", "resources", "operations", "ocr_jobs", "shares", "share_links", "storage_locations", "resource_placements", "groups", "group_members", "resource_versions", "resource_facts", "resource_links", "schema_migrations")
|
|
|
|
// resource_links.id : CHECK 32-hex (requête ciblée — le helper
|
|
// générique matcherait `from_id <> to_id` qui contient aussi "id").
|
|
var linksIDCheck string
|
|
err = conn.QueryRow(`
|
|
SELECT pg_get_constraintdef(c.oid)
|
|
FROM pg_constraint c
|
|
JOIN pg_class t ON t.oid = c.conrelid
|
|
WHERE t.relname = 'resource_links' AND c.conname = 'resource_links_id_check'`).Scan(&linksIDCheck)
|
|
if err != nil {
|
|
t.Fatalf("contrainte CHECK(resource_links.id) manquante: %v", err)
|
|
}
|
|
if !strings.Contains(linksIDCheck, "^[0-9a-f]{32}$") {
|
|
t.Errorf("CHECK resource_links.id attendu 32-hex, obtenu : %s", linksIDCheck)
|
|
}
|
|
|
|
var linksUniq int
|
|
err = conn.QueryRow(`
|
|
SELECT COUNT(*) FROM pg_index i
|
|
JOIN pg_class t ON t.oid = i.indrelid
|
|
WHERE t.relname = 'resource_links' AND i.indisunique
|
|
AND ARRAY(SELECT a.attname FROM unnest(i.indkey) WITH ORDINALITY k(attnum, ord)
|
|
JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = k.attnum
|
|
ORDER BY k.ord)::text[] = ARRAY['from_id','to_id','link_type']`).Scan(&linksUniq)
|
|
if err != nil {
|
|
t.Fatalf("links unique: %v", err)
|
|
}
|
|
if linksUniq == 0 {
|
|
t.Error("contrainte UNIQUE(from_id, to_id, link_type) manquante sur resource_links après 000021")
|
|
}
|
|
|
|
var scanSessionCol int
|
|
err = conn.QueryRow(`
|
|
SELECT COUNT(*) FROM information_schema.columns
|
|
WHERE table_schema = 'public' AND table_name = 'resources' AND column_name = 'scan_session_id'`).Scan(&scanSessionCol)
|
|
if err != nil {
|
|
t.Fatalf("scan_session_id column: %v", err)
|
|
}
|
|
if scanSessionCol == 0 {
|
|
t.Error("colonne resources.scan_session_id manquante après 000021")
|
|
}
|
|
|
|
// --- 000022 : révocation tokens ------------------------------------------
|
|
var tvCol int
|
|
err = conn.QueryRow(`
|
|
SELECT COUNT(*) FROM information_schema.columns
|
|
WHERE table_schema = 'public' AND table_name = 'users' AND column_name = 'token_version'`).Scan(&tvCol)
|
|
if err != nil {
|
|
t.Fatalf("token_version column: %v", err)
|
|
}
|
|
if tvCol == 0 {
|
|
t.Error("colonne users.token_version manquante après 000022")
|
|
}
|
|
|
|
// --- 000023 : quota (colonne héritée de 000001, IF NOT EXISTS) ------------
|
|
var quotaCol int
|
|
err = conn.QueryRow(`
|
|
SELECT COUNT(*) FROM information_schema.columns
|
|
WHERE table_schema = 'public' AND table_name = 'users' AND column_name = 'storage_quota_bytes'`).Scan("aCol)
|
|
if err != nil {
|
|
t.Fatalf("storage_quota_bytes column: %v", err)
|
|
}
|
|
if quotaCol == 0 {
|
|
t.Error("colonne users.storage_quota_bytes manquante après 000023")
|
|
}
|
|
|
|
// --- 000024 : vignettes serveur ------------------------------------------
|
|
assertTables(t, conn, "users", "devices", "resources", "operations", "ocr_jobs", "shares", "share_links", "storage_locations", "resource_placements", "groups", "group_members", "resource_versions", "resource_facts", "resource_links", "resource_previews", "schema_migrations")
|
|
|
|
if err := MigrateDownDatabase(url); err != nil {
|
|
t.Fatalf("migrate down: %v", err)
|
|
}
|
|
|
|
remaining := tableNames(t, conn)
|
|
delete(remaining, "schema_migrations")
|
|
if len(remaining) > 0 {
|
|
t.Errorf("tables restantes après migrate down : %v", remaining)
|
|
}
|
|
}
|