Skip to content

Instantly share code, notes, and snippets.

@pazaricha
Created February 11, 2026 16:04
Show Gist options
  • Select an option

  • Save pazaricha/6e3cf8bbd8d8b3095f4b8d591a850d65 to your computer and use it in GitHub Desktop.

Select an option

Save pazaricha/6e3cf8bbd8d8b3095f4b8d591a850d65 to your computer and use it in GitHub Desktop.
huge migration?!
import { MigrationInterface, QueryRunner } from "typeorm";
export class Migration1770825659772 implements MigrationInterface {
name = 'Migration1770825659772'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE "netsuite_schema_table_config" DROP CONSTRAINT "FK_netsuite_schema_table_config_org"
`);
await queryRunner.query(`
ALTER TABLE "netsuite_schema" DROP CONSTRAINT "FK_netsuite_schema_table_config"
`);
await queryRunner.query(`
ALTER TABLE "netsuite_schema_table_config_history" DROP CONSTRAINT "FK_netsuite_schema_table_config_history_org"
`);
await queryRunner.query(`
ALTER TABLE "netsuite_schema_table_config_history" DROP CONSTRAINT "FK_netsuite_schema_table_config_history_revision"
`);
await queryRunner.query(`
ALTER TABLE "netsuite_schema_history" DROP CONSTRAINT "FK_netsuite_schema_history_table_config"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments" DROP CONSTRAINT "FK_sync_field_enrichments_org"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config" DROP CONSTRAINT "lf_data_filter_config_organization_id_fkey"
`);
await queryRunner.query(`
ALTER TABLE "inventory_reconciliation_requests" DROP CONSTRAINT "FK_inv_recon_req_organization"
`);
await queryRunner.query(`
ALTER TABLE "inventory_reconciliation_requests" DROP CONSTRAINT "FK_inv_recon_req_conversation"
`);
await queryRunner.query(`
ALTER TABLE "inventory_reconciliation_requests" DROP CONSTRAINT "FK_inv_recon_req_created_by"
`);
await queryRunner.query(`
ALTER TABLE "inventory_reconciliation_requests" DROP CONSTRAINT "FK_inv_recon_req_published_by"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."chunk_finder_tasks" DROP CONSTRAINT "FK_chunk_finder_tasks_organization_id"
`);
await queryRunner.query(`
ALTER TABLE "inventory_reconciliation_request_approvers" DROP CONSTRAINT "FK_inv_recon_req_approvers_request"
`);
await queryRunner.query(`
ALTER TABLE "inventory_reconciliation_request_approvers" DROP CONSTRAINT "FK_inv_recon_req_approvers_user"
`);
await queryRunner.query(`
DROP INDEX "public"."idx_user_rbac_roles_lf_persona"
`);
await queryRunner.query(`
DROP INDEX "public"."IDX_netsuite_schema_table_config_table"
`);
await queryRunner.query(`
DROP INDEX "public"."IDX_netsuite_schema_table_config_id"
`);
await queryRunner.query(`
DROP INDEX "public"."IDX_netsuite_schema_table_config_history_table"
`);
await queryRunner.query(`
DROP INDEX "public"."IDX_netsuite_schema_history_table_config_id"
`);
await queryRunner.query(`
DROP INDEX "lake_ops"."UQ_sync_field_enrichments_org"
`);
await queryRunner.query(`
DROP INDEX "lake_ops"."UQ_sync_field_enrichments_global"
`);
await queryRunner.query(`
DROP INDEX "lake_ops"."idx_lf_data_filter_config_persona"
`);
await queryRunner.query(`
DROP INDEX "lake_ops"."idx_lf_data_filter_config_organization"
`);
await queryRunner.query(`
DROP INDEX "lake_ops"."idx_lf_data_filter_config_target_table"
`);
await queryRunner.query(`
DROP INDEX "public"."IDX_inv_recon_req_approvers_request"
`);
await queryRunner.query(`
DROP INDEX "public"."IDX_inv_recon_req_approvers_user"
`);
await queryRunner.query(`
ALTER TABLE "user_reports" DROP CONSTRAINT "UQ_user_reports_name_created_by"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config" DROP CONSTRAINT "uq_lf_data_filter_config_org_table_persona"
`);
await queryRunner.query(`
COMMENT ON TABLE "lake_ops"."sync_field_enrichments" IS NULL
`);
await queryRunner.query(`
COMMENT ON TABLE "lake_ops"."lf_data_filter_config" IS NULL
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments"
ADD "deleted_at" TIMESTAMP(3) WITH TIME ZONE
`);
await queryRunner.query(`
ALTER TABLE "user_rbac_permission_group"
ALTER COLUMN "lf_record_types"
SET NOT NULL
`);
await queryRunner.query(`
COMMENT ON COLUMN "user_rbac_permission_group"."lf_record_types" IS NULL
`);
await queryRunner.query(`
ALTER TABLE "user_rbac_permission_group"
ALTER COLUMN "lf_tables"
SET NOT NULL
`);
await queryRunner.query(`
COMMENT ON COLUMN "user_rbac_permission_group"."lf_tables" IS NULL
`);
await queryRunner.query(`
COMMENT ON COLUMN "user_rbac_roles"."lf_persona" IS NULL
`);
await queryRunner.query(`
ALTER TYPE "lake_ops"."lake_ops_auto_sync_state_lifecycle_stage_enum"
RENAME TO "lake_ops_auto_sync_state_lifecycle_stage_enum_old"
`);
await queryRunner.query(`
CREATE TYPE "lake_ops"."lake_ops_auto_sync_state_lifecycle_stage_enum" AS ENUM('discovery', 'setup', 'sync', 'cdc_active')
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."auto_sync_state"
ALTER COLUMN "lifecycle_stage" TYPE "lake_ops"."lake_ops_auto_sync_state_lifecycle_stage_enum" USING "lifecycle_stage"::"text"::"lake_ops"."lake_ops_auto_sync_state_lifecycle_stage_enum"
`);
await queryRunner.query(`
DROP TYPE "lake_ops"."lake_ops_auto_sync_state_lifecycle_stage_enum_old"
`);
await queryRunner.query(`
ALTER TABLE "organizations"
ALTER COLUMN "email_domains"
SET DEFAULT ARRAY []::text []
`);
await queryRunner.query(`
DROP INDEX "lake_ops"."IDX_sync_field_enrichments_target"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments" DROP COLUMN "target_table"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments"
ADD "target_table" character varying NOT NULL
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments" DROP COLUMN "target_column"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments"
ADD "target_column" character varying NOT NULL
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments" DROP COLUMN "target_column_type"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments"
ADD "target_column_type" character varying NOT NULL DEFAULT 'string'
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments" DROP COLUMN "source_table"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments"
ADD "source_table" character varying NOT NULL
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments" DROP COLUMN "source_column"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments"
ADD "source_column" character varying NOT NULL
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments" DROP COLUMN "target_join_key"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments"
ADD "target_join_key" character varying NOT NULL
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments" DROP COLUMN "source_join_key"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments"
ADD "source_join_key" character varying NOT NULL DEFAULT 'id'
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments" DROP COLUMN "join_source_type"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments"
ADD "join_source_type" character varying NOT NULL DEFAULT 'column'
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config" DROP COLUMN "created_at"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config"
ADD "created_at" TIMESTAMP(3) WITH TIME ZONE NOT NULL DEFAULT now()
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config" DROP COLUMN "updated_at"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config"
ADD "updated_at" TIMESTAMP(3) WITH TIME ZONE NOT NULL DEFAULT now()
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config"
ALTER COLUMN "deleted_at" TYPE TIMESTAMP(3) WITH TIME ZONE
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config" DROP COLUMN "filter_name"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config"
ADD "filter_name" character varying NOT NULL
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config" DROP COLUMN "target_table"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config"
ADD "target_table" character varying NOT NULL
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config"
ALTER COLUMN "excluded_columns"
SET NOT NULL
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config" DROP COLUMN "persona"
`);
await queryRunner.query(`
CREATE TYPE "lake_ops"."lf_persona_enum" AS ENUM(
'FULL_ACCESS',
'PURCHASING',
'INVENTORY_MGMT',
'MANUFACTURING',
'SALES'
)
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config"
ADD "persona" "lake_ops"."lf_persona_enum" NOT NULL
`);
await queryRunner.query(`
CREATE UNIQUE INDEX "UQ_user_reports_name_created_by" ON "user_reports" ("name", "created_by_id")
WHERE "deleted_at" IS NULL
`);
await queryRunner.query(`
CREATE INDEX "IDX_sync_field_enrichments_target" ON "lake_ops"."sync_field_enrichments" ("target_table")
`);
await queryRunner.query(`
CREATE INDEX "IDX_65a83e1b7f93e8b90ea74b3d09" ON "lake_ops"."lf_data_filter_config" ("organization_id")
`);
await queryRunner.query(`
CREATE INDEX "IDX_0239e44a5f1f7d7684f8f9a818" ON "lake_ops"."lf_data_filter_config" ("target_table")
`);
await queryRunner.query(`
CREATE INDEX "IDX_354498a6546ad26d342e6e3b60" ON "lake_ops"."lf_data_filter_config" ("persona")
`);
await queryRunner.query(`
CREATE UNIQUE INDEX "IDX_4b8797b8cd955817041b3e17f2" ON "lake_ops"."lf_data_filter_config" ("organization_id", "target_table", "persona")
`);
await queryRunner.query(`
CREATE INDEX "IDX_f52c0f8debe558fd70606b1c38" ON "inventory_reconciliation_request_approvers" ("request_id")
`);
await queryRunner.query(`
CREATE INDEX "IDX_951245e0d59c4ea0c8cc8f1476" ON "inventory_reconciliation_request_approvers" ("emi_user_id")
`);
await queryRunner.query(`
ALTER TABLE "netsuite_schema_table_config"
ADD CONSTRAINT "FK_7c6227166b6adcc5756ae602cf5" FOREIGN KEY ("organization_id") REFERENCES "organizations"("id") ON DELETE CASCADE ON UPDATE NO ACTION
`);
await queryRunner.query(`
ALTER TABLE "netsuite_schema"
ADD CONSTRAINT "FK_5aee594726ec8f16f7a8f279f99" FOREIGN KEY ("table_config_id") REFERENCES "netsuite_schema_table_config"("id") ON DELETE
SET NULL ON UPDATE NO ACTION
`);
await queryRunner.query(`
ALTER TABLE "netsuite_schema_table_config_history"
ADD CONSTRAINT "FK_98c807786f1442dafd44607d6fc" FOREIGN KEY ("organization_id") REFERENCES "organizations"("id") ON DELETE CASCADE ON UPDATE NO ACTION
`);
await queryRunner.query(`
ALTER TABLE "netsuite_schema_table_config_history"
ADD CONSTRAINT "FK_b4f2023da2ba4115af5d210841e" FOREIGN KEY ("revision_id") REFERENCES "netsuite_schema_revision"("id") ON DELETE CASCADE ON UPDATE NO ACTION
`);
await queryRunner.query(`
ALTER TABLE "netsuite_schema_history"
ADD CONSTRAINT "FK_711fb7b8746877b9c188a44335a" FOREIGN KEY ("table_config_history_id") REFERENCES "netsuite_schema_table_config_history"("id") ON DELETE
SET NULL ON UPDATE NO ACTION
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments"
ADD CONSTRAINT "FK_184e919001c8f170deb5f59a39e" FOREIGN KEY ("organization_id") REFERENCES "organizations"("id") ON DELETE CASCADE ON UPDATE NO ACTION
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config"
ADD CONSTRAINT "FK_65a83e1b7f93e8b90ea74b3d09e" FOREIGN KEY ("organization_id") REFERENCES "organizations"("id") ON DELETE CASCADE ON UPDATE NO ACTION
`);
await queryRunner.query(`
ALTER TABLE "inventory_reconciliation_requests"
ADD CONSTRAINT "FK_6a31565bf600f9a9c9f9492c70e" FOREIGN KEY ("organization_id") REFERENCES "organizations"("id") ON DELETE CASCADE ON UPDATE NO ACTION
`);
await queryRunner.query(`
ALTER TABLE "inventory_reconciliation_requests"
ADD CONSTRAINT "FK_f25de2aaa6ff089d43514490327" FOREIGN KEY ("conversation_id") REFERENCES "chats"("id") ON DELETE
SET NULL ON UPDATE NO ACTION
`);
await queryRunner.query(`
ALTER TABLE "inventory_reconciliation_requests"
ADD CONSTRAINT "FK_f5518be1824ae365f39a616192a" FOREIGN KEY ("created_by_id") REFERENCES "emi_users"("id") ON DELETE CASCADE ON UPDATE NO ACTION
`);
await queryRunner.query(`
ALTER TABLE "inventory_reconciliation_requests"
ADD CONSTRAINT "FK_c7d0ff011321b31deb05211a2a5" FOREIGN KEY ("published_by_id") REFERENCES "emi_users"("id") ON DELETE
SET NULL ON UPDATE NO ACTION
`);
await queryRunner.query(`
ALTER TABLE "inventory_reconciliation_request_approvers"
ADD CONSTRAINT "FK_f52c0f8debe558fd70606b1c38c" FOREIGN KEY ("request_id") REFERENCES "inventory_reconciliation_requests"("id") ON DELETE CASCADE ON UPDATE CASCADE
`);
await queryRunner.query(`
ALTER TABLE "inventory_reconciliation_request_approvers"
ADD CONSTRAINT "FK_951245e0d59c4ea0c8cc8f14764" FOREIGN KEY ("emi_user_id") REFERENCES "emi_users"("id") ON DELETE CASCADE ON UPDATE CASCADE
`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE "inventory_reconciliation_request_approvers" DROP CONSTRAINT "FK_951245e0d59c4ea0c8cc8f14764"
`);
await queryRunner.query(`
ALTER TABLE "inventory_reconciliation_request_approvers" DROP CONSTRAINT "FK_f52c0f8debe558fd70606b1c38c"
`);
await queryRunner.query(`
ALTER TABLE "inventory_reconciliation_requests" DROP CONSTRAINT "FK_c7d0ff011321b31deb05211a2a5"
`);
await queryRunner.query(`
ALTER TABLE "inventory_reconciliation_requests" DROP CONSTRAINT "FK_f5518be1824ae365f39a616192a"
`);
await queryRunner.query(`
ALTER TABLE "inventory_reconciliation_requests" DROP CONSTRAINT "FK_f25de2aaa6ff089d43514490327"
`);
await queryRunner.query(`
ALTER TABLE "inventory_reconciliation_requests" DROP CONSTRAINT "FK_6a31565bf600f9a9c9f9492c70e"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config" DROP CONSTRAINT "FK_65a83e1b7f93e8b90ea74b3d09e"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments" DROP CONSTRAINT "FK_184e919001c8f170deb5f59a39e"
`);
await queryRunner.query(`
ALTER TABLE "netsuite_schema_history" DROP CONSTRAINT "FK_711fb7b8746877b9c188a44335a"
`);
await queryRunner.query(`
ALTER TABLE "netsuite_schema_table_config_history" DROP CONSTRAINT "FK_b4f2023da2ba4115af5d210841e"
`);
await queryRunner.query(`
ALTER TABLE "netsuite_schema_table_config_history" DROP CONSTRAINT "FK_98c807786f1442dafd44607d6fc"
`);
await queryRunner.query(`
ALTER TABLE "netsuite_schema" DROP CONSTRAINT "FK_5aee594726ec8f16f7a8f279f99"
`);
await queryRunner.query(`
ALTER TABLE "netsuite_schema_table_config" DROP CONSTRAINT "FK_7c6227166b6adcc5756ae602cf5"
`);
await queryRunner.query(`
DROP INDEX "public"."IDX_951245e0d59c4ea0c8cc8f1476"
`);
await queryRunner.query(`
DROP INDEX "public"."IDX_f52c0f8debe558fd70606b1c38"
`);
await queryRunner.query(`
DROP INDEX "lake_ops"."IDX_4b8797b8cd955817041b3e17f2"
`);
await queryRunner.query(`
DROP INDEX "lake_ops"."IDX_354498a6546ad26d342e6e3b60"
`);
await queryRunner.query(`
DROP INDEX "lake_ops"."IDX_0239e44a5f1f7d7684f8f9a818"
`);
await queryRunner.query(`
DROP INDEX "lake_ops"."IDX_65a83e1b7f93e8b90ea74b3d09"
`);
await queryRunner.query(`
DROP INDEX "lake_ops"."IDX_sync_field_enrichments_target"
`);
await queryRunner.query(`
DROP INDEX "public"."UQ_user_reports_name_created_by"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config" DROP COLUMN "persona"
`);
await queryRunner.query(`
DROP TYPE "lake_ops"."lf_persona_enum"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config"
ADD "persona" lf_persona_enum NOT NULL
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config"
ALTER COLUMN "excluded_columns" DROP NOT NULL
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config" DROP COLUMN "target_table"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config"
ADD "target_table" character varying(255) NOT NULL
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config" DROP COLUMN "filter_name"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config"
ADD "filter_name" character varying(255) NOT NULL
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config"
ALTER COLUMN "deleted_at" TYPE TIMESTAMP(6) WITH TIME ZONE
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config" DROP COLUMN "updated_at"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config"
ADD "updated_at" TIMESTAMP(6) NOT NULL DEFAULT now()
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config" DROP COLUMN "created_at"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config"
ADD "created_at" TIMESTAMP(6) NOT NULL DEFAULT now()
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments" DROP COLUMN "join_source_type"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments"
ADD "join_source_type" character varying(20) NOT NULL DEFAULT 'column'
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments" DROP COLUMN "source_join_key"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments"
ADD "source_join_key" character varying(255) NOT NULL DEFAULT 'id'
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments" DROP COLUMN "target_join_key"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments"
ADD "target_join_key" character varying(255) NOT NULL
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments" DROP COLUMN "source_column"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments"
ADD "source_column" character varying(255) NOT NULL
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments" DROP COLUMN "source_table"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments"
ADD "source_table" character varying(255) NOT NULL
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments" DROP COLUMN "target_column_type"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments"
ADD "target_column_type" character varying(50) NOT NULL DEFAULT 'string'
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments" DROP COLUMN "target_column"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments"
ADD "target_column" character varying(255) NOT NULL
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments" DROP COLUMN "target_table"
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments"
ADD "target_table" character varying(255) NOT NULL
`);
await queryRunner.query(`
CREATE INDEX "IDX_sync_field_enrichments_target" ON "lake_ops"."sync_field_enrichments" ("target_table")
`);
await queryRunner.query(`
ALTER TABLE "organizations"
ALTER COLUMN "email_domains"
SET DEFAULT ARRAY []
`);
await queryRunner.query(`
CREATE TYPE "lake_ops"."lake_ops_auto_sync_state_lifecycle_stage_enum_old" AS ENUM(
'discovery',
'setup',
'sync',
'cdc_active',
'chunk_finder'
)
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."auto_sync_state"
ALTER COLUMN "lifecycle_stage" TYPE "lake_ops"."lake_ops_auto_sync_state_lifecycle_stage_enum_old" USING "lifecycle_stage"::"text"::"lake_ops"."lake_ops_auto_sync_state_lifecycle_stage_enum_old"
`);
await queryRunner.query(`
DROP TYPE "lake_ops"."lake_ops_auto_sync_state_lifecycle_stage_enum"
`);
await queryRunner.query(`
ALTER TYPE "lake_ops"."lake_ops_auto_sync_state_lifecycle_stage_enum_old"
RENAME TO "lake_ops_auto_sync_state_lifecycle_stage_enum"
`);
await queryRunner.query(`
COMMENT ON COLUMN "user_rbac_roles"."lf_persona" IS 'Lake Formation persona for row-level security. Valid values: PURCHASING, SALES, MANUFACTURING, INVENTORY_MGMT, FULL_ACCESS. NULL means no Athena access. METADATA/INTERNAL are NOT valid - use FULL_ACCESS for admin users.'
`);
await queryRunner.query(`
COMMENT ON COLUMN "user_rbac_permission_group"."lf_tables" IS 'Full Glue/Athena table names this permission group applies to (e.g., curated_transaction, curated_item).'
`);
await queryRunner.query(`
ALTER TABLE "user_rbac_permission_group"
ALTER COLUMN "lf_tables" DROP NOT NULL
`);
await queryRunner.query(`
COMMENT ON COLUMN "user_rbac_permission_group"."lf_record_types" IS 'NetSuite record types (transaction types) this permission group grants access to. Used to generate Lake Formation row filters.'
`);
await queryRunner.query(`
ALTER TABLE "user_rbac_permission_group"
ALTER COLUMN "lf_record_types" DROP NOT NULL
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments" DROP COLUMN "deleted_at"
`);
await queryRunner.query(`
COMMENT ON TABLE "lake_ops"."lf_data_filter_config" IS 'OPTIONAL: Per-organization Lake Formation filter overrides. If no entry exists for a persona/table, filters are derived from permission group lf_record_types.'
`);
await queryRunner.query(`
COMMENT ON TABLE "lake_ops"."sync_field_enrichments" IS 'Configuration for field enrichment during sync curation. Defines which fields to copy from source tables to target tables for Lake Formation RBAC filtering.'
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config"
ADD CONSTRAINT "uq_lf_data_filter_config_org_table_persona" UNIQUE ("organization_id", "target_table", "persona")
`);
await queryRunner.query(`
ALTER TABLE "user_reports"
ADD CONSTRAINT "UQ_user_reports_name_created_by" UNIQUE ("name", "created_by_id")
`);
await queryRunner.query(`
CREATE INDEX "IDX_inv_recon_req_approvers_user" ON "inventory_reconciliation_request_approvers" ("emi_user_id")
`);
await queryRunner.query(`
CREATE INDEX "IDX_inv_recon_req_approvers_request" ON "inventory_reconciliation_request_approvers" ("request_id")
`);
await queryRunner.query(`
CREATE INDEX "idx_lf_data_filter_config_target_table" ON "lake_ops"."lf_data_filter_config" ("target_table")
`);
await queryRunner.query(`
CREATE INDEX "idx_lf_data_filter_config_organization" ON "lake_ops"."lf_data_filter_config" ("organization_id")
`);
await queryRunner.query(`
CREATE INDEX "idx_lf_data_filter_config_persona" ON "lake_ops"."lf_data_filter_config" ("persona")
`);
await queryRunner.query(`
CREATE UNIQUE INDEX "UQ_sync_field_enrichments_global" ON "lake_ops"."sync_field_enrichments" ("target_table", "target_column")
WHERE (organization_id IS NULL)
`);
await queryRunner.query(`
CREATE UNIQUE INDEX "UQ_sync_field_enrichments_org" ON "lake_ops"."sync_field_enrichments" (
"organization_id",
"target_table",
"target_column"
)
WHERE (organization_id IS NOT NULL)
`);
await queryRunner.query(`
CREATE INDEX "IDX_netsuite_schema_history_table_config_id" ON "netsuite_schema_history" ("table_config_history_id")
`);
await queryRunner.query(`
CREATE INDEX "IDX_netsuite_schema_table_config_history_table" ON "netsuite_schema_table_config_history" ("table")
`);
await queryRunner.query(`
CREATE INDEX "IDX_netsuite_schema_table_config_id" ON "netsuite_schema" ("table_config_id")
`);
await queryRunner.query(`
CREATE INDEX "IDX_netsuite_schema_table_config_table" ON "netsuite_schema_table_config" ("table")
`);
await queryRunner.query(`
CREATE INDEX "idx_user_rbac_roles_lf_persona" ON "user_rbac_roles" ("lf_persona")
`);
await queryRunner.query(`
ALTER TABLE "inventory_reconciliation_request_approvers"
ADD CONSTRAINT "FK_inv_recon_req_approvers_user" FOREIGN KEY ("emi_user_id") REFERENCES "emi_users"("id") ON DELETE CASCADE ON UPDATE NO ACTION
`);
await queryRunner.query(`
ALTER TABLE "inventory_reconciliation_request_approvers"
ADD CONSTRAINT "FK_inv_recon_req_approvers_request" FOREIGN KEY ("request_id") REFERENCES "inventory_reconciliation_requests"("id") ON DELETE CASCADE ON UPDATE NO ACTION
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."chunk_finder_tasks"
ADD CONSTRAINT "FK_chunk_finder_tasks_organization_id" FOREIGN KEY ("organization_id") REFERENCES "organizations"("id") ON DELETE CASCADE ON UPDATE NO ACTION
`);
await queryRunner.query(`
ALTER TABLE "inventory_reconciliation_requests"
ADD CONSTRAINT "FK_inv_recon_req_published_by" FOREIGN KEY ("published_by_id") REFERENCES "emi_users"("id") ON DELETE
SET NULL ON UPDATE NO ACTION
`);
await queryRunner.query(`
ALTER TABLE "inventory_reconciliation_requests"
ADD CONSTRAINT "FK_inv_recon_req_created_by" FOREIGN KEY ("created_by_id") REFERENCES "emi_users"("id") ON DELETE CASCADE ON UPDATE NO ACTION
`);
await queryRunner.query(`
ALTER TABLE "inventory_reconciliation_requests"
ADD CONSTRAINT "FK_inv_recon_req_conversation" FOREIGN KEY ("conversation_id") REFERENCES "chats"("id") ON DELETE
SET NULL ON UPDATE NO ACTION
`);
await queryRunner.query(`
ALTER TABLE "inventory_reconciliation_requests"
ADD CONSTRAINT "FK_inv_recon_req_organization" FOREIGN KEY ("organization_id") REFERENCES "organizations"("id") ON DELETE CASCADE ON UPDATE NO ACTION
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."lf_data_filter_config"
ADD CONSTRAINT "lf_data_filter_config_organization_id_fkey" FOREIGN KEY ("organization_id") REFERENCES "organizations"("id") ON DELETE CASCADE ON UPDATE NO ACTION
`);
await queryRunner.query(`
ALTER TABLE "lake_ops"."sync_field_enrichments"
ADD CONSTRAINT "FK_sync_field_enrichments_org" FOREIGN KEY ("organization_id") REFERENCES "organizations"("id") ON DELETE CASCADE ON UPDATE NO ACTION
`);
await queryRunner.query(`
ALTER TABLE "netsuite_schema_history"
ADD CONSTRAINT "FK_netsuite_schema_history_table_config" FOREIGN KEY ("table_config_history_id") REFERENCES "netsuite_schema_table_config_history"("id") ON DELETE
SET NULL ON UPDATE NO ACTION
`);
await queryRunner.query(`
ALTER TABLE "netsuite_schema_table_config_history"
ADD CONSTRAINT "FK_netsuite_schema_table_config_history_revision" FOREIGN KEY ("revision_id") REFERENCES "netsuite_schema_revision"("id") ON DELETE CASCADE ON UPDATE NO ACTION
`);
await queryRunner.query(`
ALTER TABLE "netsuite_schema_table_config_history"
ADD CONSTRAINT "FK_netsuite_schema_table_config_history_org" FOREIGN KEY ("organization_id") REFERENCES "organizations"("id") ON DELETE CASCADE ON UPDATE NO ACTION
`);
await queryRunner.query(`
ALTER TABLE "netsuite_schema"
ADD CONSTRAINT "FK_netsuite_schema_table_config" FOREIGN KEY ("table_config_id") REFERENCES "netsuite_schema_table_config"("id") ON DELETE
SET NULL ON UPDATE NO ACTION
`);
await queryRunner.query(`
ALTER TABLE "netsuite_schema_table_config"
ADD CONSTRAINT "FK_netsuite_schema_table_config_org" FOREIGN KEY ("organization_id") REFERENCES "organizations"("id") ON DELETE CASCADE ON UPDATE NO ACTION
`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment