CREATE TABLE `consumers` (
	`id` text PRIMARY KEY NOT NULL,
	`project_id` text NOT NULL,
	`distribution_board_id` text,
	`name` text NOT NULL,
	`category` text,
	`quantity` integer NOT NULL,
	`installed_power_per_unit_kw` real NOT NULL,
	`demand_factor` real NOT NULL,
	`voltage_v` real,
	`phase_count` integer,
	`power_factor` real,
	`note` text,
	FOREIGN KEY (`project_id`) REFERENCES `projects`(`id`) ON UPDATE no action ON DELETE cascade,
	FOREIGN KEY (`distribution_board_id`) REFERENCES `distribution_boards`(`id`) ON UPDATE no action ON DELETE set null
);
--> statement-breakpoint
CREATE TABLE `distribution_boards` (
	`id` text PRIMARY KEY NOT NULL,
	`project_id` text NOT NULL,
	`name` text NOT NULL,
	FOREIGN KEY (`project_id`) REFERENCES `projects`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE TABLE `projects` (
	`id` text PRIMARY KEY NOT NULL,
	`name` text NOT NULL
);
