|
1 |
| --- Remove the created_at column |
2 |
| -ALTER TABLE chat_messages |
3 |
| -DROP COLUMN IF EXISTS created_at; |
| 1 | +DROP TABLE IF EXISTS chat_messages; |
4 | 2 |
|
5 |
| --- Add back message_type and message_index (assuming previous state was TEXT and SERIAL) |
6 |
| -ALTER TABLE chat_messages |
7 |
| -ADD COLUMN IF NOT EXISTS message_type TEXT NOT NULL DEFAULT '', -- Provide a default or handle NULLs |
8 |
| -ADD COLUMN IF NOT EXISTS message_index SERIAL; |
9 |
| - |
10 |
| --- Change content back to TEXT (data loss may occur if JSONB data is not representable as TEXT) |
11 |
| -ALTER TABLE chat_messages |
12 |
| -ALTER COLUMN content TYPE TEXT 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 |
| -ALTER TABLE chat_messages DROP CONSTRAINT IF EXISTS chat_messages_pkey; |
18 |
| -DROP SEQUENCE IF EXISTS chat_messages_id_seq; |
19 |
| -ALTER TABLE chat_messages ALTER COLUMN id DROP DEFAULT; |
20 |
| -ALTER TABLE chat_messages ALTER COLUMN id TYPE UUID USING (gen_random_uuid()); -- Attempt conversion, may fail |
21 |
| -ALTER TABLE chat_messages ALTER COLUMN id SET DEFAULT gen_random_uuid(); |
22 |
| -ALTER TABLE chat_messages ADD PRIMARY KEY (id); |
23 |
| - |
24 |
| --- Revert changes to chat_conversations (removing deleted_at) |
25 |
| -ALTER TABLE chat_conversations |
26 |
| -DROP COLUMN IF EXISTS deleted_at; |
27 |
| -ALTER TABLE chat_conversations DROP CONSTRAINT IF EXISTS chat_conversations_user_id_fkey; |
28 |
| -ALTER TABLE chat_conversations ADD CONSTRAINT chat_conversations_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id); |
29 |
| -ALTER TABLE chat_conversations ALTER COLUMN created_at SET DEFAULT CURRENT_TIMESTAMP; |
30 |
| -ALTER TABLE chat_conversations ALTER COLUMN updated_at SET DEFAULT CURRENT_TIMESTAMP; |
31 |
| - |
32 |
| --- Revert changes to chat_messages (removing ON DELETE CASCADE) |
33 |
| -ALTER TABLE chat_messages DROP CONSTRAINT IF EXISTS chat_messages_conversation_id_fkey; |
34 |
| -ALTER TABLE chat_messages ADD CONSTRAINT chat_messages_conversation_id_fkey FOREIGN KEY (conversation_id) REFERENCES chat_conversations(id); |
| 3 | +DROP TABLE IF EXISTS chats; |
0 commit comments