28 lines
1.1 KiB
SQL
28 lines
1.1 KiB
SQL
CREATE TABLE `measurement` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`hourId` text,
|
|
`dayId` text NOT NULL,
|
|
`metricId` text NOT NULL,
|
|
`createdAt` integer NOT NULL,
|
|
`userId` text NOT NULL,
|
|
`value` text NOT NULL,
|
|
FOREIGN KEY (`hourId`) REFERENCES `hour`(`id`) ON UPDATE no action ON DELETE no action,
|
|
FOREIGN KEY (`dayId`) REFERENCES `day`(`id`) ON UPDATE no action ON DELETE cascade,
|
|
FOREIGN KEY (`metricId`) REFERENCES `metric`(`id`) ON UPDATE no action ON DELETE cascade,
|
|
FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `metric` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`name` text NOT NULL,
|
|
`description` text,
|
|
`userId` text NOT NULL,
|
|
`type` text NOT NULL,
|
|
`unit` text,
|
|
`goal` real,
|
|
`createdAt` integer NOT NULL,
|
|
FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE UNIQUE INDEX `measurement_dayId_metricId_unique` ON `measurement` (`dayId`,`metricId`);--> statement-breakpoint
|
|
CREATE UNIQUE INDEX `metric_userId_name_unique` ON `metric` (`userId`,`name`); |