feat(api): add teams CRUD routes and update auth team references

This commit is contained in:
Siddharth Kumar Sah
2026-03-26 01:10:51 +08:00
parent 62fbb5484c
commit ab370a74fe
5 changed files with 893 additions and 206 deletions
+4 -3
View File
@@ -4,18 +4,19 @@ CREATE TABLE IF NOT EXISTS `teams` (
`name` text NOT NULL,
`created_at` integer NOT NULL DEFAULT (unixepoch())
);
--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS `teams_name_unique` ON `teams` (`name`);
--> statement-breakpoint
-- Seed Default team with a known UUID
INSERT OR IGNORE INTO `teams` (`id`, `name`, `created_at`) VALUES ('default-team-00000000', 'Default', unixepoch());
--> statement-breakpoint
-- Migrate existing users: for each distinct team value, create a team if it doesn't exist
INSERT OR IGNORE INTO `teams` (`id`, `name`, `created_at`)
SELECT lower(hex(randomblob(16))), `team`, unixepoch()
FROM `users`
WHERE `team` != 'Default'
GROUP BY `team`;
--> statement-breakpoint
-- Update users to reference team IDs instead of team names
UPDATE `users` SET `team` = (
SELECT `id` FROM `teams` WHERE `teams`.`name` = `users`.`team`