54 lines
6.0 KiB
JavaScript
54 lines
6.0 KiB
JavaScript
// Schema-only fixture captured from the two additive migrations in disposable PostgreSQL.
|
|
export function aiModelRegistryEvidence() {
|
|
const column = (table_name, column_name, data_type, is_nullable = 'NO', column_default = null, udt_name = null) => ({ table_name, column_name, data_type, is_nullable, column_default, udt_name })
|
|
const provider = 'ai_model_providers', catalog = 'ai_model_catalog', config = 'ai_model_configuration', audit = 'ai_model_audit', verification = 'ai_model_verifications'
|
|
const unique = (tablename, indexname, columns, predicate = '') => ({ tablename, indexname, columns, predicate, indisunique: true, indisprimary: false, indisvalid: true, indisready: true, access_method: 'btree' })
|
|
const foreign = (tablename, name, referenced_table) => ({ tablename, constraint_name: `${tablename}_${name}_fkey`, contype: 'f', convalidated: true, delete_action: 'r', columns: [name], referenced_table, referenced_columns: ['id'] })
|
|
const check = (tablename, constraint_name, columns, expression) => ({ tablename, constraint_name, columns, expression, contype: 'c', convalidated: true })
|
|
return {
|
|
columns: [
|
|
...['id', 'name', 'base_url', 'credential_source'].map(name => column(provider, name, 'text')),
|
|
...['secret_ciphertext', 'secret_nonce', 'secret_auth_tag'].map(name => column(provider, name, 'text', 'YES')),
|
|
...['enabled', 'legacy_binding'].map(name => column(provider, name, 'boolean', 'NO', 'false')),
|
|
column(provider, 'revision', 'integer', 'NO', '1'), column(provider, 'synced_at', 'timestamp with time zone', 'YES'),
|
|
...['created_at', 'updated_at'].map(name => column(provider, name, 'timestamp with time zone', 'NO', 'now()')),
|
|
...['id', 'provider_id', 'model_id'].map(name => column(catalog, name, 'text')),
|
|
column(catalog, 'compatibility', 'text', 'NO', "'unconfirmed'::text"), column(catalog, 'stages', 'ARRAY', 'NO', 'ARRAY[]::text[]', '_text'),
|
|
column(catalog, 'capability_metadata', 'jsonb', 'YES'), column(catalog, 'enabled', 'boolean', 'NO', 'false'), column(catalog, 'present', 'boolean', 'NO', 'true'),
|
|
...['created_at', 'updated_at'].map(name => column(catalog, name, 'timestamp with time zone', 'NO', 'now()')),
|
|
column(config, 'id', 'text'), ...['default_analysis', 'default_copy', 'default_image'].map(name => column(config, name, 'text', 'YES')),
|
|
column(config, 'revision', 'integer', 'NO', '1'), column(config, 'updated_at', 'timestamp with time zone', 'NO', 'now()'),
|
|
...['id', 'actor_id', 'action'].map(name => column(audit, name, 'text')), column(audit, 'provider_id', 'text', 'YES'),
|
|
column(audit, 'details', 'jsonb', 'NO', "'{}'::jsonb"), column(audit, 'created_at', 'timestamp with time zone', 'NO', 'now()'),
|
|
...['id', 'model_key', 'stage', 'context_hash', 'idempotency_key', 'actor_id', 'status'].map(name => column(verification, name, 'text')),
|
|
...['request_id', 'task_id', 'message'].map(name => column(verification, name, 'text', 'YES')),
|
|
column(verification, 'evidence', 'jsonb', 'NO', "'{}'::jsonb"),
|
|
...['started_at', 'deadline_at'].map(name => column(verification, name, 'timestamp with time zone')),
|
|
column(verification, 'finished_at', 'timestamp with time zone', 'YES'),
|
|
],
|
|
indexes: [
|
|
unique(provider, 'ai_model_providers_legacy_binding_key', ['legacy_binding'], '(legacy_binding = true)'),
|
|
unique(catalog, 'ai_model_catalog_provider_model_key', ['provider_id', 'model_id']),
|
|
{ tablename: audit, indexname: 'ai_model_audit_created_idx', indexdef: 'CREATE INDEX ai_model_audit_created_idx ON public.ai_model_audit USING btree (created_at)' },
|
|
unique(verification, 'ai_model_verifications_idempotency_key', ['model_key', 'stage', 'idempotency_key']),
|
|
unique(verification, 'ai_model_verifications_unresolved_key', ['model_key', 'stage'], "status = ANY (ARRAY['running'::text, 'unknown'::text])"),
|
|
{ tablename: verification, indexname: 'ai_model_verifications_model_stage_idx', indexdef: 'CREATE INDEX ai_model_verifications_model_stage_idx ON public.ai_model_verifications USING btree (model_key, stage, started_at DESC)', indisvalid: true, indisready: true, indisunique: false, predicate: '' },
|
|
],
|
|
constraints: [
|
|
foreign(catalog, 'provider_id', provider), ...['default_analysis', 'default_copy', 'default_image'].map(name => foreign(config, name, catalog)),
|
|
foreign(verification, 'model_key', catalog),
|
|
check(provider, 'ai_model_providers_credential_source_check', ['credential_source'], "credential_source = ANY (ARRAY['environment'::text, 'encrypted'::text])"),
|
|
check(provider, 'ai_model_providers_revision_check', ['revision'], 'revision > 0'),
|
|
check(provider, 'ai_model_credential_complete', ['credential_source', 'secret_ciphertext', 'secret_nonce', 'secret_auth_tag'], "credential_source = 'environment'::text AND secret_ciphertext IS NULL AND secret_nonce IS NULL AND secret_auth_tag IS NULL OR credential_source = 'encrypted'::text AND secret_ciphertext IS NOT NULL AND secret_nonce IS NOT NULL AND secret_auth_tag IS NOT NULL"),
|
|
check(catalog, 'ai_model_catalog_stages_check', ['stages'], "stages <@ ARRAY['analysis'::text, 'copy'::text, 'image'::text]"),
|
|
check(catalog, 'ai_model_catalog_compatibility_check', ['compatibility'], "compatibility = ANY (ARRAY['confirmed'::text, 'unconfirmed'::text])"),
|
|
check(catalog, 'ai_model_enabled_stages', ['enabled', 'stages'], 'NOT enabled OR cardinality(stages) > 0'),
|
|
check(verification, 'ai_model_verifications_stage_check', ['stage'], "stage = ANY (ARRAY['analysis'::text, 'copy'::text, 'image'::text])"),
|
|
check(verification, 'ai_model_verifications_context_hash_check', ['context_hash'], "context_hash ~ '^[0-9a-f]{64}$'::text"),
|
|
check(verification, 'ai_model_verifications_status_check', ['status'], "status = ANY (ARRAY['running'::text, 'passed'::text, 'failed'::text, 'unknown'::text])"),
|
|
check(config, 'ai_model_configuration_id_check', ['id'], "id = 'detail-generator'::text"),
|
|
check(config, 'ai_model_configuration_revision_check', ['revision'], 'revision > 0'),
|
|
],
|
|
}
|
|
}
|