-- CreateTable: Company (sister companies for invoicing/accounting)
CREATE TABLE "Company" (
  "id"             TEXT NOT NULL,
  "name"           TEXT NOT NULL,
  "gstNumber"      TEXT,
  "address"        TEXT,
  "telephone"      TEXT,
  "mobile"         TEXT,
  "email"          TEXT,
  "invoiceAddress" TEXT,
  "isActive"       BOOLEAN NOT NULL DEFAULT true,
  "createdAt"      TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "updatedAt"      TIMESTAMP(3) NOT NULL,
  CONSTRAINT "Company_pkey" PRIMARY KEY ("id")
);

-- AlterTable: add optional companyId FK to PurchaseOrder
ALTER TABLE "PurchaseOrder" ADD COLUMN "companyId" TEXT;

ALTER TABLE "PurchaseOrder" ADD CONSTRAINT "PurchaseOrder_companyId_fkey"
  FOREIGN KEY ("companyId") REFERENCES "Company"("id") ON DELETE SET NULL ON UPDATE CASCADE;
