Initial commit: sap-intercompany-worker
Motor de escenarios de replicacion entre bases SAP Business One (Service Layer). Poll periodico sobre webhook_events, escenarios configurables via Prisma (filter + transform por escenario). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
commit
ca57403663
36 files changed
+5539
No files matched your search
@@ -0,0 +1,31 @@
|
||||
-- CreateEnum
|
||||
CREATE TYPE "EventStatus" AS ENUM ('pending', 'processing', 'done', 'partial', 'failed');
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "webhook_events" (
|
||||
"id" TEXT NOT NULL,
|
||||
"business_object" TEXT NOT NULL,
|
||||
"operation" TEXT NOT NULL,
|
||||
"subject" TEXT NOT NULL,
|
||||
"payload" JSONB NOT NULL,
|
||||
"received_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"status" "EventStatus" NOT NULL DEFAULT 'pending',
|
||||
|
||||
CONSTRAINT "webhook_events_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "replication_attempts" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"event_id" TEXT NOT NULL,
|
||||
"subsidiary" TEXT NOT NULL,
|
||||
"verb_used" TEXT NOT NULL,
|
||||
"http_status" INTEGER,
|
||||
"error_message" TEXT,
|
||||
"attempted_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "replication_attempts_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "replication_attempts" ADD CONSTRAINT "replication_attempts_event_id_fkey" FOREIGN KEY ("event_id") REFERENCES "webhook_events"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,83 @@
|
||||
-- CreateEnum
|
||||
CREATE TYPE "ReplicationRuleType" AS ENUM ('master', 'transaction');
|
||||
|
||||
-- AlterEnum
|
||||
ALTER TYPE "EventStatus" ADD VALUE 'filtered';
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "replication_attempts" ADD COLUMN "result_key" TEXT;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "subsidiaries" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"code" TEXT NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"base_url" TEXT NOT NULL,
|
||||
"company_db" TEXT NOT NULL,
|
||||
"username" TEXT NOT NULL,
|
||||
"password" TEXT NOT NULL,
|
||||
"routing_value" TEXT,
|
||||
"active" BOOLEAN NOT NULL DEFAULT true,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "subsidiaries_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "replication_rules" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"business_object" TEXT NOT NULL,
|
||||
"type" "ReplicationRuleType" NOT NULL,
|
||||
"key_field" TEXT,
|
||||
"routing_field" TEXT,
|
||||
"idempotency_field" TEXT,
|
||||
"active" BOOLEAN NOT NULL DEFAULT true,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "replication_rules_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "mapped_fields" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"business_object" TEXT NOT NULL,
|
||||
"field_name" TEXT NOT NULL,
|
||||
"active" BOOLEAN NOT NULL DEFAULT true,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "mapped_fields_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "reference_field_mappings" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"business_object" TEXT NOT NULL,
|
||||
"field_name" TEXT NOT NULL,
|
||||
"subsidiary_code" TEXT NOT NULL,
|
||||
"hq_value" TEXT NOT NULL,
|
||||
"subsidiary_value" TEXT NOT NULL,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "reference_field_mappings_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "subsidiaries_code_key" ON "subsidiaries"("code");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "subsidiaries_routing_value_key" ON "subsidiaries"("routing_value");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "replication_rules_business_object_key" ON "replication_rules"("business_object");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "mapped_fields_business_object_field_name_key" ON "mapped_fields"("business_object", "field_name");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "reference_field_mappings_business_object_field_name_subsidi_key" ON "reference_field_mappings"("business_object", "field_name", "subsidiary_code", "hq_value");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "reference_field_mappings" ADD CONSTRAINT "reference_field_mappings_subsidiary_code_fkey" FOREIGN KEY ("subsidiary_code") REFERENCES "subsidiaries"("code") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,144 @@
|
||||
-- CreateEnum
|
||||
CREATE TYPE "ScenarioDestinationMode" AS ENUM ('fixed', 'payload');
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "reference_field_mappings" DROP CONSTRAINT "reference_field_mappings_subsidiary_code_fkey";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "replication_attempts" DROP COLUMN "subsidiary",
|
||||
ADD COLUMN "destination_database" TEXT NOT NULL,
|
||||
ADD COLUMN "origin_database" TEXT NOT NULL,
|
||||
ADD COLUMN "payload_sent" JSONB,
|
||||
ADD COLUMN "scenario_id" INTEGER NOT NULL;
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "mapped_fields";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "reference_field_mappings";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "replication_rules";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "subsidiaries";
|
||||
|
||||
-- DropEnum
|
||||
DROP TYPE "ReplicationRuleType";
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "databases" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"code" TEXT NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"base_url" TEXT NOT NULL,
|
||||
"company_db" TEXT NOT NULL,
|
||||
"username" TEXT NOT NULL,
|
||||
"password" TEXT NOT NULL,
|
||||
"active" BOOLEAN NOT NULL DEFAULT true,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "databases_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "scenarios" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"code" TEXT NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"business_object" TEXT NOT NULL,
|
||||
"origin_database_code" TEXT NOT NULL,
|
||||
"destination_mode" "ScenarioDestinationMode" NOT NULL,
|
||||
"key_field" TEXT NOT NULL,
|
||||
"routing_field" TEXT,
|
||||
"filter_field" TEXT,
|
||||
"filter_operator" TEXT,
|
||||
"filter_value" TEXT,
|
||||
"active" BOOLEAN NOT NULL DEFAULT true,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "scenarios_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "scenario_destinations" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"scenario_id" INTEGER NOT NULL,
|
||||
"database_code" TEXT NOT NULL,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "scenario_destinations_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "scenario_mapped_fields" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"scenario_id" INTEGER NOT NULL,
|
||||
"field_name" TEXT NOT NULL,
|
||||
"active" BOOLEAN NOT NULL DEFAULT true,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "scenario_mapped_fields_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "scenario_value_mappings" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"scenario_id" INTEGER NOT NULL,
|
||||
"field_name" TEXT NOT NULL,
|
||||
"database_code" TEXT NOT NULL,
|
||||
"source_value" TEXT NOT NULL,
|
||||
"target_value" TEXT NOT NULL,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "scenario_value_mappings_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "databases_code_key" ON "databases"("code");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "scenarios_code_key" ON "scenarios"("code");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "scenario_destinations_scenario_id_database_code_key" ON "scenario_destinations"("scenario_id", "database_code");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "scenario_mapped_fields_scenario_id_field_name_key" ON "scenario_mapped_fields"("scenario_id", "field_name");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "scenario_value_mappings_scenario_id_field_name_database_cod_key" ON "scenario_value_mappings"("scenario_id", "field_name", "database_code", "source_value");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "replication_attempts_event_id_idx" ON "replication_attempts"("event_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "replication_attempts_scenario_id_idx" ON "replication_attempts"("scenario_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "replication_attempts_attempted_at_idx" ON "replication_attempts"("attempted_at");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "scenarios" ADD CONSTRAINT "scenarios_origin_database_code_fkey" FOREIGN KEY ("origin_database_code") REFERENCES "databases"("code") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "scenario_destinations" ADD CONSTRAINT "scenario_destinations_scenario_id_fkey" FOREIGN KEY ("scenario_id") REFERENCES "scenarios"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "scenario_destinations" ADD CONSTRAINT "scenario_destinations_database_code_fkey" FOREIGN KEY ("database_code") REFERENCES "databases"("code") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "scenario_mapped_fields" ADD CONSTRAINT "scenario_mapped_fields_scenario_id_fkey" FOREIGN KEY ("scenario_id") REFERENCES "scenarios"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "scenario_value_mappings" ADD CONSTRAINT "scenario_value_mappings_scenario_id_fkey" FOREIGN KEY ("scenario_id") REFERENCES "scenarios"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "scenario_value_mappings" ADD CONSTRAINT "scenario_value_mappings_database_code_fkey" FOREIGN KEY ("database_code") REFERENCES "databases"("code") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "replication_attempts" ADD CONSTRAINT "replication_attempts_scenario_id_fkey" FOREIGN KEY ("scenario_id") REFERENCES "scenarios"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "scenario_mapped_fields" DROP CONSTRAINT "scenario_mapped_fields_scenario_id_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "scenario_value_mappings" DROP CONSTRAINT "scenario_value_mappings_database_code_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "scenario_value_mappings" DROP CONSTRAINT "scenario_value_mappings_scenario_id_fkey";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "scenario_mapped_fields";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "scenario_value_mappings";
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
-- CreateEnum
|
||||
CREATE TYPE "ScenarioKeyStrategy" AS ENUM ('portable', 'udfLink');
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "scenarios" ADD COLUMN "key_strategy" "ScenarioKeyStrategy" NOT NULL DEFAULT 'portable',
|
||||
ADD COLUMN "match_field" TEXT;
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
-- CreateEnum
|
||||
CREATE TYPE "ScenarioKeyType" AS ENUM ('string', 'number');
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "scenarios" ADD COLUMN "key_type" "ScenarioKeyType" NOT NULL DEFAULT 'string';
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "scenario_value_mappings" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"scenario_id" INTEGER NOT NULL,
|
||||
"field_name" TEXT NOT NULL,
|
||||
"database_code" TEXT NOT NULL,
|
||||
"source_value" TEXT NOT NULL,
|
||||
"target_value" TEXT NOT NULL,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "scenario_value_mappings_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "scenario_value_mappings_scenario_id_field_name_database_cod_key" ON "scenario_value_mappings"("scenario_id", "field_name", "database_code", "source_value");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "scenario_value_mappings" ADD CONSTRAINT "scenario_value_mappings_scenario_id_fkey" FOREIGN KEY ("scenario_id") REFERENCES "scenarios"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "scenario_value_mappings" ADD CONSTRAINT "scenario_value_mappings_database_code_fkey" FOREIGN KEY ("database_code") REFERENCES "databases"("code") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "scenarios" DROP COLUMN "filter_field",
|
||||
DROP COLUMN "filter_operator",
|
||||
DROP COLUMN "filter_value";
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "scenarios" ADD COLUMN "destination_business_object" TEXT;
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
# Please do not edit this file manually
|
||||
# It should be added in your version-control system (e.g., Git)
|
||||
provider = "postgresql"
|
||||
Reference in new issue
Block a user