mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-10-13 19:18:14 +00:00
feat(db): add migrations
This commit is contained in:
51
drizzle/0001_acoustic_wild_pack.sql
Normal file
51
drizzle/0001_acoustic_wild_pack.sql
Normal file
@@ -0,0 +1,51 @@
|
||||
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`);
|
125
drizzle/meta/0001_snapshot.json
Normal file
125
drizzle/meta/0001_snapshot.json
Normal file
@@ -0,0 +1,125 @@
|
||||
{
|
||||
"version": "6",
|
||||
"dialect": "sqlite",
|
||||
"id": "766180d3-caab-4b9e-9f35-61ee7b652903",
|
||||
"prevId": "ef3a044b-0f34-40b5-babb-2bb3a909ba27",
|
||||
"tables": {
|
||||
"chats": {
|
||||
"name": "chats",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"title": {
|
||||
"name": "title",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"createdAt": {
|
||||
"name": "createdAt",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"focusMode": {
|
||||
"name": "focusMode",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"files": {
|
||||
"name": "files",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"default": "'[]'"
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"messages": {
|
||||
"name": "messages",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"type": {
|
||||
"name": "type",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"chatId": {
|
||||
"name": "chatId",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"createdAt": {
|
||||
"name": "createdAt",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "CURRENT_TIMESTAMP"
|
||||
},
|
||||
"messageId": {
|
||||
"name": "messageId",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"content": {
|
||||
"name": "content",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"sources": {
|
||||
"name": "sources",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"default": "'[]'"
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
}
|
||||
},
|
||||
"views": {},
|
||||
"enums": {},
|
||||
"_meta": {
|
||||
"schemas": {},
|
||||
"tables": {},
|
||||
"columns": {}
|
||||
},
|
||||
"internal": {
|
||||
"indexes": {}
|
||||
}
|
||||
}
|
@@ -8,6 +8,13 @@
|
||||
"when": 1748405503809,
|
||||
"tag": "0000_fuzzy_randall",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"version": "6",
|
||||
"when": 1756793457846,
|
||||
"tag": "0001_acoustic_wild_pack",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@@ -6,14 +6,14 @@ export const messages = sqliteTable('messages', {
|
||||
id: integer('id').primaryKey(),
|
||||
role: text('type', { enum: ['assistant', 'user', 'source'] }).notNull(),
|
||||
chatId: text('chatId').notNull(),
|
||||
createdAt: text('createdAt').notNull(),
|
||||
createdAt: text('createdAt').notNull().default(sql`CURRENT_TIMESTAMP`),
|
||||
messageId: text('messageId').notNull(),
|
||||
|
||||
content: text('content'),
|
||||
|
||||
sources: text('sources', {
|
||||
mode: 'json',
|
||||
}).$type<Document[]>(),
|
||||
}).$type<Document[]>().default(sql`'[]'`),
|
||||
});
|
||||
|
||||
interface File {
|
||||
|
Reference in New Issue
Block a user