mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-10-14 03:28:14 +00:00
feat(db): fix migration errors, explicitly migrate based on index
This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
PRAGMA foreign_keys=OFF;
|
||||
--> statement-breakpoint
|
||||
|
||||
CREATE TABLE `__new_messages` (
|
||||
`id` integer PRIMARY KEY NOT NULL,
|
||||
`type` text NOT NULL,
|
||||
`chatId` text NOT NULL,
|
||||
`createdAt` text DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
`messageId` text NOT NULL,
|
||||
`content` text,
|
||||
`sources` text DEFAULT '[]'
|
||||
);
|
||||
--> statement-breakpoint
|
||||
|
||||
INSERT INTO `__new_messages`("id", "type", "chatId", "createdAt", "messageId", "content", "sources")
|
||||
SELECT
|
||||
id,
|
||||
COALESCE(type, 'user') as type,
|
||||
chatId,
|
||||
CASE
|
||||
WHEN metadata IS NOT NULL AND instr(metadata, '\"createdAt\":\"') > 0 THEN
|
||||
substr(
|
||||
metadata,
|
||||
instr(metadata, '\"createdAt\":\"') + 14,
|
||||
CASE
|
||||
WHEN instr(substr(metadata, instr(metadata, '\"createdAt\":\"') + 14), '\"') > 0 THEN
|
||||
instr(substr(metadata, instr(metadata, '\"createdAt\":\"') + 14), '\"') - 1
|
||||
ELSE 24
|
||||
END
|
||||
)
|
||||
ELSE CURRENT_TIMESTAMP
|
||||
END as createdAt,
|
||||
messageId,
|
||||
content,
|
||||
'[]' as sources
|
||||
FROM `messages`;
|
||||
--> statement-breakpoint
|
||||
|
||||
DROP TABLE `messages`;
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE `__new_messages` RENAME TO `messages`;
|
||||
--> statement-breakpoint
|
||||
|
||||
PRAGMA foreign_keys=ON;
|
||||
--> statement-breakpoint
|
||||
|
||||
CREATE INDEX IF NOT EXISTS `idx_messages_chatId` ON `messages` (`chatId`);
|
||||
--> statement-breakpoint
|
||||
CREATE INDEX IF NOT EXISTS `idx_messages_type` ON `messages` (`type`);
|
||||
--> statement-breakpoint
|
||||
CREATE INDEX IF NOT EXISTS `idx_messages_createdAt` ON `messages` (`createdAt`);
|
1
drizzle/0001_wise_rockslide.sql
Normal file
1
drizzle/0001_wise_rockslide.sql
Normal file
@@ -0,0 +1 @@
|
||||
/* Do nothing */
|
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"version": "6",
|
||||
"dialect": "sqlite",
|
||||
"id": "766180d3-caab-4b9e-9f35-61ee7b652903",
|
||||
"id": "6dedf55f-0e44-478f-82cf-14a21ac686f8",
|
||||
"prevId": "ef3a044b-0f34-40b5-babb-2bb3a909ba27",
|
||||
"tables": {
|
||||
"chats": {
|
||||
|
@@ -12,8 +12,8 @@
|
||||
{
|
||||
"idx": 1,
|
||||
"version": "6",
|
||||
"when": 1756793457846,
|
||||
"tag": "0001_acoustic_wild_pack",
|
||||
"when": 1758863991284,
|
||||
"tag": "0001_wise_rockslide",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
|
Reference in New Issue
Block a user