|
| 1 | + |
| 2 | +-- +migrate Up |
| 3 | +CREATE TABLE IF NOT EXISTS "base_salaries" ( |
| 4 | + "id" uuid PRIMARY KEY DEFAULT (uuid()), |
| 5 | + "employee_id" uuid, |
| 6 | + "contract_amount" int8 NOT NULL DEFAULT 0, |
| 7 | + "company_account_amount" int8 NOT NULL DEFAULT 0, |
| 8 | + "personal_account_amount" int8 NOT NULL DEFAULT 0, |
| 9 | + "insurance_amount" int8 NOT NULL DEFAULT 0, |
| 10 | + "currency_id" uuid, |
| 11 | + "effective_date" date, |
| 12 | + "created_at" timestamptz(6) DEFAULT now(), |
| 13 | + "deleted_at" timestamptz(6), |
| 14 | + "is_active" bool DEFAULT true, |
| 15 | + "batch" int4, |
| 16 | + "type" text COLLATE "pg_catalog"."default", |
| 17 | + "category" text COLLATE "pg_catalog"."default" |
| 18 | +) |
| 19 | +; |
| 20 | +ALTER TABLE "base_salaries" ADD CONSTRAINT "base_salaries_currency_id_fkey" FOREIGN KEY ("currency_id") REFERENCES "currencies" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION; |
| 21 | +ALTER TABLE "base_salaries" ADD CONSTRAINT "base_salaries_employee_id_fkey" FOREIGN KEY ("employee_id") REFERENCES "employees" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION; |
| 22 | + |
| 23 | +CREATE TABLE IF NOT EXISTS "accounting_transactions" ( |
| 24 | + "id" uuid PRIMARY KEY DEFAULT (uuid()), |
| 25 | + "created_at" timestamptz(6) DEFAULT now(), |
| 26 | + "deleted_at" timestamptz(6), |
| 27 | + "date" timestamptz(6) DEFAULT now(), |
| 28 | + "name" text COLLATE "pg_catalog"."default", |
| 29 | + "amount" float8, |
| 30 | + "currency_id" uuid NOT NULL, |
| 31 | + "conversion_amount" int8, |
| 32 | + "organization" text COLLATE "pg_catalog"."default", |
| 33 | + "metadata" json, |
| 34 | + "category" text COLLATE "pg_catalog"."default", |
| 35 | + "currency" text COLLATE "pg_catalog"."default", |
| 36 | + "conversion_rate" float4, |
| 37 | + "type" text COLLATE "pg_catalog"."default" |
| 38 | +) |
| 39 | +; |
| 40 | +ALTER TABLE "accounting_transactions" ADD CONSTRAINT "transaction_info_unique" UNIQUE ("name", "date"); |
| 41 | +ALTER TABLE "accounting_transactions" DROP CONSTRAINT IF EXISTS "accounting_transactions_currency_id_fkey"; |
| 42 | +ALTER TABLE "accounting_transactions" ADD CONSTRAINT "accounting_transactions_currency_id_fkey" FOREIGN KEY ("currency_id") REFERENCES "currencies" ("id") ON DELETE CASCADE ON UPDATE NO ACTION; |
| 43 | + |
| 44 | +CREATE TABLE IF NOT EXISTS "accounting_categories" ( |
| 45 | + "id" uuid PRIMARY KEY DEFAULT (uuid()), |
| 46 | + "created_at" timestamptz(6) DEFAULT now(), |
| 47 | + "updated_at" TIMESTAMPTZ(6) DEFAULT NOW(), |
| 48 | + "deleted_at" timestamptz(6), |
| 49 | + "name" text COLLATE "pg_catalog"."default", |
| 50 | + "type" text COLLATE "pg_catalog"."default" |
| 51 | +); |
| 52 | + |
| 53 | +CREATE TABLE IF NOT EXISTS "employee_commissions" ( |
| 54 | + "id" UUID PRIMARY KEY DEFAULT (uuid()), |
| 55 | + "created_at" TIMESTAMPTZ(6) DEFAULT NOW(), |
| 56 | + "updated_at" TIMESTAMPTZ(6) DEFAULT NOW(), |
| 57 | + "deleted_at" TIMESTAMPTZ(6), |
| 58 | + "invoice_id" UUID NOT NULL, |
| 59 | + "employee_id" UUID, |
| 60 | + "amount" INT4, |
| 61 | + "project" TEXT COLLATE "pg_catalog"."default", |
| 62 | + "conversion_rate" DECIMAL DEFAULT 0, |
| 63 | + "is_paid" BOOL DEFAULT FALSE, |
| 64 | + "formula" TEXT COLLATE "pg_catalog"."default", |
| 65 | + "note" TEXT COLLATE "pg_catalog"."default", |
| 66 | + "paid_at" TIMESTAMPTZ(6) |
| 67 | +); |
| 68 | +ALTER TABLE "employee_commissions" ADD CONSTRAINT "employee_commissions_employee_id_fkey" FOREIGN KEY ("employee_id") REFERENCES "employees" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION; |
| 69 | + |
| 70 | +CREATE TABLE IF NOT EXISTS "employee_bonuses" ( |
| 71 | + "id" uuid PRIMARY KEY DEFAULT (uuid()), |
| 72 | + "employee_id" uuid NOT NULL, |
| 73 | + "amount" int8, |
| 74 | + "is_active" bool DEFAULT true, |
| 75 | + "name" text COLLATE "pg_catalog"."default", |
| 76 | + "created_at" timestamp(6) DEFAULT now() |
| 77 | +) |
| 78 | +; |
| 79 | +ALTER TABLE "employee_bonuses" ADD CONSTRAINT "employee_bonuses_employee_id_fkey" FOREIGN KEY ("employee_id") REFERENCES "employees" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION; |
| 80 | + |
| 81 | +CREATE TABLE IF NOT EXISTS "payrolls" ( |
| 82 | + "id" uuid PRIMARY KEY DEFAULT (uuid()), |
| 83 | + "employee_id" uuid NOT NULL, |
| 84 | + "total" int8 NOT NULL DEFAULT 0, |
| 85 | + "month" int4, |
| 86 | + "year" int4, |
| 87 | + "commission_amount" int8 NOT NULL DEFAULT 0, |
| 88 | + "commission_explain" json, |
| 89 | + "employee_rank_snapshot" json, |
| 90 | + "total_explain" json, |
| 91 | + "project_bonus_amount" int8 NOT NULL DEFAULT 0, |
| 92 | + "due_date" date, |
| 93 | + "project_bonus_explain" json, |
| 94 | + "is_paid" bool DEFAULT false, |
| 95 | + "conversion_amount" int8 NOT NULL DEFAULT 0, |
| 96 | + "base_salary_amount" int8 NOT NULL DEFAULT 0, |
| 97 | + "contract_amount" int8 |
| 98 | +); |
| 99 | +ALTER TABLE |
| 100 | + "payrolls" |
| 101 | +ADD |
| 102 | + CONSTRAINT "payrolls_employee_id_fkey" FOREIGN KEY ("employee_id") REFERENCES "employees" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION; |
| 103 | + |
| 104 | +CREATE TABLE IF NOT EXISTS "project_commission_configs" ( |
| 105 | + "id" UUID PRIMARY KEY DEFAULT (uuid()), |
| 106 | + "deleted_at" TIMESTAMP(6), |
| 107 | + "created_at" TIMESTAMP(6) DEFAULT (NOW()), |
| 108 | + "updated_at" TIMESTAMP(6) DEFAULT (NOW()), |
| 109 | + "project_id" UUID, |
| 110 | + "position" project_head_positions, |
| 111 | + "commission_rate" DECIMAL |
| 112 | +); |
| 113 | + |
| 114 | +ALTER TABLE |
| 115 | + "project_commission_configs" |
| 116 | +ADD |
| 117 | + CONSTRAINT "project_commission_configs_project_id_fkey" FOREIGN KEY ("project_id") REFERENCES "projects" ("id"); |
| 118 | + |
| 119 | +-- +migrate Down |
0 commit comments