Initial Commit
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
-- @suaveplan/api-plugin-import — SurrealDB schema
|
||||
--
|
||||
-- Backing table for `SurrealImportStore` (an `ImportStoreAdapter`
|
||||
-- implementation that ships alongside `MemoryImportStore`). The host
|
||||
-- application is responsible for applying this migration — either via
|
||||
-- `@suaveplan/api-plugin-database`'s migration runner pointed at this
|
||||
-- file, or by reading the file and calling `adapter.query(surql)` in
|
||||
-- `beforeAll`. The `SurrealImportStore` itself does not apply
|
||||
-- migrations.
|
||||
--
|
||||
-- Columns are snake_case to match the convention established by the
|
||||
-- shipped `event.surql` schema (`packages/api/api-plugin-events/surql/`).
|
||||
-- The mapping between snake_case columns and the camelCase
|
||||
-- `ImportJobRecord` shape is fully encapsulated inside the store.
|
||||
|
||||
DEFINE TABLE OVERWRITE import_job SCHEMAFULL;
|
||||
|
||||
DEFINE FIELD OVERWRITE owner_id ON import_job TYPE string
|
||||
ASSERT $value != NONE AND string::len(string::trim($value)) > 0;
|
||||
|
||||
DEFINE FIELD OVERWRITE status ON import_job TYPE string
|
||||
ASSERT $value INSIDE ['created', 'validating', 'importing', 'completed', 'failed']
|
||||
DEFAULT 'created';
|
||||
|
||||
DEFINE FIELD OVERWRITE total_rows ON import_job TYPE int
|
||||
ASSERT $value != NONE AND $value >= 0 DEFAULT 0;
|
||||
DEFINE FIELD OVERWRITE processed_rows ON import_job TYPE int
|
||||
ASSERT $value != NONE AND $value >= 0 DEFAULT 0;
|
||||
DEFINE FIELD OVERWRITE success_count ON import_job TYPE int
|
||||
ASSERT $value != NONE AND $value >= 0 DEFAULT 0;
|
||||
DEFINE FIELD OVERWRITE error_count ON import_job TYPE int
|
||||
ASSERT $value != NONE AND $value >= 0 DEFAULT 0;
|
||||
|
||||
DEFINE FIELD OVERWRITE errors ON import_job TYPE array DEFAULT [];
|
||||
DEFINE FIELD OVERWRITE errors.* ON import_job TYPE object;
|
||||
DEFINE FIELD OVERWRITE errors.*.row ON import_job TYPE int;
|
||||
DEFINE FIELD OVERWRITE errors.*.message ON import_job TYPE string;
|
||||
|
||||
DEFINE FIELD OVERWRITE metadata ON import_job TYPE option<object>;
|
||||
|
||||
DEFINE FIELD OVERWRITE created_at ON import_job TYPE datetime
|
||||
ASSERT $value != NONE;
|
||||
DEFINE FIELD OVERWRITE updated_at ON import_job TYPE datetime
|
||||
ASSERT $value != NONE;
|
||||
DEFINE FIELD OVERWRITE completed_at ON import_job TYPE option<datetime>;
|
||||
|
||||
-- Owner-scoped lookup index (used by `list({ ownerId })`).
|
||||
DEFINE INDEX OVERWRITE import_job_owner_idx ON import_job FIELDS owner_id;
|
||||
-- Status-filter index (used by `list({ status })`).
|
||||
DEFINE INDEX OVERWRITE import_job_status_idx ON import_job FIELDS status;
|
||||
-- Created-at ordering index (LIST ORDER BY created_at DESC).
|
||||
DEFINE INDEX OVERWRITE import_job_created_idx ON import_job FIELDS created_at;
|
||||
Reference in New Issue
Block a user