43 lines
2.8 KiB
TypeScript
43 lines
2.8 KiB
TypeScript
import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres'
|
|
|
|
export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
|
|
await db.execute(sql`
|
|
CREATE TYPE "public"."enum_awards_grant_config_allowed_grantor_assignment_types" AS ENUM('division', 'squad', 'team', 'special');
|
|
CREATE TYPE "public"."enum_awards_grant_config_recipient_scope" AS ENUM('same_command', 'whitelist', 'anyone');
|
|
CREATE TABLE "awards_grant_config_allowed_grantor_assignment_types" (
|
|
"order" integer NOT NULL,
|
|
"parent_id" integer NOT NULL,
|
|
"value" "enum_awards_grant_config_allowed_grantor_assignment_types",
|
|
"id" serial PRIMARY KEY NOT NULL
|
|
);
|
|
|
|
CREATE TABLE "awards_rels" (
|
|
"id" serial PRIMARY KEY NOT NULL,
|
|
"order" integer,
|
|
"parent_id" integer NOT NULL,
|
|
"path" varchar NOT NULL,
|
|
"assignments_id" integer
|
|
);
|
|
|
|
ALTER TABLE "awards" ADD COLUMN "grant_config_max_grants_per_grantor" numeric;
|
|
ALTER TABLE "awards" ADD COLUMN "grant_config_recipient_scope" "enum_awards_grant_config_recipient_scope" DEFAULT 'same_command';
|
|
ALTER TABLE "awards_grant_config_allowed_grantor_assignment_types" ADD CONSTRAINT "awards_grant_config_allowed_grantor_assignment_types_parent_fk" FOREIGN KEY ("parent_id") REFERENCES "public"."awards"("id") ON DELETE cascade ON UPDATE no action;
|
|
ALTER TABLE "awards_rels" ADD CONSTRAINT "awards_rels_parent_fk" FOREIGN KEY ("parent_id") REFERENCES "public"."awards"("id") ON DELETE cascade ON UPDATE no action;
|
|
ALTER TABLE "awards_rels" ADD CONSTRAINT "awards_rels_assignments_fk" FOREIGN KEY ("assignments_id") REFERENCES "public"."assignments"("id") ON DELETE cascade ON UPDATE no action;
|
|
CREATE INDEX "awards_grant_config_allowed_grantor_assignment_types_order_idx" ON "awards_grant_config_allowed_grantor_assignment_types" USING btree ("order");
|
|
CREATE INDEX "awards_grant_config_allowed_grantor_assignment_types_parent_idx" ON "awards_grant_config_allowed_grantor_assignment_types" USING btree ("parent_id");
|
|
CREATE INDEX "awards_rels_order_idx" ON "awards_rels" USING btree ("order");
|
|
CREATE INDEX "awards_rels_parent_idx" ON "awards_rels" USING btree ("parent_id");
|
|
CREATE INDEX "awards_rels_path_idx" ON "awards_rels" USING btree ("path");
|
|
CREATE INDEX "awards_rels_assignments_id_idx" ON "awards_rels" USING btree ("assignments_id");`)
|
|
}
|
|
|
|
export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
|
|
await db.execute(sql`
|
|
DROP TABLE "awards_grant_config_allowed_grantor_assignment_types" CASCADE;
|
|
DROP TABLE "awards_rels" CASCADE;
|
|
ALTER TABLE "awards" DROP COLUMN "grant_config_max_grants_per_grantor";
|
|
ALTER TABLE "awards" DROP COLUMN "grant_config_recipient_scope";
|
|
DROP TYPE "public"."enum_awards_grant_config_allowed_grantor_assignment_types";
|
|
DROP TYPE "public"."enum_awards_grant_config_recipient_scope";`)
|
|
}
|