2025-01-29 03:03:11 +08:00
|
|
|
-- Your SQL goes here
|
|
|
|
-- Rename existing threads table to threads_deprecated
|
|
|
|
ALTER TABLE threads RENAME TO threads_deprecated;
|
|
|
|
|
|
|
|
-- Create new threads table with updated schema
|
2025-03-01 00:41:44 +08:00
|
|
|
CREATE TABLE chats(
|
2025-01-29 03:03:11 +08:00
|
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
|
|
title TEXT NOT NULL,
|
|
|
|
organization_id UUID NOT NULL REFERENCES organizations(id),
|
|
|
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
|
|
|
|
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
|
|
|
|
deleted_at TIMESTAMP WITH TIME ZONE,
|
2025-03-05 01:47:16 +08:00
|
|
|
created_by UUID NOT NULL REFERENCES users(id),
|
|
|
|
updated_by UUID NOT NULL REFERENCES users(id)
|
2025-01-29 03:03:11 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
-- Create indexes for common query patterns
|
2025-03-01 00:41:44 +08:00
|
|
|
CREATE INDEX chats_organization_id_idx ON chats(organization_id);
|
|
|
|
CREATE INDEX chats_created_by_idx ON chats(created_by);
|
|
|
|
CREATE INDEX chats_created_at_idx ON chats(created_at);
|