1
0
forked from boos/BoosAPI

Add initial database schema and journal entries for token management

- Created a new snapshot JSON file (0003_snapshot.json) defining the schema for tables including account_tokens, accounts, checkin_logs, events, model_availability, proxy_logs, route_channels, settings, sites, token_model_availability, and token_routes.
- Added columns, indexes, and foreign key constraints for each table to ensure data integrity and relationships.
- Introduced a journal JSON file (_journal.json) to track schema versions and changes, including entries for version 6 with relevant tags and timestamps.
This commit is contained in:
cita
2026-02-28 22:20:28 +08:00
parent 2eeebbd686
commit 9405d468d9
8 changed files with 2177 additions and 1 deletions
+35
View File
@@ -0,0 +1,35 @@
CREATE TABLE IF NOT EXISTS `account_tokens` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`account_id` integer NOT NULL,
`name` text NOT NULL,
`token` text NOT NULL,
`source` text DEFAULT 'manual',
`enabled` integer DEFAULT true,
`is_default` integer DEFAULT false,
`created_at` text DEFAULT (datetime('now')),
`updated_at` text DEFAULT (datetime('now')),
FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
ALTER TABLE `route_channels` ADD COLUMN `token_id` integer;
--> statement-breakpoint
INSERT INTO `account_tokens` (`account_id`, `name`, `token`, `source`, `enabled`, `is_default`, `created_at`, `updated_at`)
SELECT
`a`.`id`,
'default',
`a`.`api_token`,
'legacy',
true,
true,
datetime('now'),
datetime('now')
FROM `accounts` AS `a`
WHERE
`a`.`api_token` IS NOT NULL
AND trim(`a`.`api_token`) <> ''
AND NOT EXISTS (
SELECT 1 FROM `account_tokens` AS `t`
WHERE `t`.`account_id` = `a`.`id`
AND `t`.`token` = `a`.`api_token`
);