2020-10-29 02:20:39 +00:00
|
|
|
CREATE TABLE IF NOT EXISTS "owners" (
|
|
|
|
"id" SERIAL PRIMARY KEY NOT NULL,
|
|
|
|
"name" VARCHAR(255) NOT NULL,
|
|
|
|
"api_key" UUID NOT NULL UNIQUE,
|
|
|
|
"ip_address" inet,
|
|
|
|
"mod_version" INTEGER NOT NULL,
|
|
|
|
"created_at" timestamp(3) NOT NULL,
|
|
|
|
"updated_at" timestamp(3) NOT NULL
|
|
|
|
);
|
|
|
|
CREATE UNIQUE INDEX "owners_unique_name_and_api_key" ON "owners" ("name", "api_key");
|
|
|
|
CREATE TABLE "shops" (
|
|
|
|
"id" SERIAL PRIMARY KEY NOT NULL,
|
|
|
|
"name" VARCHAR(255) NOT NULL,
|
|
|
|
"owner_id" INTEGER REFERENCES "owners"(id) NOT NULL,
|
|
|
|
"description" TEXT,
|
|
|
|
"created_at" timestamp(3) NOT NULL,
|
|
|
|
"updated_at" timestamp(3) NOT NULL
|
|
|
|
);
|
|
|
|
CREATE UNIQUE INDEX "shops_unique_name_and_owner_id" ON "shops" ("name", "owner_id");
|
|
|
|
CREATE TABLE "interior_ref_lists" (
|
|
|
|
"id" SERIAL PRIMARY KEY NOT NULL,
|
|
|
|
"shop_id" INTEGER REFERENCES "shops"(id) NOT NULL UNIQUE,
|
|
|
|
"owner_id" INTEGER REFERENCES "owners"(id) NOT NULL,
|
|
|
|
"ref_list" jsonb NOT NULL,
|
|
|
|
"created_at" timestamp(3) NOT NULL,
|
|
|
|
"updated_at" timestamp(3) NOT NULL
|
|
|
|
);
|
|
|
|
CREATE TABLE "merchandise_lists" (
|
|
|
|
"id" SERIAL PRIMARY KEY NOT NULL,
|
|
|
|
"shop_id" INTEGER REFERENCES "shops"(id) NOT NULL UNIQUE,
|
|
|
|
"owner_id" INTEGER REFERENCES "owners"(id) NOT NULL,
|
2020-10-29 03:40:38 +00:00
|
|
|
"form_list" jsonb NOT NULL
|
2020-10-29 03:56:53 +00:00
|
|
|
CONSTRAINT "merchandise_quantity_gt_zero" CHECK (NOT jsonb_path_exists(form_list, '$[*].quantity ? (@ < 1)')),
|
2020-10-29 02:20:39 +00:00
|
|
|
"created_at" timestamp(3) NOT NULL,
|
|
|
|
"updated_at" timestamp(3) NOT NULL
|
2020-10-30 04:22:26 +00:00
|
|
|
);
|
2020-11-01 00:34:20 +00:00
|
|
|
CREATE INDEX "merchandise_lists_mod_name_and_local_form_id" ON "merchandise_lists" USING GIN (form_list jsonb_path_ops);
|
2020-10-30 04:22:26 +00:00
|
|
|
CREATE TABLE "transactions" (
|
|
|
|
"id" SERIAL PRIMARY KEY NOT NULL,
|
2020-11-01 00:34:20 +00:00
|
|
|
"shop_id" INTEGER REFERENCES "shops"(id) NOT NULL,
|
2020-10-30 04:22:26 +00:00
|
|
|
"owner_id" INTEGER REFERENCES "owners"(id) NOT NULL,
|
|
|
|
"mod_name" VARCHAR(260) NOT NULL,
|
|
|
|
"local_form_id" INTEGER NOT NULL,
|
2020-11-01 00:34:20 +00:00
|
|
|
"name" TEXT NOT NULL,
|
|
|
|
"form_type" INTEGER NOT NULL,
|
|
|
|
"is_food" BOOLEAN NOT NULL,
|
|
|
|
"price" INTEGER NOT NULL,
|
2020-10-30 04:22:26 +00:00
|
|
|
"is_sell" BOOLEAN NOT NULL,
|
|
|
|
"quantity" INTEGER NOT NULL,
|
|
|
|
"amount" INTEGER NOT NULL,
|
|
|
|
"created_at" timestamp(3) NOT NULL,
|
|
|
|
"updated_at" timestamp(3) NOT NULL
|
2020-11-01 00:34:20 +00:00
|
|
|
);
|
|
|
|
CREATE INDEX "transactions_shop_id" ON "transactions" ("shop_id");
|
|
|
|
CREATE INDEX "transactions_owner_id" ON "transactions" ("owner_id");
|
|
|
|
CREATE INDEX "transactions_mod_name_and_local_form_id" ON "transactions" ("mod_name", "local_form_id");
|