28 lines
2.1 KiB
MySQL
28 lines
2.1 KiB
MySQL
|
-- +goose Up
|
||
|
-- create "document_blocks" table
|
||
|
CREATE TABLE "document_blocks" ("id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, "name" character varying NOT NULL, "content" character varying NOT NULL, "order" bigint NOT NULL, "document_id" bigint NOT NULL, "user_id" character varying NOT NULL, "created_at" timestamptz NOT NULL, "updated_at" timestamptz NOT NULL, PRIMARY KEY ("id"));
|
||
|
-- create index "documentblock_name_user_id_order" to table: "document_blocks"
|
||
|
CREATE INDEX "documentblock_name_user_id_order" ON "document_blocks" ("name", "user_id", "order");
|
||
|
-- create "libraries" table
|
||
|
CREATE TABLE "libraries" ("id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, "name" character varying NOT NULL, "user_id" character varying NOT NULL, "created_at" timestamptz NOT NULL, "updated_at" timestamptz NOT NULL, PRIMARY KEY ("id"));
|
||
|
-- create index "library_name_user_id" to table: "libraries"
|
||
|
CREATE INDEX "library_name_user_id" ON "libraries" ("name", "user_id");
|
||
|
-- create "documents" table
|
||
|
CREATE TABLE "documents" ("id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, "name" character varying NOT NULL, "user_id" character varying NOT NULL, "library_id" bigint NOT NULL, "created_at" timestamptz NOT NULL, "updated_at" timestamptz NOT NULL, "document_block_document" bigint NULL, PRIMARY KEY ("id"), CONSTRAINT "documents_document_blocks_document" FOREIGN KEY ("document_block_document") REFERENCES "document_blocks" ("id") ON DELETE SET NULL);
|
||
|
-- create index "document_name_user_id" to table: "documents"
|
||
|
CREATE INDEX "document_name_user_id" ON "documents" ("name", "user_id");
|
||
|
|
||
|
-- +goose Down
|
||
|
-- reverse: create index "document_name_user_id" to table: "documents"
|
||
|
DROP INDEX "document_name_user_id";
|
||
|
-- reverse: create "documents" table
|
||
|
DROP TABLE "documents";
|
||
|
-- reverse: create index "library_name_user_id" to table: "libraries"
|
||
|
DROP INDEX "library_name_user_id";
|
||
|
-- reverse: create "libraries" table
|
||
|
DROP TABLE "libraries";
|
||
|
-- reverse: create index "documentblock_name_user_id_order" to table: "document_blocks"
|
||
|
DROP INDEX "documentblock_name_user_id_order";
|
||
|
-- reverse: create "document_blocks" table
|
||
|
DROP TABLE "document_blocks";
|