

-- Drop triggers
DROP TRIGGER IF EXISTS "log_user_updates";
DROP TRIGGER IF EXISTS "log_user_deletes";
DROP TRIGGER IF EXISTS "log_user_inserts";

-- Clean up unused space
VACUUM;

CREATE TABLE "items" (
    "id" INTEGER,
    "name" TEXT NOT NULL UNIQUE,
    "price" NUMERIC NOT NULL,
    PRIMARY KEY("id")
);

CREATE TABLE "orders" (
    "id" INTEGER,
    "user_id" INTEGER,
    "item_id" INTEGER,
    "quantity" INTEGER NOT NULL CHECK("quantity" > 0),
    PRIMARY KEY("id"),
    FOREIGN KEY("user_id") REFERENCES "users"("id"),
    FOREIGN KEY("item_id") REFERENCES "items"("id")
);
END;
END;
END;

INSERT INTO "items" ("id", "name", "price")
VALUES ('1', 'CS50 Rubber Duck', '4.99'),
('2', 'CS50 Pen', '4.99'),
('3', 'CS50 Sunglasses', '9.99'),
('4', 'CS50 Unisex T-Shirt', '30.00'),
('5', 'CS50 Hoodie', '42.00'),
('6', 'CS50 Toddler Shirt', '20.00'),
('7', 'CS50 Pillow', '28.00'),
('8', 'CS50 Mug', '14.00'),
('9', 'CS50 Embroidered Beanie', '24.00'),
('10', 'CS50 Kids T-Shirt', '25.00');

INSERT INTO "orders" ("id", "user_id", "item_id", "quantity")
VALUES ('1', '37', '5', '1'),
('2', '33', '5', '7'),
('3', '38', '6', '10'),
('4', '48', '3', '5'),
('5', '27', '6', '7'),
('6', '24', '6', '1'),
('7', '20', '9', '3'),
('8', '45', '1', '1'),
('9', '14', '8', '7'),
('10', '21', '10', '9'),
('11', '21', '10', '4'),
('12', '31', '4', '10'),
('13', '31', '6', '6'),
('14', '41', '2', '4'),
('15', '35', '8', '3'),
('16', '5', '10', '3'),
('17', '7', '2', '1'),
('18', '44', '3', '5'),
('19', '34', '1', '8'),
('20', '29', '8', '6'),
('21', '8', '8', '8'),
('22', '9', '5', '8'),
('23', '10', '3', '10'),
('24', '39', '5', '4'),
('25', '24', '10', '2'),
('26', '44', '9', '2'),
('27', '37', '6', '3'),
('28', '44', '2', '1'),
('29', '28', '5', '2'),
('30', '35', '3', '9'),
('31', '11', '3', '3'),
('32', '42', '3', '9'),
('33', '20', '4', '3'),
('34', '38', '10', '4'),
('35', '34', '3', '5'),
('36', '26', '7', '9'),
('37', '23', '8', '4'),
('38', '27', '6', '3'),
('39', '10', '5', '7'),
('40', '11', '10', '5'),
('41', '34', '2', '4'),
('42', '5', '6', '1'),
('43', '11', '7', '6'),
('44', '45', '5', '1'),
('45', '18', '4', '10'),
('46', '16', '6', '5'),
('47', '7', '5', '6'),
('48', '19', '6', '1'),
('49', '34', '5', '5'),
('50', '29', '5', '4'),
('51', '22', '8', '5'),
('52', '35', '4', '9'),
('53', '6', '3', '5'),
('54', '26', '10', '5'),
('55', '38', '3', '2'),
('56', '9', '9', '4'),
('57', '36', '5', '3'),
('58', '25', '5', '8'),
('59', '39', '5', '3'),
('60', '46', '1', '3'),
('61', '49', '6', '1'),
('62', '7', '8', '4'),
('63', '5', '9', '10'),
('64', '10', '2', '5'),
('65', '29', '7', '3'),
('66', '18', '1', '3'),
('67', '3', '3', '2'),
('68', '38', '6', '10'),
('69', '38', '6', '4'),
('70', '13', '7', '6'),
('71', '10', '1', '8'),
('72', '8', '10', '8'),
('73', '20', '4', '6'),
('74', '30', '6', '6'),
('75', '29', '7', '6'),
('76', '3', '6', '3'),
('77', '20', '10', '5'),
('78', '2', '7', '9'),
('79', '23', '9', '1'),
('80', '19', '2', '3'),
('81', '20', '3', '9'),
('82', '40', '4', '8'),
('83', '40', '4', '8'),
('84', '10', '6', '6'),
('85', '10', '9', '3'),
('86', '14', '10', '2'),
('87', '19', '3', '4'),
('88', '5', '10', '4'),
('89', '8', '3', '6'),
('90', '18', '7', '4'),
('91', '4', '5', '9'),
('92', '3', '3', '4'),
('93', '37', '6', '5'),
('94', '13', '5', '1'),
('95', '5', '8', '8'),
('96', '28', '6', '1'),
('97', '22', '3', '8'),
('98', '35', '6', '6'),
('99', '44', '5', '4'),
('100', '29', '5', '7');