mirror of
https://github.com/nicotsx/zerobyte.git
synced 2026-02-14 15:31:40 -05:00
* feat(db): add support for multiple users and organizations * feat: backfill entities with new organization id * refactor: filter all backend queries to surface only organization specific entities * refactor: each org has its own restic password * test: ensure organization is created * chore: pr feedbacks * refactor: filter by org id in all places * refactor: download restic password from stored db password * refactor(navigation): use volume id in urls instead of name * feat: disable registrations * refactor(auth): bubble up auth error to hono * refactor: use async local storage for cleaner context sharing * refactor: enable user registration vs disabling it * test: multi-org isolation * chore: final cleanup
44 lines
2.1 KiB
SQL
44 lines
2.1 KiB
SQL
CREATE TABLE `invitation` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`organization_id` text NOT NULL,
|
|
`email` text NOT NULL,
|
|
`role` text,
|
|
`status` text DEFAULT 'pending' NOT NULL,
|
|
`expires_at` integer NOT NULL,
|
|
`created_at` integer NOT NULL,
|
|
`inviter_id` text NOT NULL,
|
|
FOREIGN KEY (`organization_id`) REFERENCES `organization`(`id`) ON UPDATE no action ON DELETE cascade,
|
|
FOREIGN KEY (`inviter_id`) REFERENCES `users_table`(`id`) ON UPDATE no action ON DELETE cascade
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE INDEX `invitation_organizationId_idx` ON `invitation` (`organization_id`);--> statement-breakpoint
|
|
CREATE INDEX `invitation_email_idx` ON `invitation` (`email`);--> statement-breakpoint
|
|
CREATE TABLE `member` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`organization_id` text NOT NULL,
|
|
`user_id` text NOT NULL,
|
|
`role` text DEFAULT 'member' NOT NULL,
|
|
`created_at` integer NOT NULL,
|
|
FOREIGN KEY (`organization_id`) REFERENCES `organization`(`id`) ON UPDATE no action ON DELETE cascade,
|
|
FOREIGN KEY (`user_id`) REFERENCES `users_table`(`id`) ON UPDATE no action ON DELETE cascade
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE INDEX `member_organizationId_idx` ON `member` (`organization_id`);--> statement-breakpoint
|
|
CREATE INDEX `member_userId_idx` ON `member` (`user_id`);--> statement-breakpoint
|
|
CREATE TABLE `organization` (
|
|
`id` text PRIMARY KEY NOT NULL,
|
|
`name` text NOT NULL,
|
|
`slug` text NOT NULL,
|
|
`logo` text,
|
|
`created_at` integer NOT NULL,
|
|
`metadata` text
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE UNIQUE INDEX `organization_slug_unique` ON `organization` (`slug`);--> statement-breakpoint
|
|
CREATE UNIQUE INDEX `organization_slug_uidx` ON `organization` (`slug`);--> statement-breakpoint
|
|
ALTER TABLE `sessions_table` ADD `impersonated_by` text;--> statement-breakpoint
|
|
ALTER TABLE `sessions_table` ADD `active_organization_id` text;--> statement-breakpoint
|
|
ALTER TABLE `users_table` ADD `role` text;--> statement-breakpoint
|
|
ALTER TABLE `users_table` ADD `banned` integer DEFAULT false;--> statement-breakpoint
|
|
ALTER TABLE `users_table` ADD `ban_reason` text;--> statement-breakpoint
|
|
ALTER TABLE `users_table` ADD `ban_expires` integer; |