packages/db-main-prisma/prisma/sqlite/migrations/20240308114656_initial_database/migration.sql
-- CreateTable
CREATE TABLE "space" (
"id" TEXT NOT NULL PRIMARY KEY,
"name" TEXT NOT NULL,
"deleted_time" DATETIME,
"created_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"created_by" TEXT NOT NULL,
"last_modified_by" TEXT,
"last_modified_time" DATETIME
);
-- CreateTable
CREATE TABLE "base" (
"id" TEXT NOT NULL PRIMARY KEY,
"space_id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"order" REAL NOT NULL,
"icon" TEXT,
"schema_pass" TEXT,
"deleted_time" DATETIME,
"created_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"created_by" TEXT NOT NULL,
"last_modified_by" TEXT,
"last_modified_time" DATETIME,
CONSTRAINT "base_space_id_fkey" FOREIGN KEY ("space_id") REFERENCES "space" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
-- CreateTable
CREATE TABLE "table_meta" (
"id" TEXT NOT NULL PRIMARY KEY,
"base_id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"description" TEXT,
"icon" TEXT,
"db_table_name" TEXT NOT NULL,
"version" INTEGER NOT NULL,
"order" REAL NOT NULL,
"created_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"last_modified_time" DATETIME,
"deleted_time" DATETIME,
"created_by" TEXT NOT NULL,
"last_modified_by" TEXT,
CONSTRAINT "table_meta_base_id_fkey" FOREIGN KEY ("base_id") REFERENCES "base" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
-- CreateTable
CREATE TABLE "field" (
"id" TEXT NOT NULL PRIMARY KEY,
"name" TEXT NOT NULL,
"description" TEXT,
"options" TEXT,
"type" TEXT NOT NULL,
"cell_value_type" TEXT NOT NULL,
"is_multiple_cell_value" BOOLEAN,
"db_field_type" TEXT NOT NULL,
"db_field_name" TEXT NOT NULL,
"not_null" BOOLEAN,
"unique" BOOLEAN,
"is_primary" BOOLEAN,
"is_computed" BOOLEAN,
"is_lookup" BOOLEAN,
"is_pending" BOOLEAN,
"has_error" BOOLEAN,
"lookup_linked_field_id" TEXT,
"lookup_options" TEXT,
"table_id" TEXT NOT NULL,
"version" INTEGER NOT NULL,
"created_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"last_modified_time" DATETIME,
"deleted_time" DATETIME,
"created_by" TEXT NOT NULL,
"last_modified_by" TEXT,
CONSTRAINT "field_table_id_fkey" FOREIGN KEY ("table_id") REFERENCES "table_meta" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
-- CreateTable
CREATE TABLE "view" (
"id" TEXT NOT NULL PRIMARY KEY,
"name" TEXT NOT NULL,
"description" TEXT,
"table_id" TEXT NOT NULL,
"type" TEXT NOT NULL,
"sort" TEXT,
"filter" TEXT,
"group" TEXT,
"options" TEXT,
"order" REAL NOT NULL,
"version" INTEGER NOT NULL,
"column_meta" TEXT NOT NULL,
"enable_share" BOOLEAN,
"share_id" TEXT,
"share_meta" TEXT,
"created_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"last_modified_time" DATETIME,
"deleted_time" DATETIME,
"created_by" TEXT NOT NULL,
"last_modified_by" TEXT,
CONSTRAINT "view_table_id_fkey" FOREIGN KEY ("table_id") REFERENCES "table_meta" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
-- CreateTable
CREATE TABLE "ops" (
"collection" TEXT NOT NULL,
"doc_id" TEXT NOT NULL,
"doc_type" TEXT NOT NULL,
"version" INTEGER NOT NULL,
"operation" TEXT NOT NULL,
"created_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"created_by" TEXT NOT NULL
);
-- CreateTable
CREATE TABLE "snapshots" (
"collection" TEXT NOT NULL,
"doc_id" TEXT NOT NULL,
"doc_type" TEXT NOT NULL,
"version" INTEGER NOT NULL,
"data" TEXT NOT NULL
);
-- CreateTable
CREATE TABLE "reference" (
"id" TEXT NOT NULL PRIMARY KEY,
"from_field_id" TEXT NOT NULL,
"to_field_id" TEXT NOT NULL,
"created_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- CreateTable
CREATE TABLE "users" (
"id" TEXT NOT NULL PRIMARY KEY,
"name" TEXT NOT NULL,
"password" TEXT,
"salt" TEXT,
"phone" TEXT,
"email" TEXT NOT NULL,
"avatar" TEXT,
"notify_meta" TEXT,
"last_sign_time" DATETIME,
"created_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"deleted_time" DATETIME,
"last_modified_time" DATETIME
);
-- CreateTable
CREATE TABLE "account" (
"id" TEXT NOT NULL PRIMARY KEY,
"user_id" TEXT NOT NULL,
"type" TEXT NOT NULL,
"provider" TEXT NOT NULL,
"provider_id" TEXT NOT NULL,
"created_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "account_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
-- CreateTable
CREATE TABLE "attachments" (
"id" TEXT NOT NULL PRIMARY KEY,
"bucket" TEXT NOT NULL,
"token" TEXT NOT NULL,
"hash" TEXT NOT NULL,
"size" INTEGER NOT NULL,
"mimetype" TEXT NOT NULL,
"path" TEXT NOT NULL,
"width" INTEGER,
"height" INTEGER,
"deleted_time" DATETIME,
"created_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"created_by" TEXT NOT NULL,
"last_modified_by" TEXT
);
-- CreateTable
CREATE TABLE "attachments_table" (
"id" TEXT NOT NULL PRIMARY KEY,
"attachment_id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"token" TEXT NOT NULL,
"table_id" TEXT NOT NULL,
"record_id" TEXT NOT NULL,
"field_id" TEXT NOT NULL,
"created_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"created_by" TEXT NOT NULL,
"last_modified_by" TEXT,
"last_modified_time" DATETIME
);
-- CreateTable
CREATE TABLE "automation_workflow" (
"id" TEXT NOT NULL PRIMARY KEY,
"workflow_id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"description" TEXT,
"deployment_status" TEXT NOT NULL DEFAULT 'undeployed',
"created_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"last_modified_time" DATETIME,
"deleted_time" DATETIME,
"created_by" TEXT NOT NULL,
"last_modified_by" TEXT
);
-- CreateTable
CREATE TABLE "automation_workflow_trigger" (
"id" TEXT NOT NULL PRIMARY KEY,
"trigger_id" TEXT NOT NULL,
"workflow_id" TEXT NOT NULL,
"description" TEXT,
"trigger_type" TEXT,
"input_expressions" TEXT,
"created_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"last_modified_time" DATETIME,
"deleted_time" DATETIME,
"created_by" TEXT NOT NULL,
"last_modified_by" TEXT
);
-- CreateTable
CREATE TABLE "automation_workflow_action" (
"id" TEXT NOT NULL PRIMARY KEY,
"action_id" TEXT NOT NULL,
"workflow_id" TEXT NOT NULL,
"description" TEXT,
"action_type" TEXT,
"input_expressions" TEXT,
"next_node_id" TEXT,
"parent_node_id" TEXT,
"created_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"last_modified_time" DATETIME,
"deleted_time" DATETIME,
"created_by" TEXT NOT NULL,
"last_modified_by" TEXT
);
-- CreateTable
CREATE TABLE "automation_workflow_execution_history" (
"id" TEXT NOT NULL PRIMARY KEY,
"workflow_id" TEXT NOT NULL,
"execution_type" TEXT NOT NULL,
"execution_result" TEXT NOT NULL,
"created_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- CreateTable
CREATE TABLE "collaborator" (
"id" TEXT NOT NULL PRIMARY KEY,
"role_name" TEXT NOT NULL,
"base_id" TEXT,
"space_id" TEXT,
"user_id" TEXT NOT NULL,
"deleted_time" DATETIME,
"created_by" TEXT NOT NULL,
"created_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"last_modified_time" DATETIME,
"last_modified_by" TEXT
);
-- CreateTable
CREATE TABLE "invitation" (
"id" TEXT NOT NULL PRIMARY KEY,
"base_id" TEXT,
"space_id" TEXT,
"type" TEXT NOT NULL,
"role" TEXT NOT NULL,
"invitation_code" TEXT NOT NULL,
"expired_time" DATETIME,
"create_by" TEXT NOT NULL,
"created_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"last_modified_time" DATETIME,
"last_modified_by" TEXT,
"deleted_time" DATETIME
);
-- CreateTable
CREATE TABLE "invitation_record" (
"id" TEXT NOT NULL PRIMARY KEY,
"invitation_id" TEXT NOT NULL,
"base_id" TEXT,
"space_id" TEXT,
"type" TEXT NOT NULL,
"inviter" TEXT NOT NULL,
"accepter" TEXT NOT NULL,
"created_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- CreateTable
CREATE TABLE "notification" (
"id" TEXT NOT NULL PRIMARY KEY,
"from_user" TEXT,
"to_user" TEXT,
"from_user_id" TEXT NOT NULL,
"to_user_id" TEXT NOT NULL,
"type" TEXT NOT NULL,
"message" TEXT NOT NULL,
"url_meta" TEXT,
"is_read" BOOLEAN NOT NULL DEFAULT false,
"created_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"created_by" TEXT NOT NULL
);
-- CreateTable
CREATE TABLE "access_token" (
"id" TEXT NOT NULL PRIMARY KEY,
"name" TEXT NOT NULL,
"description" TEXT,
"user_id" TEXT NOT NULL,
"scopes" TEXT NOT NULL,
"space_ids" TEXT,
"base_ids" TEXT,
"sign" TEXT NOT NULL,
"expired_time" DATETIME NOT NULL,
"last_used_time" DATETIME,
"created_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"last_modified_time" DATETIME
);
-- CreateIndex
CREATE INDEX "base_order_idx" ON "base"("order");
-- CreateIndex
CREATE INDEX "table_meta_order_idx" ON "table_meta"("order");
-- CreateIndex
CREATE INDEX "field_lookup_linked_field_id_idx" ON "field"("lookup_linked_field_id");
-- CreateIndex
CREATE INDEX "view_order_idx" ON "view"("order");
-- CreateIndex
CREATE INDEX "ops_collection_created_time_idx" ON "ops"("collection", "created_time");
-- CreateIndex
CREATE UNIQUE INDEX "ops_collection_doc_id_version_key" ON "ops"("collection", "doc_id", "version");
-- CreateIndex
CREATE UNIQUE INDEX "snapshots_collection_doc_id_key" ON "snapshots"("collection", "doc_id");
-- CreateIndex
CREATE INDEX "reference_from_field_id_idx" ON "reference"("from_field_id");
-- CreateIndex
CREATE INDEX "reference_to_field_id_idx" ON "reference"("to_field_id");
-- CreateIndex
CREATE UNIQUE INDEX "reference_to_field_id_from_field_id_key" ON "reference"("to_field_id", "from_field_id");
-- CreateIndex
CREATE UNIQUE INDEX "users_phone_key" ON "users"("phone");
-- CreateIndex
CREATE UNIQUE INDEX "users_email_key" ON "users"("email");
-- CreateIndex
CREATE UNIQUE INDEX "account_provider_provider_id_key" ON "account"("provider", "provider_id");
-- CreateIndex
CREATE UNIQUE INDEX "attachments_token_key" ON "attachments"("token");
-- CreateIndex
CREATE UNIQUE INDEX "automation_workflow_workflow_id_key" ON "automation_workflow"("workflow_id");
-- CreateIndex
CREATE UNIQUE INDEX "automation_workflow_trigger_trigger_id_key" ON "automation_workflow_trigger"("trigger_id");
-- CreateIndex
CREATE INDEX "automation_workflow_trigger_workflow_id_idx" ON "automation_workflow_trigger"("workflow_id");
-- CreateIndex
CREATE UNIQUE INDEX "automation_workflow_action_action_id_key" ON "automation_workflow_action"("action_id");
-- CreateIndex
CREATE INDEX "automation_workflow_action_workflow_id_idx" ON "automation_workflow_action"("workflow_id");
-- CreateIndex
CREATE INDEX "automation_workflow_execution_history_workflow_id_idx" ON "automation_workflow_execution_history"("workflow_id");
-- CreateIndex
CREATE INDEX "notification_to_user_id_is_read_created_time_idx" ON "notification"("to_user_id", "is_read", "created_time");