-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_PieceRemplacee" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "tenantId" TEXT NOT NULL,
    "ticketId" TEXT NOT NULL,
    "composant" TEXT NOT NULL,
    "fournisseurId" TEXT,
    "serieRetiree" TEXT,
    "serieInstallee" TEXT,
    CONSTRAINT "PieceRemplacee_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "PieceRemplacee_ticketId_fkey" FOREIGN KEY ("ticketId") REFERENCES "Ticket" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "PieceRemplacee_fournisseurId_fkey" FOREIGN KEY ("fournisseurId") REFERENCES "Fournisseur" ("id") ON DELETE SET NULL ON UPDATE CASCADE
);
INSERT INTO "new_PieceRemplacee" ("composant", "fournisseurId", "id", "serieInstallee", "serieRetiree", "tenantId", "ticketId") SELECT "composant", "fournisseurId", "id", "serieInstallee", "serieRetiree", "tenantId", "ticketId" FROM "PieceRemplacee";
DROP TABLE "PieceRemplacee";
ALTER TABLE "new_PieceRemplacee" RENAME TO "PieceRemplacee";
CREATE INDEX "PieceRemplacee_tenantId_idx" ON "PieceRemplacee"("tenantId");
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;
