feat(db): add object table
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
-- Catalogue objects (the inventory-minimum core). One row = one object or a group.
|
||||||
|
CREATE TABLE object (
|
||||||
|
id UUID PRIMARY KEY,
|
||||||
|
object_number TEXT NOT NULL UNIQUE,
|
||||||
|
object_name TEXT NOT NULL,
|
||||||
|
number_of_objects INTEGER NOT NULL DEFAULT 1 CHECK (number_of_objects >= 1),
|
||||||
|
brief_description TEXT,
|
||||||
|
current_location TEXT,
|
||||||
|
current_owner TEXT,
|
||||||
|
recorder TEXT,
|
||||||
|
recording_date DATE,
|
||||||
|
visibility TEXT NOT NULL DEFAULT 'draft'
|
||||||
|
CHECK (visibility IN ('draft', 'internal', 'public')),
|
||||||
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||||
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX object_visibility_idx ON object (visibility);
|
||||||
@@ -19,6 +19,18 @@ async fn migrate_is_idempotent_and_creates_audit_log(pool: PgPool) {
|
|||||||
assert_eq!(regclass.as_deref(), Some("audit_log"));
|
assert_eq!(regclass.as_deref(), Some("audit_log"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[sqlx::test]
|
||||||
|
async fn migrate_creates_object_table(pool: PgPool) {
|
||||||
|
let db = Db::from_pool(pool);
|
||||||
|
|
||||||
|
let regclass: Option<String> = sqlx::query_scalar("SELECT to_regclass('public.object')::text")
|
||||||
|
.fetch_one(db.pool())
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(regclass.as_deref(), Some("object"));
|
||||||
|
}
|
||||||
|
|
||||||
#[sqlx::test]
|
#[sqlx::test]
|
||||||
async fn migrate_creates_vocabulary_and_authority_tables(pool: PgPool) {
|
async fn migrate_creates_vocabulary_and_authority_tables(pool: PgPool) {
|
||||||
let db = Db::from_pool(pool);
|
let db = Db::from_pool(pool);
|
||||||
|
|||||||
Reference in New Issue
Block a user