/*
  Warnings:

  - You are about to drop the column `inventoryId` on the `Sales_Invoices` table. All the data in the column will be lost.
  - Added the required column `posAccountId` to the `Sales_Invoices` table without a default value. This is not possible if the table is not empty.

*/
-- DropForeignKey
ALTER TABLE `Sales_Invoices` DROP FOREIGN KEY `Sales_Invoices_inventoryId_fkey`;

-- DropIndex
DROP INDEX `Sales_Invoices_inventoryId_fkey` ON `Sales_Invoices`;

-- AlterTable
ALTER TABLE `Purchase_Receipt_Payments` ADD COLUMN `inventoryBankAccountBankAccountId` INTEGER NULL,
    ADD COLUMN `inventoryBankAccountInventoryId` INTEGER NULL;

-- AlterTable
ALTER TABLE `Sales_Invoices` DROP COLUMN `inventoryId`,
    ADD COLUMN `posAccountId` INTEGER NOT NULL;

-- CreateIndex
CREATE INDEX `Sales_Invoices_posAccountId_idx` ON `Sales_Invoices`(`posAccountId`);

-- AddForeignKey
ALTER TABLE `Sales_Invoices` ADD CONSTRAINT `Sales_Invoices_posAccountId_fkey` FOREIGN KEY (`posAccountId`) REFERENCES `Pos_Accounts`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Purchase_Receipt_Payments` ADD CONSTRAINT `Purchase_Receipt_Payments_inventoryBankAccountInventoryId_i_fkey` FOREIGN KEY (`inventoryBankAccountInventoryId`, `inventoryBankAccountBankAccountId`) REFERENCES `Inventory_Bank_Accounts`(`inventoryId`, `bankAccountId`) ON DELETE SET NULL ON UPDATE CASCADE;

-- RenameIndex
ALTER TABLE `Orders` RENAME INDEX `Orders_customerId_fkey` TO `Orders_customerId_idx`;

-- RenameIndex
ALTER TABLE `Product_Variants` RENAME INDEX `products_barcode_unique` TO `Product_Variants_barcode_key`;

-- RenameIndex
ALTER TABLE `Products` RENAME INDEX `products_barcode_unique` TO `Products_barcode_key`;

-- RenameIndex
ALTER TABLE `Products` RENAME INDEX `products_sku_unique` TO `Products_sku_key`;

-- RenameIndex
ALTER TABLE `Sales_Invoice_Items` RENAME INDEX `Sales_Invoice_Items_invoiceId_fkey` TO `Sales_Invoice_Items_invoiceId_idx`;

-- RenameIndex
ALTER TABLE `Sales_Invoice_Items` RENAME INDEX `Sales_Invoice_Items_productId_fkey` TO `Sales_Invoice_Items_productId_idx`;

-- RenameIndex
ALTER TABLE `Sales_Invoices` RENAME INDEX `Sales_Invoices_customerId_fkey` TO `Sales_Invoices_customerId_idx`;
