-- CreateTable CREATE TABLE "suppliers" ( "id" UUID NOT NULL, "code" TEXT NOT NULL, "name" TEXT NOT NULL, "short_name" TEXT, "tax_no" TEXT, "contact_name" TEXT, "contact_phone" TEXT, "payment_terms" TEXT, "legal_entity_id" UUID, "enabled" BOOLEAN NOT NULL DEFAULT true, "archived_at" TIMESTAMP(3), "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "created_by" UUID, "updated_at" TIMESTAMP(3) NOT NULL, "updated_by" UUID, CONSTRAINT "suppliers_pkey" PRIMARY KEY ("id") ); -- CreateIndex CREATE UNIQUE INDEX "suppliers_code_key" ON "suppliers"("code"); -- CreateIndex CREATE INDEX "idx_suppliers_legal_entity_status" ON "suppliers"("legal_entity_id", "enabled", "archived_at"); -- CreateIndex CREATE INDEX "idx_suppliers_name" ON "suppliers"("name"); -- AddForeignKey ALTER TABLE "suppliers" ADD CONSTRAINT "suppliers_legal_entity_id_fkey" FOREIGN KEY ("legal_entity_id") REFERENCES "legal_entities"("id") ON DELETE SET NULL ON UPDATE CASCADE;