mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-24 23:58:23 +00:00
48 lines
1.9 KiB
SQL
48 lines
1.9 KiB
SQL
-- snippets 0001: adopt_snippets_tables
|
|
-- Generated by termix-plugin migrations. Review before committing.
|
|
|
|
CREATE TABLE IF NOT EXISTS "snippets" (
|
|
"id" integer PRIMARY KEY AUTOINCREMENT,
|
|
"user_id" text NOT NULL,
|
|
"name" text NOT NULL,
|
|
"content" text NOT NULL,
|
|
"description" text,
|
|
"folder" text,
|
|
"order" integer NOT NULL DEFAULT 0,
|
|
"sync_id" text UNIQUE,
|
|
"created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
"updated_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
"host_filter" text,
|
|
"is_note" integer NOT NULL DEFAULT 0,
|
|
FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE
|
|
);
|
|
CREATE INDEX IF NOT EXISTS "idx_snippets_user_id" ON "snippets" ("user_id");
|
|
ALTER TABLE "snippets" RENAME TO "p_snippets_snippets";
|
|
CREATE TABLE IF NOT EXISTS "snippet_folders" (
|
|
"id" integer PRIMARY KEY AUTOINCREMENT,
|
|
"user_id" text NOT NULL,
|
|
"name" text NOT NULL,
|
|
"color" text,
|
|
"icon" text,
|
|
"sync_id" text UNIQUE,
|
|
"created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
"updated_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE
|
|
);
|
|
ALTER TABLE "snippet_folders" RENAME TO "p_snippets_snippet_folders";
|
|
CREATE TABLE IF NOT EXISTS "snippet_access" (
|
|
"id" integer PRIMARY KEY AUTOINCREMENT,
|
|
"snippet_id" integer NOT NULL,
|
|
"user_id" text,
|
|
"role_id" integer,
|
|
"granted_by" text NOT NULL,
|
|
"permission_level" text NOT NULL DEFAULT 'view',
|
|
"expires_at" text,
|
|
"created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY ("granted_by") REFERENCES "users" ("id") ON DELETE CASCADE
|
|
);
|
|
CREATE INDEX IF NOT EXISTS "idx_snippet_access_user_id" ON "snippet_access" ("user_id");
|
|
CREATE INDEX IF NOT EXISTS "idx_snippet_access_snippet_id" ON "snippet_access" ("snippet_id");
|
|
CREATE INDEX IF NOT EXISTS "idx_snippet_access_role_id" ON "snippet_access" ("role_id");
|
|
ALTER TABLE "snippet_access" RENAME TO "p_snippets_snippet_access";
|