wip: improve invoice generation logic

This commit is contained in:
2025-08-14 20:00:21 +01:00
parent a85e13e17d
commit 7f4da2f606
10 changed files with 165 additions and 42 deletions
+23
View File
@@ -0,0 +1,23 @@
-- Disable the enforcement of foreign-keys constraints
PRAGMA foreign_keys = off;
-- Create "new_items" table
CREATE TABLE `new_items` (
`id` varchar NULL,
`invoice_id` varchar NULL,
`user_id` varchar NULL,
`name` text NULL,
`type` text NULL,
`price` real NULL,
`quantity` integer NULL,
`tax` integer NULL,
PRIMARY KEY (`id`),
CONSTRAINT `fk_invoices_items` FOREIGN KEY (`invoice_id`) REFERENCES `invoices` (`id`) ON UPDATE NO ACTION ON DELETE NO ACTION
);
-- Copy rows from old table "items" to new temporary table "new_items"
INSERT INTO `new_items` (`id`, `invoice_id`, `user_id`, `name`, `type`, `price`, `quantity`, `tax`) SELECT `id`, `invoice_id`, `user_id`, `name`, `type`, `price`, `quantity`, `tax` FROM `items`;
-- Drop "items" table after copying rows
DROP TABLE `items`;
-- Rename temporary table "new_items" to "items"
ALTER TABLE `new_items` RENAME TO `items`;
-- Enable back the enforcement of foreign-keys constraints
PRAGMA foreign_keys = on;
+2 -1
View File
@@ -1,5 +1,6 @@
h1:dDD/MWKqjFIkCAuR4i/9LtH4ibg9wZR03FApuHHYCos=
h1:wDAImuaIK9lhzbnQ3++MNijLAxUnoaLdlysqqYjOfoU=
20250611102124.sql h1:HkDgtWXUxfAR9gIObTMzP98pVEIakerASGGSufW695k=
20250616102420.sql h1:7C1kEskaDwdHmQOu3t48oZcky0WaNiFeIugJcJFkjKM=
20250616150439.sql h1:nx8CvH5om7lbeEezo7roNcTV+f0agch0gBjYxKtTDn8=
20250616151658.sql h1:O4hbYFj4bwMDML0mR9PtSn7GUbXQVCbh+lGkwTNBwnU=
20250814173803.sql h1:xRBhN15wPcJJOfzzPuMoUJsUqEYNCdLmEBiYUJBF1FA=