CREATE TABLE ledger.transfer
(
  "transferId" bigserial NOT NULL,
  "paymentId" character varying(100) NOT NULL,
  "transferDate" timestamp without time zone NOT NULL,
  "transferTypeId" integer,
  "debitAccountId" integer NOT NULL,
  "debitIdentifier" varchar(256),
  "debitIdentifierType" varchar(3),
  "debitMemo" json,
  "creditAccountId" integer NOT NULL,
  "creditIdentifier" varchar(256),
  "creditIdentifierType" varchar(3),
  "creditMemo" json,
  "currencyId" character(3) NOT NULL,
  "fulfillment" character varying(100),
  "amount" numeric(19,2) NOT NULL,
  "description" text,
  "executionCondition"  character varying(100),
  "cancellationCondition"  character varying(100),
  "transferStateId"  int,
  "expiresAt" timestamp,
  "proposedAt" timestamp,
  "preparedAt" timestamp,
  "executedAt" timestamp,
  "rejectedAt" timestamp,
  "creationDate" timestamp without time zone NOT NULL,
  CONSTRAINT "pkLedgerTransfer" PRIMARY KEY ("transferId"),
  CONSTRAINT "ukLedgerTransfer" UNIQUE ("paymentId"),
  CONSTRAINT "fkLedgerTransfer_debitAccount" FOREIGN KEY ("debitAccountId") REFERENCES ledger.account ("accountId") MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "fkLedgerTransfer_creditAccount" FOREIGN KEY ("creditAccountId") REFERENCES ledger.account ("accountId") MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "fkLedgerTransfer_currency" FOREIGN KEY ("currencyId") REFERENCES ledger.currency ("currencyId") MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "fkLedgerTransfer_transferType" FOREIGN KEY ("transferTypeId") REFERENCES ledger."transferType" ("transferTypeId") MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "fkLedgerTransfer_transferState" FOREIGN KEY ("transferStateId") REFERENCES ledger."transferState" ("transferStateId") MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION
)
