Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfb58caa

Browse files
committed
fix(coderd/database): fix down migration and add fixture
1 parentb390e56 commitfb58caa

File tree

2 files changed

+8
-33
lines changed

2 files changed

+8
-33
lines changed
Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,3 @@
1-
-- Remove the created_at column
2-
ALTERTABLE chat_messages
3-
DROP COLUMN IF EXISTS created_at;
1+
DROPTABLE IF EXISTS chat_messages;
42

5-
-- Add back message_type and message_index (assuming previous state was TEXT and SERIAL)
6-
ALTERTABLE chat_messages
7-
ADD COLUMN IF NOT EXISTS message_typeTEXTNOT NULL DEFAULT'',-- Provide a default or handle NULLs
8-
ADD COLUMN IF NOT EXISTS message_indexSERIAL;
9-
10-
-- Change content back to TEXT (data loss may occur if JSONB data is not representable as TEXT)
11-
ALTERTABLE chat_messages
12-
ALTER COLUMN content TYPETEXT USING content::TEXT;
13-
14-
-- Attempt to revert id back to UUID with default
15-
-- WARNING: This is complex and potentially destructive. It might fail if data exists.
16-
-- It drops the existing primary key, sequence, and default, then attempts to set a new one.
17-
ALTERTABLE chat_messages DROPCONSTRAINT IF EXISTS chat_messages_pkey;
18-
DROPSEQUENCE IF EXISTS chat_messages_id_seq;
19-
ALTERTABLE chat_messages ALTER COLUMN id DROP DEFAULT;
20-
ALTERTABLE chat_messages ALTER COLUMN id TYPE UUID USING (gen_random_uuid());-- Attempt conversion, may fail
21-
ALTERTABLE chat_messages ALTER COLUMN idSET DEFAULT gen_random_uuid();
22-
ALTERTABLE chat_messages ADDPRIMARY KEY (id);
23-
24-
-- Revert changes to chat_conversations (removing deleted_at)
25-
ALTERTABLE chat_conversations
26-
DROP COLUMN IF EXISTS deleted_at;
27-
ALTERTABLE chat_conversations DROPCONSTRAINT IF EXISTS chat_conversations_user_id_fkey;
28-
ALTERTABLE chat_conversations ADDCONSTRAINT chat_conversations_user_id_fkeyFOREIGN KEY (user_id)REFERENCES users(id);
29-
ALTERTABLE chat_conversations ALTER COLUMN created_atSET DEFAULTCURRENT_TIMESTAMP;
30-
ALTERTABLE chat_conversations ALTER COLUMN updated_atSET DEFAULTCURRENT_TIMESTAMP;
31-
32-
-- Revert changes to chat_messages (removing ON DELETE CASCADE)
33-
ALTERTABLE chat_messages DROPCONSTRAINT IF EXISTS chat_messages_conversation_id_fkey;
34-
ALTERTABLE chat_messages ADDCONSTRAINT chat_messages_conversation_id_fkeyFOREIGN KEY (conversation_id)REFERENCES chat_conversations(id);
3+
DROPTABLE IF EXISTS chats;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
INSERT INTO chats (id, owner_id, created_at, updated_at, title)VALUES
2+
('00000000-0000-0000-0000-000000000001','0ed9befc-4911-4ccf-a8e2-559bf72daa94','2023-10-01 12:00:00+00','2023-10-01 12:00:00+00','Test Chat 1');
3+
4+
INSERT INTO chat_messages (id, chat_id, created_at, model, provider, content)VALUES
5+
(1,'00000000-0000-0000-0000-000000000001','2023-10-01 12:00:00+00','annie-oakley','cowboy-coder','{"role":"user","content":"Hello"}'),
6+
(2,'00000000-0000-0000-0000-000000000001','2023-10-01 12:01:00+00','annie-oakley','cowboy-coder','{"role":"assistant","content":"Howdy pardner! What can I do ya for?"}');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp