32 lines
1.1 KiB
SQL
32 lines
1.1 KiB
SQL
CREATE TABLE `devices` (
|
|
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
`user_id` text NOT NULL,
|
|
`name` text NOT NULL,
|
|
`opnsense_id` text,
|
|
`public_key` text NOT NULL,
|
|
`private_key` text,
|
|
`pre_shared_key` text,
|
|
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE UNIQUE INDEX `devices_public_key_unique` ON `devices` (`public_key`);--> statement-breakpoint
|
|
CREATE TABLE `ip_allocations` (
|
|
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
`device_id` integer,
|
|
FOREIGN KEY (`device_id`) REFERENCES `devices`(`id`) ON UPDATE no action ON DELETE set null
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE UNIQUE INDEX `ip_allocations_device_id_unique` ON `ip_allocations` (`device_id`);--> statement-breakpoint
|
|
CREATE TABLE `sessions` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`user_id` text NOT NULL,
|
|
`expires_at` integer NOT NULL,
|
|
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE `users` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`username` text NOT NULL,
|
|
`name` text NOT NULL
|
|
);
|