feat(supabase): animals and relations M3 with RPCs, history and caps
Species rows (8 + other), animals with the D6b birth model, relations with composite workspace keys, current/ended/voided states and a partial unique index; definer RPCs for animals and relations (one lock order, shared write budget, caps), invoker reads (search_animals, list_client_animals, client_archive_preview) and search_clients with current_animal_count. pgTAP 014 (254), parity test, sandbox suite, types from the isolated stack.
This commit is contained in:
1 parent
2dc04bcfba
commit
b54c8e5bd8
8 files changed
+3354
-11
No files matched your search
@@ -239,6 +239,149 @@ export type Database = {
|
||||
},
|
||||
]
|
||||
}
|
||||
animal_client_relations: {
|
||||
Row: {
|
||||
animal_id: string
|
||||
client_id: string
|
||||
create_request_digest: string
|
||||
create_request_id: string
|
||||
created_at: string
|
||||
ended_at: string | null
|
||||
ended_on: string | null
|
||||
id: string
|
||||
relation_role: Database['public']['Enums']['animal_relation_role']
|
||||
revision: number
|
||||
started_on: string | null
|
||||
updated_at: string
|
||||
voided_at: string | null
|
||||
workspace_id: string
|
||||
}
|
||||
ComputedFields: never
|
||||
Insert: {
|
||||
animal_id: string
|
||||
client_id: string
|
||||
create_request_digest: string
|
||||
create_request_id: string
|
||||
created_at?: string
|
||||
ended_at?: string | null
|
||||
ended_on?: string | null
|
||||
id?: string
|
||||
relation_role: Database['public']['Enums']['animal_relation_role']
|
||||
revision?: number
|
||||
started_on?: string | null
|
||||
updated_at?: string
|
||||
voided_at?: string | null
|
||||
workspace_id: string
|
||||
}
|
||||
Update: {
|
||||
animal_id?: string
|
||||
client_id?: string
|
||||
create_request_digest?: string
|
||||
create_request_id?: string
|
||||
created_at?: string
|
||||
ended_at?: string | null
|
||||
ended_on?: string | null
|
||||
id?: string
|
||||
relation_role?: Database['public']['Enums']['animal_relation_role']
|
||||
revision?: number
|
||||
started_on?: string | null
|
||||
updated_at?: string
|
||||
voided_at?: string | null
|
||||
workspace_id?: string
|
||||
}
|
||||
Relationships: [
|
||||
{
|
||||
foreignKeyName: 'animal_client_relations_animal_fk'
|
||||
columns: ['workspace_id', 'animal_id']
|
||||
isOneToOne: false
|
||||
referencedRelation: 'animals'
|
||||
referencedColumns: ['workspace_id', 'id']
|
||||
},
|
||||
{
|
||||
foreignKeyName: 'animal_client_relations_client_fk'
|
||||
columns: ['workspace_id', 'client_id']
|
||||
isOneToOne: false
|
||||
referencedRelation: 'clients'
|
||||
referencedColumns: ['workspace_id', 'id']
|
||||
},
|
||||
]
|
||||
}
|
||||
animals: {
|
||||
Row: {
|
||||
archived_at: string | null
|
||||
birth_date: string | null
|
||||
birth_year: number | null
|
||||
breed: string | null
|
||||
create_request_digest: string
|
||||
create_request_id: string
|
||||
created_at: string
|
||||
id: string
|
||||
name: string
|
||||
name_key: string | null
|
||||
revision: number
|
||||
search_key: string | null
|
||||
sex: Database['public']['Enums']['animal_sex']
|
||||
species_detail: string | null
|
||||
species_id: string
|
||||
updated_at: string
|
||||
workspace_id: string
|
||||
}
|
||||
ComputedFields: never
|
||||
Insert: {
|
||||
archived_at?: string | null
|
||||
birth_date?: string | null
|
||||
birth_year?: number | null
|
||||
breed?: string | null
|
||||
create_request_digest: string
|
||||
create_request_id: string
|
||||
created_at?: string
|
||||
id?: string
|
||||
name: string
|
||||
name_key?: never
|
||||
revision?: number
|
||||
search_key?: never
|
||||
sex: Database['public']['Enums']['animal_sex']
|
||||
species_detail?: string | null
|
||||
species_id: string
|
||||
updated_at?: string
|
||||
workspace_id: string
|
||||
}
|
||||
Update: {
|
||||
archived_at?: string | null
|
||||
birth_date?: string | null
|
||||
birth_year?: number | null
|
||||
breed?: string | null
|
||||
create_request_digest?: string
|
||||
create_request_id?: string
|
||||
created_at?: string
|
||||
id?: string
|
||||
name?: string
|
||||
name_key?: never
|
||||
revision?: number
|
||||
search_key?: never
|
||||
sex?: Database['public']['Enums']['animal_sex']
|
||||
species_detail?: string | null
|
||||
species_id?: string
|
||||
updated_at?: string
|
||||
workspace_id?: string
|
||||
}
|
||||
Relationships: [
|
||||
{
|
||||
foreignKeyName: 'animals_species_id_fkey'
|
||||
columns: ['species_id']
|
||||
isOneToOne: false
|
||||
referencedRelation: 'species'
|
||||
referencedColumns: ['id']
|
||||
},
|
||||
{
|
||||
foreignKeyName: 'animals_workspace_id_fkey'
|
||||
columns: ['workspace_id']
|
||||
isOneToOne: false
|
||||
referencedRelation: 'workspaces'
|
||||
referencedColumns: ['id']
|
||||
},
|
||||
]
|
||||
}
|
||||
assets: {
|
||||
Row: {
|
||||
attempts: number
|
||||
@@ -628,6 +771,7 @@ export type Database = {
|
||||
object_name: string
|
||||
}[]
|
||||
}
|
||||
client_archive_preview: { Args: { client_id: string }; Returns: Json }
|
||||
complete_avatar_job: {
|
||||
Args: {
|
||||
asset_id: string
|
||||
@@ -654,6 +798,33 @@ export type Database = {
|
||||
}
|
||||
Returns: string
|
||||
}
|
||||
create_animal: {
|
||||
Args: {
|
||||
birth_date?: string
|
||||
birth_year?: string
|
||||
breed?: string
|
||||
client_id?: string
|
||||
create_request_id: string
|
||||
name: string
|
||||
relation_role?: string
|
||||
sex: string
|
||||
species_detail?: string
|
||||
species_id: string
|
||||
started_on?: string
|
||||
workspace_id: string
|
||||
}
|
||||
Returns: Json
|
||||
}
|
||||
create_animal_client_relation: {
|
||||
Args: {
|
||||
animal_id: string
|
||||
client_id: string
|
||||
create_request_id: string
|
||||
relation_role: string
|
||||
started_on?: string
|
||||
}
|
||||
Returns: Json
|
||||
}
|
||||
create_client: {
|
||||
Args: {
|
||||
address_line1?: string
|
||||
@@ -685,6 +856,14 @@ export type Database = {
|
||||
Args: { reason?: string; version_id: string }
|
||||
Returns: string
|
||||
}
|
||||
end_animal_client_relation: {
|
||||
Args: {
|
||||
ended_on?: string
|
||||
expected_revision: number
|
||||
relation_id: string
|
||||
}
|
||||
Returns: Json
|
||||
}
|
||||
expire_pending_uploads: {
|
||||
Args: { max_age_seconds: number }
|
||||
Returns: number
|
||||
@@ -705,6 +884,31 @@ export type Database = {
|
||||
}
|
||||
Returns: string
|
||||
}
|
||||
list_client_animals: {
|
||||
Args: {
|
||||
after_id?: string
|
||||
after_sort?: string
|
||||
client_id: string
|
||||
page_size?: number
|
||||
}
|
||||
Returns: {
|
||||
animal_archived_at: string
|
||||
animal_id: string
|
||||
animal_name: string
|
||||
birth_year: number
|
||||
breed: string
|
||||
ended_on: string
|
||||
is_current: boolean
|
||||
relation_id: string
|
||||
relation_revision: number
|
||||
relation_role: Database['public']['Enums']['animal_relation_role']
|
||||
sex: Database['public']['Enums']['animal_sex']
|
||||
sort_key: string
|
||||
species_detail: string
|
||||
species_id: string
|
||||
started_on: string
|
||||
}[]
|
||||
}
|
||||
mark_quarantine_purged: { Args: { asset_id: string }; Returns: undefined }
|
||||
publish_sheet_version: { Args: { version_id: string }; Returns: string }
|
||||
register_sheet_asset: {
|
||||
@@ -730,6 +934,30 @@ export type Database = {
|
||||
}
|
||||
Returns: string
|
||||
}
|
||||
search_animals: {
|
||||
Args: {
|
||||
after_id?: string
|
||||
after_name_key?: string
|
||||
archived?: boolean
|
||||
page_size?: number
|
||||
query?: string
|
||||
species_filter?: string
|
||||
workspace_id: string
|
||||
}
|
||||
Returns: {
|
||||
archived_at: string
|
||||
birth_year: number
|
||||
breed: string
|
||||
current_owner_count: number
|
||||
current_owners: Json
|
||||
id: string
|
||||
name: string
|
||||
name_key: string
|
||||
sex: Database['public']['Enums']['animal_sex']
|
||||
species_detail: string
|
||||
species_id: string
|
||||
}[]
|
||||
}
|
||||
search_clients: {
|
||||
Args: {
|
||||
after_id?: string
|
||||
@@ -742,6 +970,7 @@ export type Database = {
|
||||
Returns: {
|
||||
archived_at: string
|
||||
city: string
|
||||
current_animal_count: number
|
||||
display_name: string
|
||||
email: string
|
||||
id: string
|
||||
@@ -750,6 +979,10 @@ export type Database = {
|
||||
phone: string
|
||||
}[]
|
||||
}
|
||||
set_animal_archived: {
|
||||
Args: { animal_id: string; archived: boolean }
|
||||
Returns: Json
|
||||
}
|
||||
set_client_archived: {
|
||||
Args: { archived: boolean; client_id: string }
|
||||
Returns: Json
|
||||
@@ -761,6 +994,29 @@ export type Database = {
|
||||
}
|
||||
Returns: string
|
||||
}
|
||||
update_animal: {
|
||||
Args: {
|
||||
animal_id: string
|
||||
birth_date: string
|
||||
birth_year: string
|
||||
breed: string
|
||||
expected_revision: number
|
||||
name: string
|
||||
sex: string
|
||||
species_detail: string
|
||||
species_id: string
|
||||
}
|
||||
Returns: Json
|
||||
}
|
||||
update_animal_client_relation: {
|
||||
Args: {
|
||||
ended_on: string
|
||||
expected_revision: number
|
||||
relation_id: string
|
||||
started_on: string
|
||||
}
|
||||
Returns: Json
|
||||
}
|
||||
update_client: {
|
||||
Args: {
|
||||
address_line1: string
|
||||
@@ -777,8 +1033,14 @@ export type Database = {
|
||||
}
|
||||
Returns: Json
|
||||
}
|
||||
void_animal_client_relation: {
|
||||
Args: { expected_revision: number; relation_id: string }
|
||||
Returns: Json
|
||||
}
|
||||
}
|
||||
Enums: {
|
||||
animal_relation_role: 'owner' | 'keeper' | 'contact'
|
||||
animal_sex: 'male' | 'female' | 'unknown'
|
||||
asset_status:
|
||||
| 'pending_upload'
|
||||
| 'uploaded'
|
||||
@@ -919,6 +1181,8 @@ export type CompositeTypes<
|
||||
export const Constants = {
|
||||
public: {
|
||||
Enums: {
|
||||
animal_relation_role: ['owner', 'keeper', 'contact'],
|
||||
animal_sex: ['male', 'female', 'unknown'],
|
||||
asset_status: [
|
||||
'pending_upload',
|
||||
'uploaded',
|
||||
|
||||
@@ -16,6 +16,20 @@ export const CLIENT_FIELD_LIMITS = {
|
||||
city: 80,
|
||||
} as const
|
||||
|
||||
export const ANIMAL_FIELD_LIMITS = {
|
||||
name: 80,
|
||||
breed: 80,
|
||||
speciesDetail: 80,
|
||||
} as const
|
||||
|
||||
/**
|
||||
* Lower bounds of the SQL CHECKs on birth years and on every record date
|
||||
* (birth, relation start and end). The upper bound is "not in the future":
|
||||
* the form checks the device's local date, the RPCs tomorrow's UTC date.
|
||||
*/
|
||||
export const BIRTH_YEAR_MIN = 1900
|
||||
export const RECORD_DATE_MIN = '1900-01-01'
|
||||
|
||||
/** U+0000 to U+001F, U+007F to U+009F, U+2028, U+2029 (the SQL literal starts at U+0001: text cannot hold U+0000). */
|
||||
export const CONTROL_CHARACTERS = /[\u0000-\u001F\u007F-\u009F\u2028\u2029]/u
|
||||
|
||||
|
||||
Reference in new issue
Block a user