diff --git a/apps/backend/drizzle/0003_dry_starhawk.sql b/apps/backend/drizzle/0003_dry_starhawk.sql new file mode 100644 index 000000000..b1f37e0a7 --- /dev/null +++ b/apps/backend/drizzle/0003_dry_starhawk.sql @@ -0,0 +1 @@ +ALTER TABLE `undb_base` ADD `allow_template` integer DEFAULT false NOT NULL; \ No newline at end of file diff --git a/apps/backend/drizzle/meta/0003_snapshot.json b/apps/backend/drizzle/meta/0003_snapshot.json new file mode 100644 index 000000000..5d17ef1dc --- /dev/null +++ b/apps/backend/drizzle/meta/0003_snapshot.json @@ -0,0 +1,1804 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "cb669dfe-2cdd-465f-b584-9d98057ac6f9", + "prevId": "6f6c207c-336b-486f-8a37-c44c56a85fb6", + "tables": { + "undb_api_token": { + "name": "undb_api_token", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "space_id": { + "name": "space_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "undb_api_token_user_id_unique": { + "name": "undb_api_token_user_id_unique", + "columns": [ + "user_id" + ], + "isUnique": true + }, + "undb_api_token_token_unique": { + "name": "undb_api_token_token_unique", + "columns": [ + "token" + ], + "isUnique": true + }, + "api_token_space_id_idx": { + "name": "api_token_space_id_idx", + "columns": [ + "space_id" + ], + "isUnique": false + }, + "api_token_user_id_idx": { + "name": "api_token_user_id_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "undb_api_token_user_id_undb_user_id_fk": { + "name": "undb_api_token_user_id_undb_user_id_fk", + "tableFrom": "undb_api_token", + "tableTo": "undb_user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "undb_api_token_space_id_undb_space_id_fk": { + "name": "undb_api_token_space_id_undb_space_id_fk", + "tableFrom": "undb_api_token", + "tableTo": "undb_space", + "columnsFrom": [ + "space_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "undb_attachment_mapping": { + "name": "undb_attachment_mapping", + "columns": { + "attachment_id": { + "name": "attachment_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "table_id": { + "name": "table_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "record_id": { + "name": "record_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "field_id": { + "name": "field_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "undb_attachment_mapping_attachment_id_undb_attachment_id_fk": { + "name": "undb_attachment_mapping_attachment_id_undb_attachment_id_fk", + "tableFrom": "undb_attachment_mapping", + "tableTo": "undb_attachment", + "columnsFrom": [ + "attachment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "undb_attachment_mapping_table_id_undb_table_id_fk": { + "name": "undb_attachment_mapping_table_id_undb_table_id_fk", + "tableFrom": "undb_attachment_mapping", + "tableTo": "undb_table", + "columnsFrom": [ + "table_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "undb_attachment_mapping_attachment_id_table_id_record_id_field_id_pk": { + "columns": [ + "attachment_id", + "table_id", + "record_id", + "field_id" + ], + "name": "undb_attachment_mapping_attachment_id_table_id_record_id_field_id_pk" + } + }, + "uniqueConstraints": {} + }, + "undb_attachment": { + "name": "undb_attachment", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "size": { + "name": "size", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "mime_type": { + "name": "mime_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "space_id": { + "name": "space_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "attachment_size_idx": { + "name": "attachment_size_idx", + "columns": [ + "size" + ], + "isUnique": false + }, + "attachment_space_id_idx": { + "name": "attachment_space_id_idx", + "columns": [ + "space_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "undb_attachment_created_by_undb_user_id_fk": { + "name": "undb_attachment_created_by_undb_user_id_fk", + "tableFrom": "undb_attachment", + "tableTo": "undb_user", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "undb_attachment_space_id_undb_space_id_fk": { + "name": "undb_attachment_space_id_undb_space_id_fk", + "tableFrom": "undb_attachment", + "tableTo": "undb_space", + "columnsFrom": [ + "space_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "undb_audit": { + "name": "undb_audit", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "timestamp": { + "name": "timestamp", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "detail": { + "name": "detail", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "meta": { + "name": "meta", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "op": { + "name": "op", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "table_id": { + "name": "table_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "record_id": { + "name": "record_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "operator_id": { + "name": "operator_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "space_id": { + "name": "space_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "audit_table_id_idx": { + "name": "audit_table_id_idx", + "columns": [ + "table_id" + ], + "isUnique": false + }, + "audit_space_id_idx": { + "name": "audit_space_id_idx", + "columns": [ + "space_id" + ], + "isUnique": false + }, + "audit_record_id_idx": { + "name": "audit_record_id_idx", + "columns": [ + "record_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "undb_audit_space_id_undb_space_id_fk": { + "name": "undb_audit_space_id_undb_space_id_fk", + "tableFrom": "undb_audit", + "tableTo": "undb_space", + "columnsFrom": [ + "space_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "undb_base": { + "name": "undb_base", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "allow_template": { + "name": "allow_template", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "space_id": { + "name": "space_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(CURRENT_TIMESTAMP)" + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_by": { + "name": "updated_by", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "base_space_id_idx": { + "name": "base_space_id_idx", + "columns": [ + "space_id" + ], + "isUnique": false + }, + "base_name_unique_idx": { + "name": "base_name_unique_idx", + "columns": [ + "name", + "space_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "undb_base_space_id_undb_space_id_fk": { + "name": "undb_base_space_id_undb_space_id_fk", + "tableFrom": "undb_base", + "tableTo": "undb_space", + "columnsFrom": [ + "space_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "undb_base_created_by_undb_user_id_fk": { + "name": "undb_base_created_by_undb_user_id_fk", + "tableFrom": "undb_base", + "tableTo": "undb_user", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "undb_base_updated_by_undb_user_id_fk": { + "name": "undb_base_updated_by_undb_user_id_fk", + "tableFrom": "undb_base", + "tableTo": "undb_user", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "undb_email_verification_code": { + "name": "undb_email_verification_code", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "code": { + "name": "code", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "undb_email_verification_code_user_id_unique": { + "name": "undb_email_verification_code_user_id_unique", + "columns": [ + "user_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "undb_email_verification_code_user_id_undb_user_id_fk": { + "name": "undb_email_verification_code_user_id_undb_user_id_fk", + "tableFrom": "undb_email_verification_code", + "tableTo": "undb_user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "undb_invitation": { + "name": "undb_invitation", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "space_id": { + "name": "space_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "invited_at": { + "name": "invited_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "inviter_id": { + "name": "inviter_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "invitation_space_id_idx": { + "name": "invitation_space_id_idx", + "columns": [ + "space_id" + ], + "isUnique": false + }, + "invitation_unique_idx": { + "name": "invitation_unique_idx", + "columns": [ + "email", + "space_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "undb_invitation_space_id_undb_space_id_fk": { + "name": "undb_invitation_space_id_undb_space_id_fk", + "tableFrom": "undb_invitation", + "tableTo": "undb_space", + "columnsFrom": [ + "space_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "undb_invitation_inviter_id_undb_user_id_fk": { + "name": "undb_invitation_inviter_id_undb_user_id_fk", + "tableFrom": "undb_invitation", + "tableTo": "undb_user", + "columnsFrom": [ + "inviter_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "undb_oauth_account": { + "name": "undb_oauth_account", + "columns": { + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "provider_user_id": { + "name": "provider_user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "undb_oauth_account_user_id_undb_user_id_fk": { + "name": "undb_oauth_account_user_id_undb_user_id_fk", + "tableFrom": "undb_oauth_account", + "tableTo": "undb_user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "undb_oauth_account_provider_id_provider_user_id_pk": { + "columns": [ + "provider_id", + "provider_user_id" + ], + "name": "undb_oauth_account_provider_id_provider_user_id_pk" + } + }, + "uniqueConstraints": {} + }, + "undb_outbox": { + "name": "undb_outbox", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "payload": { + "name": "payload", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "meta": { + "name": "meta", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "timestamp": { + "name": "timestamp", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "operator_id": { + "name": "operator_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "space_id": { + "name": "space_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "outbox_space_id_idx": { + "name": "outbox_space_id_idx", + "columns": [ + "space_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "undb_outbox_space_id_undb_space_id_fk": { + "name": "undb_outbox_space_id_undb_space_id_fk", + "tableFrom": "undb_outbox", + "tableTo": "undb_space", + "columnsFrom": [ + "space_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "undb_password_reset_token": { + "name": "undb_password_reset_token", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "undb_password_reset_token_token_unique": { + "name": "undb_password_reset_token_token_unique", + "columns": [ + "token" + ], + "isUnique": true + }, + "password_reset_token_user_id_idx": { + "name": "password_reset_token_user_id_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "undb_password_reset_token_user_id_undb_user_id_fk": { + "name": "undb_password_reset_token_user_id_undb_user_id_fk", + "tableFrom": "undb_password_reset_token", + "tableTo": "undb_user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "undb_reference_id_mapping": { + "name": "undb_reference_id_mapping", + "columns": { + "field_id": { + "name": "field_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "table_id": { + "name": "table_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "symmetric_field_id": { + "name": "symmetric_field_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "foreign_table_id": { + "name": "foreign_table_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "reference_id_mapping_unique_idx": { + "name": "reference_id_mapping_unique_idx", + "columns": [ + "field_id", + "table_id", + "symmetric_field_id", + "foreign_table_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "undb_reference_id_mapping_table_id_undb_table_id_fk": { + "name": "undb_reference_id_mapping_table_id_undb_table_id_fk", + "tableFrom": "undb_reference_id_mapping", + "tableTo": "undb_table", + "columnsFrom": [ + "table_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "undb_reference_id_mapping_foreign_table_id_undb_table_id_fk": { + "name": "undb_reference_id_mapping_foreign_table_id_undb_table_id_fk", + "tableFrom": "undb_reference_id_mapping", + "tableTo": "undb_table", + "columnsFrom": [ + "foreign_table_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "undb_rollup_id_mapping": { + "name": "undb_rollup_id_mapping", + "columns": { + "field_id": { + "name": "field_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "table_id": { + "name": "table_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "rollup_id": { + "name": "rollup_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "rollup_table_id": { + "name": "rollup_table_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "undb_rollup_id_mapping_table_id_undb_table_id_fk": { + "name": "undb_rollup_id_mapping_table_id_undb_table_id_fk", + "tableFrom": "undb_rollup_id_mapping", + "tableTo": "undb_table", + "columnsFrom": [ + "table_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "undb_rollup_id_mapping_rollup_table_id_undb_table_id_fk": { + "name": "undb_rollup_id_mapping_rollup_table_id_undb_table_id_fk", + "tableFrom": "undb_rollup_id_mapping", + "tableTo": "undb_table", + "columnsFrom": [ + "rollup_table_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "undb_rollup_id_mapping_field_id_rollup_id_pk": { + "columns": [ + "field_id", + "rollup_id" + ], + "name": "undb_rollup_id_mapping_field_id_rollup_id_pk" + } + }, + "uniqueConstraints": {} + }, + "undb_session": { + "name": "undb_session", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "space_id": { + "name": "space_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "undb_session_user_id_undb_user_id_fk": { + "name": "undb_session_user_id_undb_user_id_fk", + "tableFrom": "undb_session", + "tableTo": "undb_user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "undb_session_space_id_undb_space_id_fk": { + "name": "undb_session_space_id_undb_space_id_fk", + "tableFrom": "undb_session", + "tableTo": "undb_space", + "columnsFrom": [ + "space_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "undb_share": { + "name": "undb_share", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "target_type": { + "name": "target_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "target_id": { + "name": "target_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "space_id": { + "name": "space_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "share_space_id_idx": { + "name": "share_space_id_idx", + "columns": [ + "space_id" + ], + "isUnique": false + }, + "share_unique_idx": { + "name": "share_unique_idx", + "columns": [ + "target_type", + "target_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "undb_share_space_id_undb_space_id_fk": { + "name": "undb_share_space_id_undb_space_id_fk", + "tableFrom": "undb_share", + "tableTo": "undb_space", + "columnsFrom": [ + "space_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "undb_space": { + "name": "undb_space", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "is_personal": { + "name": "is_personal", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "avatar": { + "name": "avatar", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(CURRENT_TIMESTAMP)" + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_by": { + "name": "updated_by", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "deleted_by": { + "name": "deleted_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "space_name_idx": { + "name": "space_name_idx", + "columns": [ + "name" + ], + "isUnique": false + } + }, + "foreignKeys": { + "undb_space_created_by_undb_user_id_fk": { + "name": "undb_space_created_by_undb_user_id_fk", + "tableFrom": "undb_space", + "tableTo": "undb_user", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "undb_space_updated_by_undb_user_id_fk": { + "name": "undb_space_updated_by_undb_user_id_fk", + "tableFrom": "undb_space", + "tableTo": "undb_user", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "undb_space_deleted_by_undb_user_id_fk": { + "name": "undb_space_deleted_by_undb_user_id_fk", + "tableFrom": "undb_space", + "tableTo": "undb_user", + "columnsFrom": [ + "deleted_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "undb_space_member": { + "name": "undb_space_member", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "space_id": { + "name": "space_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "space_member_unique_idx": { + "name": "space_member_unique_idx", + "columns": [ + "user_id", + "space_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "undb_space_member_user_id_undb_user_id_fk": { + "name": "undb_space_member_user_id_undb_user_id_fk", + "tableFrom": "undb_space_member", + "tableTo": "undb_user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "undb_space_member_space_id_undb_space_id_fk": { + "name": "undb_space_member_space_id_undb_space_id_fk", + "tableFrom": "undb_space_member", + "tableTo": "undb_space", + "columnsFrom": [ + "space_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "undb_table_id_mapping": { + "name": "undb_table_id_mapping", + "columns": { + "table_id": { + "name": "table_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "subject_id": { + "name": "subject_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "undb_table_id_mapping_table_id_undb_table_id_fk": { + "name": "undb_table_id_mapping_table_id_undb_table_id_fk", + "tableFrom": "undb_table_id_mapping", + "tableTo": "undb_table", + "columnsFrom": [ + "table_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "undb_table_id_mapping_table_id_subject_id_pk": { + "columns": [ + "table_id", + "subject_id" + ], + "name": "undb_table_id_mapping_table_id_subject_id_pk" + } + }, + "uniqueConstraints": {} + }, + "undb_table": { + "name": "undb_table", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "base_id": { + "name": "base_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "space_id": { + "name": "space_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "schema": { + "name": "schema", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "views": { + "name": "views", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "forms": { + "name": "forms", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "rls": { + "name": "rls", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(CURRENT_TIMESTAMP)" + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_by": { + "name": "updated_by", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "table_base_id_idx": { + "name": "table_base_id_idx", + "columns": [ + "base_id" + ], + "isUnique": false + }, + "table_space_id_idx": { + "name": "table_space_id_idx", + "columns": [ + "space_id" + ], + "isUnique": false + }, + "table_name_unique_idx": { + "name": "table_name_unique_idx", + "columns": [ + "name", + "base_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "undb_table_base_id_undb_base_id_fk": { + "name": "undb_table_base_id_undb_base_id_fk", + "tableFrom": "undb_table", + "tableTo": "undb_base", + "columnsFrom": [ + "base_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "undb_table_space_id_undb_space_id_fk": { + "name": "undb_table_space_id_undb_space_id_fk", + "tableFrom": "undb_table", + "tableTo": "undb_space", + "columnsFrom": [ + "space_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "undb_table_created_by_undb_user_id_fk": { + "name": "undb_table_created_by_undb_user_id_fk", + "tableFrom": "undb_table", + "tableTo": "undb_user", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "undb_table_updated_by_undb_user_id_fk": { + "name": "undb_table_updated_by_undb_user_id_fk", + "tableFrom": "undb_table", + "tableTo": "undb_user", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "undb_user": { + "name": "undb_user", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "email_verified": { + "name": "email_verified", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "avatar": { + "name": "avatar", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "undb_user_email_unique": { + "name": "undb_user_email_unique", + "columns": [ + "email" + ], + "isUnique": true + }, + "user_username_idx": { + "name": "user_username_idx", + "columns": [ + "username" + ], + "isUnique": false + }, + "user_email_idx": { + "name": "user_email_idx", + "columns": [ + "email" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "undb_webhook": { + "name": "undb_webhook", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "method": { + "name": "method", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "table_id": { + "name": "table_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "headers": { + "name": "headers", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "condition": { + "name": "condition", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "event": { + "name": "event", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "space_id": { + "name": "space_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "webhook_table_id_idx": { + "name": "webhook_table_id_idx", + "columns": [ + "table_id" + ], + "isUnique": false + }, + "webhook_space_id_idx": { + "name": "webhook_space_id_idx", + "columns": [ + "space_id" + ], + "isUnique": false + }, + "webhook_url_idx": { + "name": "webhook_url_idx", + "columns": [ + "url" + ], + "isUnique": false + } + }, + "foreignKeys": { + "undb_webhook_table_id_undb_table_id_fk": { + "name": "undb_webhook_table_id_undb_table_id_fk", + "tableFrom": "undb_webhook", + "tableTo": "undb_table", + "columnsFrom": [ + "table_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "undb_webhook_space_id_undb_space_id_fk": { + "name": "undb_webhook_space_id_undb_space_id_fk", + "tableFrom": "undb_webhook", + "tableTo": "undb_space", + "columnsFrom": [ + "space_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + } + }, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/apps/backend/drizzle/meta/_journal.json b/apps/backend/drizzle/meta/_journal.json index 9de325ad8..86776ecff 100644 --- a/apps/backend/drizzle/meta/_journal.json +++ b/apps/backend/drizzle/meta/_journal.json @@ -22,6 +22,13 @@ "when": 1723731591583, "tag": "0002_fixed_lockjaw", "breakpoints": true + }, + { + "idx": 3, + "version": "6", + "when": 1723898576164, + "tag": "0003_dry_starhawk", + "breakpoints": true } ] } \ No newline at end of file diff --git a/apps/frontend/schema.graphql b/apps/frontend/schema.graphql index 2bb73b79f..ff0c9b8a6 100644 --- a/apps/frontend/schema.graphql +++ b/apps/frontend/schema.graphql @@ -13,9 +13,14 @@ type Audit { type Base { id: ID! name: String! + option: BaseOption tables: [Table]! } +type BaseOption { + allowTemplate: Boolean +} + type Field { constraint: JSON defaultValue: JSON diff --git a/apps/frontend/src/lib/components/blocks/base/base-header.svelte b/apps/frontend/src/lib/components/blocks/base/base-header.svelte index 51d2c12bd..cd5c7c835 100644 --- a/apps/frontend/src/lib/components/blocks/base/base-header.svelte +++ b/apps/frontend/src/lib/components/blocks/base/base-header.svelte @@ -4,6 +4,7 @@ import { DUPLICATE_BASE_MODAL, UPDATE_BASE_MODAL, toggleModal } from "$lib/store/modal.store" import { HardDriveIcon, PencilIcon, ChevronDownIcon, CopyIcon } from "lucide-svelte" import DuplicateBase from "./duplicate-base.svelte" + import { SettingsIcon } from "lucide-svelte" export let base: GetBaseQuery$result["base"] @@ -11,14 +12,19 @@
{#if base} - -
- - {base.name} +
+ +
+ + {base.name} - -
-
+ +
+ + + + +
toggleModal(UPDATE_BASE_MODAL)}> diff --git a/apps/frontend/src/lib/components/blocks/base/base-setting.svelte b/apps/frontend/src/lib/components/blocks/base/base-setting.svelte new file mode 100644 index 000000000..62467c1a6 --- /dev/null +++ b/apps/frontend/src/lib/components/blocks/base/base-setting.svelte @@ -0,0 +1,69 @@ + + +
+
+
+ Base Setting +
+ + +
+ Allow Template + Allow users to create templates from base. +
+ +
+
+
+
+ + Submit +
+
diff --git a/apps/frontend/src/routes/(authed)/+layout.gql b/apps/frontend/src/routes/(authed)/+layout.gql index f006ff1bb..9078be3bd 100644 --- a/apps/frontend/src/routes/(authed)/+layout.gql +++ b/apps/frontend/src/routes/(authed)/+layout.gql @@ -17,8 +17,6 @@ query GetIndexQuery { type isDefault } - - recordsCount } bases { diff --git a/apps/frontend/src/routes/(authed)/bases/[baseId]/+layout.gql b/apps/frontend/src/routes/(authed)/bases/[baseId]/+layout.gql index 76ea3e406..b2033ee23 100644 --- a/apps/frontend/src/routes/(authed)/bases/[baseId]/+layout.gql +++ b/apps/frontend/src/routes/(authed)/bases/[baseId]/+layout.gql @@ -2,6 +2,9 @@ query GetBaseQuery($baseId: ID!) { base(id: $baseId) { id name + option { + allowTemplate + } tables { id diff --git a/apps/frontend/src/routes/(authed)/bases/[baseId]/+layout.svelte b/apps/frontend/src/routes/(authed)/bases/[baseId]/+layout.svelte new file mode 100644 index 000000000..c8a741c4a --- /dev/null +++ b/apps/frontend/src/routes/(authed)/bases/[baseId]/+layout.svelte @@ -0,0 +1,16 @@ + + +
+ {#if base} + + + {/if} +
diff --git a/apps/frontend/src/routes/(authed)/bases/[baseId]/+page.svelte b/apps/frontend/src/routes/(authed)/bases/[baseId]/+page.svelte index aff8fb7ea..6212d7016 100644 --- a/apps/frontend/src/routes/(authed)/bases/[baseId]/+page.svelte +++ b/apps/frontend/src/routes/(authed)/bases/[baseId]/+page.svelte @@ -1,19 +1,15 @@ -
- {#if base} - - - - {/if} -
+{#if base} + + +{/if} diff --git a/apps/frontend/src/routes/(authed)/bases/[baseId]/setting/+layout.svelte b/apps/frontend/src/routes/(authed)/bases/[baseId]/setting/+layout.svelte new file mode 100644 index 000000000..bd666ee19 --- /dev/null +++ b/apps/frontend/src/routes/(authed)/bases/[baseId]/setting/+layout.svelte @@ -0,0 +1,3 @@ +
+ +
diff --git a/apps/frontend/src/routes/(authed)/bases/[baseId]/setting/+page.svelte b/apps/frontend/src/routes/(authed)/bases/[baseId]/setting/+page.svelte new file mode 100644 index 000000000..dc5857270 --- /dev/null +++ b/apps/frontend/src/routes/(authed)/bases/[baseId]/setting/+page.svelte @@ -0,0 +1,13 @@ + + +{#if base} + +{/if} diff --git a/apps/frontend/src/routes/(authed)/t/[tableId]/+layout.gql b/apps/frontend/src/routes/(authed)/t/[tableId]/+layout.gql index 8f3d837d4..7c905eea3 100644 --- a/apps/frontend/src/routes/(authed)/t/[tableId]/+layout.gql +++ b/apps/frontend/src/routes/(authed)/t/[tableId]/+layout.gql @@ -62,7 +62,5 @@ query GetTableQuery($tableId: ID!, $viewId: ID) { condition updateCondition } - - recordsCount } } diff --git a/packages/base/src/base.factory.ts b/packages/base/src/base.factory.ts index c6cb65caa..354ce29b0 100644 --- a/packages/base/src/base.factory.ts +++ b/packages/base/src/base.factory.ts @@ -6,8 +6,10 @@ import { BaseCreatedEvent } from "./events/base-created.event.js" import type { IBaseSpecification } from "./interface.js" import { WithBaseId } from "./specifications/base-id.specification.js" import { WithBaseName } from "./specifications/base-name.specification.js" +import { WithBaseOption } from "./specifications/base-option.specification.js" import { WithBaseSpaceId } from "./specifications/base-space-id.specification.js" import { BaseId } from "./value-objects/base-id.vo.js" +import { BaseOption } from "./value-objects/base-option.js" export class BaseFactory { static new(...specs: IBaseSpecification[]): Base { @@ -18,7 +20,12 @@ export class BaseFactory { } static fromJSON(dto: IBaseDTO): Base { - return this.new(WithBaseId.fromString(dto.id), WithBaseName.fromString(dto.name), new WithBaseSpaceId(dto.spaceId)) + return this.new( + WithBaseId.fromString(dto.id), + WithBaseName.fromString(dto.name), + new WithBaseSpaceId(dto.spaceId), + new WithBaseOption(new BaseOption({ allowTemplate: dto.option?.allowTemplate })), + ) } static create(input: ICreateBaseDTO): Base { diff --git a/packages/base/src/base.ts b/packages/base/src/base.ts index 115555413..a2ed46d34 100644 --- a/packages/base/src/base.ts +++ b/packages/base/src/base.ts @@ -9,13 +9,15 @@ import type { IUpdateBaseDTO } from "./dto/update-base.dto.js" import { BaseUpdatedEvent } from "./events/base-updated.event.js" import type { IBaseSpecification } from "./interface.js" import { WithBaseName } from "./specifications/base-name.specification.js" +import { WithBaseOption } from "./specifications/base-option.specification.js" import { DuplicatedBaseSpecification } from "./specifications/base.specification.js" -import { BaseId, type BaseName } from "./value-objects/index.js" +import { BaseId, BaseOption, type BaseName } from "./value-objects/index.js" export class Base extends AggregateRoot { id!: BaseId name!: BaseName spaceId!: ISpaceId + option: BaseOption = new BaseOption({ allowTemplate: false }) static empty() { return new Base() @@ -29,6 +31,10 @@ export class Base extends AggregateRoot { specs.push(WithBaseName.fromString(schema.name)) } + if (typeof schema.allowTemplate === "boolean") { + specs.push(new WithBaseOption(new BaseOption({ allowTemplate: schema.allowTemplate }))) + } + const spec = and(...specs) if (spec.isSome()) { spec.unwrap().mutate(this) @@ -43,6 +49,7 @@ export class Base extends AggregateRoot { public $duplicate(dto: IDuplicateBaseDTO, baseNames: string[]): DuplicatedBaseSpecification { const duplicatedBase = BaseFactory.fromJSON({ ...this.toJSON(), + option: { ...this.option?.toJSON(), allowTemplate: false }, id: BaseId.create().value, spaceId: dto.spaceId ?? this.spaceId, name: dto.name ?? getNextName(baseNames, this.name.value), @@ -56,6 +63,7 @@ export class Base extends AggregateRoot { id: this.id.value, spaceId: this.spaceId, name: this.name.value, + option: this.option?.toJSON(), } } } diff --git a/packages/base/src/dto/base.dto.ts b/packages/base/src/dto/base.dto.ts index 646baae68..9183fa376 100644 --- a/packages/base/src/dto/base.dto.ts +++ b/packages/base/src/dto/base.dto.ts @@ -1,11 +1,12 @@ import { spaceIdSchema } from "@undb/space" import { z } from "@undb/zod" -import { baseIdSchema, baseNameSchema } from "../value-objects" +import { baseIdSchema, baseNameSchema, baseOptionSchema } from "../value-objects" export const baseDTO = z.object({ id: baseIdSchema, name: baseNameSchema, spaceId: spaceIdSchema, + option: baseOptionSchema.optional(), }) export type IBaseDTO = z.infer diff --git a/packages/base/src/dto/update-base.dto.ts b/packages/base/src/dto/update-base.dto.ts index 74dd4ed4a..c46028897 100644 --- a/packages/base/src/dto/update-base.dto.ts +++ b/packages/base/src/dto/update-base.dto.ts @@ -3,7 +3,8 @@ import { baseIdSchema, baseNameSchema } from "../value-objects" export const updateBaseDTO = z.object({ id: baseIdSchema, - name: baseNameSchema, + name: baseNameSchema.optional(), + allowTemplate: z.boolean().optional(), }) export type IUpdateBaseDTO = z.infer diff --git a/packages/base/src/interface.ts b/packages/base/src/interface.ts index 0099291ab..b10b203ae 100644 --- a/packages/base/src/interface.ts +++ b/packages/base/src/interface.ts @@ -2,12 +2,14 @@ import type { CompositeSpecification, ISpecVisitor } from "@undb/domain" import type { Base } from "./base.js" import type { WithBaseId } from "./specifications/base-id.specification.js" import type { WithBaseName } from "./specifications/base-name.specification.js" +import type { WithBaseOption } from "./specifications/base-option.specification.js" import type { WithBaseQ } from "./specifications/base-q.specification.js" import type { WithBaseSpaceId } from "./specifications/base-space-id.specification.js" import type { DuplicatedBaseSpecification } from "./specifications/base.specification.js" export interface IBaseSpecVisitor extends ISpecVisitor { withId(v: WithBaseId): void + withOption(v: WithBaseOption): void withBaseSpaceId(v: WithBaseSpaceId): void duplicatedBase(v: DuplicatedBaseSpecification): void withName(v: WithBaseName): void diff --git a/packages/base/src/specifications/base-option.specification.ts b/packages/base/src/specifications/base-option.specification.ts new file mode 100644 index 000000000..d98005a7d --- /dev/null +++ b/packages/base/src/specifications/base-option.specification.ts @@ -0,0 +1,21 @@ +import { CompositeSpecification, Ok, Result } from "@undb/domain" +import type { Base } from "../base.js" +import type { IBaseSpecVisitor } from "../interface.js" +import { BaseOption } from "../value-objects/base-option.js" + +export class WithBaseOption extends CompositeSpecification { + constructor(public readonly option: BaseOption) { + super() + } + isSatisfiedBy(t: Base): boolean { + return this.option.equals(t.option) + } + mutate(t: Base): Result { + t.option = this.option + return Ok(t) + } + accept(v: IBaseSpecVisitor): Result { + v.withOption(this) + return Ok(undefined) + } +} diff --git a/packages/base/src/value-objects/base-option.ts b/packages/base/src/value-objects/base-option.ts new file mode 100644 index 000000000..8059b5bc6 --- /dev/null +++ b/packages/base/src/value-objects/base-option.ts @@ -0,0 +1,23 @@ +import { ValueObject } from "@undb/domain" +import { z } from "@undb/zod" + +export const baseOptionSchema = z.object({ + allowTemplate: z.boolean().optional(), +}) + +export type IBaseOption = z.infer + +export class BaseOption extends ValueObject { + public readonly allowTemplate: boolean + + constructor(props: IBaseOption) { + super(props) + this.allowTemplate = props.allowTemplate ?? false + } + + toJSON() { + return { + allowTemplate: this.allowTemplate, + } + } +} diff --git a/packages/base/src/value-objects/index.ts b/packages/base/src/value-objects/index.ts index 8420b0e1f..98d09c069 100644 --- a/packages/base/src/value-objects/index.ts +++ b/packages/base/src/value-objects/index.ts @@ -1,2 +1,3 @@ export * from "./base-id.vo.js" export * from "./base-name.vo.js" +export * from "./base-option.js" diff --git a/packages/command-handlers/src/handlers/create-from-template.command-handler.ts b/packages/command-handlers/src/handlers/create-from-template.command-handler.ts index 3ce212145..f64beba6f 100644 --- a/packages/command-handlers/src/handlers/create-from-template.command-handler.ts +++ b/packages/command-handlers/src/handlers/create-from-template.command-handler.ts @@ -23,6 +23,10 @@ export class CreateFromTemplateCommandHandler implements ICommandHandler export class UpdateBaseCommand extends Command implements IUpdateBaseCommand { public readonly id: string - public readonly name: string + public readonly name?: string + public readonly allowTemplate?: boolean constructor(props: CommandProps) { super(props) this.id = props.id this.name = props.name + this.allowTemplate = props.allowTemplate } } diff --git a/packages/graphql/src/index.ts b/packages/graphql/src/index.ts index c40c88cfb..93c063c55 100644 --- a/packages/graphql/src/index.ts +++ b/packages/graphql/src/index.ts @@ -228,9 +228,14 @@ export class Graphql { user: User! } + type BaseOption { + allowTemplate: Boolean + } + type Base { id: ID! name: String! + option: BaseOption tables: [Table]! } diff --git a/packages/persistence/src/base/base.filter-visitor.ts b/packages/persistence/src/base/base.filter-visitor.ts index 8d05f3609..b10f4b2b7 100644 --- a/packages/persistence/src/base/base.filter-visitor.ts +++ b/packages/persistence/src/base/base.filter-visitor.ts @@ -1,4 +1,5 @@ import type { Base, IBaseSpecVisitor, WithBaseId, WithBaseName, WithBaseQ, WithBaseSpaceId } from "@undb/base" +import type { WithBaseOption } from "@undb/base/src/specifications/base-option.specification" import type { DuplicatedBaseSpecification } from "@undb/base/src/specifications/base.specification" import { mustGetCurrentSpaceId } from "@undb/context/server" import type { ExpressionBuilder } from "kysely" @@ -12,6 +13,9 @@ export class BaseFilterVisitor extends AbstractQBVisitor implements IBaseS this.addCond(this.eb.eb("space_id", "=", spaceId)) } + withOption(v: WithBaseOption): void { + throw new Error("Not implemented") + } duplicatedBase(v: DuplicatedBaseSpecification): void { throw new Error("Not implemented") } diff --git a/packages/persistence/src/base/base.mapper.ts b/packages/persistence/src/base/base.mapper.ts index 24e4c787a..0bb51d5ef 100644 --- a/packages/persistence/src/base/base.mapper.ts +++ b/packages/persistence/src/base/base.mapper.ts @@ -10,6 +10,9 @@ export class BaseMapper implements Mapper { id: entity.id, name: entity.name, spaceId: entity.space_id, + option: { + allowTemplate: entity.allow_template, + }, }) } toEntity(domain: BaseDo): Base { @@ -17,6 +20,7 @@ export class BaseMapper implements Mapper { id: domain.id.value, space_id: domain.spaceId, name: domain.name.value, + allow_template: domain.option.allowTemplate, } } toDTO(entity: Base): IBaseDTO { @@ -24,6 +28,9 @@ export class BaseMapper implements Mapper { id: entity.id, spaceId: entity.space_id, name: entity.name, + option: { + allowTemplate: entity.allow_template, + }, } } } diff --git a/packages/persistence/src/base/base.mutate-visitor.ts b/packages/persistence/src/base/base.mutate-visitor.ts index e342db6d1..9d8c096f4 100644 --- a/packages/persistence/src/base/base.mutate-visitor.ts +++ b/packages/persistence/src/base/base.mutate-visitor.ts @@ -1,8 +1,12 @@ import type { IBaseSpecVisitor, WithBaseId, WithBaseName, WithBaseQ, WithBaseSpaceId } from "@undb/base" +import type { WithBaseOption } from "@undb/base/src/specifications/base-option.specification" import type { DuplicatedBaseSpecification } from "@undb/base/src/specifications/base.specification" import { AbstractQBMutationVisitor } from "../abstract-qb.visitor" export class BaseMutateVisitor extends AbstractQBMutationVisitor implements IBaseSpecVisitor { + withOption(v: WithBaseOption): void { + this.setData("allow_template", v.option.allowTemplate) + } duplicatedBase(v: DuplicatedBaseSpecification): void { throw new Error("Method not implemented.") } diff --git a/packages/persistence/src/tables.ts b/packages/persistence/src/tables.ts index 5e83cd87e..70689fd51 100644 --- a/packages/persistence/src/tables.ts +++ b/packages/persistence/src/tables.ts @@ -345,6 +345,7 @@ export const baseTable = sqliteTable( { id: text("id").notNull().primaryKey(), name: text("name").notNull(), + allowTemplate: integer("allow_template", { mode: "boolean" }).notNull().default(false), spaceId: text("space_id") .references(() => space.id) .notNull(),