· 4 years ago · Feb 16, 2021, 12:02 PM
1BEGIN;
2--
3-- Creates extension btree_gist
4--
5CREATE EXTENSION IF NOT EXISTS "btree_gist";
6--
7-- Create model COAHeaderModel
8--
9CREATE TABLE "coa_coaheadermodel" ("id" serial NOT NULL PRIMARY KEY, "created_at" timestamp with time zone NOT NULL, "updated_at" timestamp with time zone NOT NULL, "deleted_at" timestamp with time zone NULL, "name" varchar(128) NOT NULL, "description" varchar(512) NOT NULL, "level" integer NOT NULL, "range" int4range NOT NULL, "created_by_id" integer NULL, "deleted_by_id" integer NULL, "updated_by_id" integer NULL);
10--
11-- Create model COACollectionModel
12--
13CREATE TABLE "coa_coacollectionmodel" ("id" serial NOT NULL PRIMARY KEY, "created_at" timestamp with time zone NOT NULL, "updated_at" timestamp with time zone NOT NULL, "deleted_at" timestamp with time zone NULL, "name" varchar(128) NOT NULL, "description" varchar(512) NOT NULL, "created_by_id" integer NULL, "deleted_by_id" integer NULL, "updated_by_id" integer NULL);
14--
15-- Create model COAAccountModel
16--
17CREATE TABLE "coa_coaaccountmodel" ("id" serial NOT NULL PRIMARY KEY, "created_at" timestamp with time zone NOT NULL, "updated_at" timestamp with time zone NOT NULL, "deleted_at" timestamp with time zone NULL, "number" integer NOT NULL, "name" varchar(128) NOT NULL, "type" varchar(3) NOT NULL, "default_vat_code" integer NULL, "default_vat_rate" integer NULL, "deprecation_code" varchar(1) NOT NULL, "collection_id" integer NOT NULL, "created_by_id" integer NULL, "deleted_by_id" integer NULL, "updated_by_id" integer NULL);
18--
19-- Create constraint overlap_constraint on model coaheadermodel
20--
21ALTER TABLE "coa_coaheadermodel" ADD CONSTRAINT "overlap_constraint" EXCLUDE USING GIST ("range" WITH &&, "level" WITH =);
22ALTER TABLE "coa_coaheadermodel" ADD CONSTRAINT "coa_coaheadermodel_created_by_id_62b04264_fk_main_usermodel_id" FOREIGN KEY ("created_by_id") REFERENCES "main_usermodel" ("id") DEFERRABLE INITIALLY DEFERRED;
23ALTER TABLE "coa_coaheadermodel" ADD CONSTRAINT "coa_coaheadermodel_deleted_by_id_2401f9cf_fk_main_usermodel_id" FOREIGN KEY ("deleted_by_id") REFERENCES "main_usermodel" ("id") DEFERRABLE INITIALLY DEFERRED;
24ALTER TABLE "coa_coaheadermodel" ADD CONSTRAINT "coa_coaheadermodel_updated_by_id_8d39ebad_fk_main_usermodel_id" FOREIGN KEY ("updated_by_id") REFERENCES "main_usermodel" ("id") DEFERRABLE INITIALLY DEFERRED;
25CREATE INDEX "coa_coaheadermodel_created_by_id_62b04264" ON "coa_coaheadermodel" ("created_by_id");
26CREATE INDEX "coa_coaheadermodel_deleted_by_id_2401f9cf" ON "coa_coaheadermodel" ("deleted_by_id");
27CREATE INDEX "coa_coaheadermodel_updated_by_id_8d39ebad" ON "coa_coaheadermodel" ("updated_by_id");
28ALTER TABLE "coa_coacollectionmodel" ADD CONSTRAINT "coa_coacollectionmod_created_by_id_59c6b01e_fk_main_user" FOREIGN KEY ("created_by_id") REFERENCES "main_usermodel" ("id") DEFERRABLE INITIALLY DEFERRED;
29ALTER TABLE "coa_coacollectionmodel" ADD CONSTRAINT "coa_coacollectionmod_deleted_by_id_75b5f395_fk_main_user" FOREIGN KEY ("deleted_by_id") REFERENCES "main_usermodel" ("id") DEFERRABLE INITIALLY DEFERRED;
30ALTER TABLE "coa_coacollectionmodel" ADD CONSTRAINT "coa_coacollectionmod_updated_by_id_9e257dd8_fk_main_user" FOREIGN KEY ("updated_by_id") REFERENCES "main_usermodel" ("id") DEFERRABLE INITIALLY DEFERRED;
31CREATE INDEX "coa_coacollectionmodel_created_by_id_59c6b01e" ON "coa_coacollectionmodel" ("created_by_id");
32CREATE INDEX "coa_coacollectionmodel_deleted_by_id_75b5f395" ON "coa_coacollectionmodel" ("deleted_by_id");
33CREATE INDEX "coa_coacollectionmodel_updated_by_id_9e257dd8" ON "coa_coacollectionmodel" ("updated_by_id");
34ALTER TABLE "coa_coaaccountmodel" ADD CONSTRAINT "coa_coaaccountmodel_collection_id_ac4e35e8_fk_coa_coaco" FOREIGN KEY ("collection_id") REFERENCES "coa_coacollectionmodel" ("id") DEFERRABLE INITIALLY DEFERRED;
35ALTER TABLE "coa_coaaccountmodel" ADD CONSTRAINT "coa_coaaccountmodel_created_by_id_dd755b21_fk_main_usermodel_id" FOREIGN KEY ("created_by_id") REFERENCES "main_usermodel" ("id") DEFERRABLE INITIALLY DEFERRED;
36ALTER TABLE "coa_coaaccountmodel" ADD CONSTRAINT "coa_coaaccountmodel_deleted_by_id_5c7b6a44_fk_main_usermodel_id" FOREIGN KEY ("deleted_by_id") REFERENCES "main_usermodel" ("id") DEFERRABLE INITIALLY DEFERRED;
37ALTER TABLE "coa_coaaccountmodel" ADD CONSTRAINT "coa_coaaccountmodel_updated_by_id_129ebdf2_fk_main_usermodel_id" FOREIGN KEY ("updated_by_id") REFERENCES "main_usermodel" ("id") DEFERRABLE INITIALLY DEFERRED;
38CREATE INDEX "coa_coaaccountmodel_collection_id_ac4e35e8" ON "coa_coaaccountmodel" ("collection_id");
39CREATE INDEX "coa_coaaccountmodel_created_by_id_dd755b21" ON "coa_coaaccountmodel" ("created_by_id");
40CREATE INDEX "coa_coaaccountmodel_deleted_by_id_5c7b6a44" ON "coa_coaaccountmodel" ("deleted_by_id");
41CREATE INDEX "coa_coaaccountmodel_updated_by_id_129ebdf2" ON "coa_coaaccountmodel" ("updated_by_id");
42COMMIT;