CREATE TABLE `delas` (
	`ID` integer PRIMARY KEY,
	`dID` text NOT NULL UNIQUE,
	`name` text NOT NULL,
	`location` text NOT NULL,
	`revolutUsername` text NOT NULL,
	`date` integer NOT NULL,
	`createdAt` integer NOT NULL
);
--> statement-breakpoint
CREATE TABLE `items` (
	`ID` integer PRIMARY KEY,
	`delaID` integer NOT NULL,
	`name` text NOT NULL,
	`price` integer NOT NULL,
	`splits` integer NOT NULL,
	CONSTRAINT `fk_items_delaID_delas_ID_fk` FOREIGN KEY (`delaID`) REFERENCES `delas`(`ID`) ON DELETE CASCADE
);
--> statement-breakpoint
CREATE TABLE `participants` (
	`ID` integer PRIMARY KEY,
	`parID` text NOT NULL UNIQUE,
	`delaID` integer NOT NULL,
	`username` text NOT NULL,
	CONSTRAINT `fk_participants_delaID_delas_ID_fk` FOREIGN KEY (`delaID`) REFERENCES `delas`(`ID`) ON DELETE CASCADE
);
--> statement-breakpoint
CREATE TABLE `paymentItems` (
	`paymentID` integer NOT NULL,
	`itemID` integer NOT NULL,
	`splitsPaid` integer NOT NULL,
	CONSTRAINT `paymentItems_pk` PRIMARY KEY(`paymentID`, `itemID`),
	CONSTRAINT `fk_paymentItems_paymentID_payments_ID_fk` FOREIGN KEY (`paymentID`) REFERENCES `payments`(`ID`) ON DELETE CASCADE,
	CONSTRAINT `fk_paymentItems_itemID_items_ID_fk` FOREIGN KEY (`itemID`) REFERENCES `items`(`ID`) ON DELETE CASCADE
);
--> statement-breakpoint
CREATE TABLE `payments` (
	`ID` integer PRIMARY KEY,
	`parID` integer NOT NULL UNIQUE,
	`payID` text NOT NULL UNIQUE,
	`status` text DEFAULT 'unpaid' NOT NULL,
	`createdAt` integer NOT NULL,
	`updatedAt` integer NOT NULL
);
--> statement-breakpoint
CREATE TABLE `users` (
	`ID` integer PRIMARY KEY,
	`token` text NOT NULL UNIQUE,
	`createdAt` integer NOT NULL
);
