Update test migrations

This commit is contained in:
Marshall Bowers 2026-05-29 17:58:07 -04:00
parent 4bcee26b08
commit a635de8e2f
4 changed files with 0 additions and 164 deletions

View file

@ -720,23 +720,6 @@ mod tests {
assert_eq!(restored.updated_at, original.updated_at);
}
#[test]
fn test_imported_flag_defaults_to_false() {
// Simulate deserializing a thread without the imported field (backwards compatibility).
let json = r#"{
"title": "Old Thread",
"messages": [],
"updated_at": "2024-01-01T00:00:00Z"
}"#;
let db_thread: DbThread = serde_json::from_str(json).expect("Failed to deserialize");
assert!(
!db_thread.imported,
"Legacy threads without imported field should default to false"
);
}
fn session_id(value: &str) -> acp::SessionId {
acp::SessionId::new(Arc::<str>::from(value))
}

View file

@ -434,14 +434,3 @@ CREATE TABLE IF NOT EXISTS "breakpoints" (
);
CREATE INDEX "index_breakpoints_on_project_id" ON "breakpoints" ("project_id");
CREATE TABLE IF NOT EXISTS "shared_threads" (
"id" TEXT PRIMARY KEY NOT NULL,
"user_id" INTEGER NOT NULL,
"title" VARCHAR(512) NOT NULL,
"data" BLOB NOT NULL,
"created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX "index_shared_threads_user_id" ON "shared_threads" ("user_id");

View file

@ -406,15 +406,6 @@ CREATE SEQUENCE public.servers_id_seq
ALTER SEQUENCE public.servers_id_seq OWNED BY public.servers.id;
CREATE TABLE public.shared_threads (
id uuid NOT NULL,
user_id integer NOT NULL,
title text NOT NULL,
data bytea NOT NULL,
created_at timestamp without time zone DEFAULT now() NOT NULL,
updated_at timestamp without time zone DEFAULT now() NOT NULL
);
CREATE TABLE public.users (
id integer NOT NULL,
github_login character varying,
@ -596,9 +587,6 @@ ALTER TABLE ONLY public.rooms
ALTER TABLE ONLY public.servers
ADD CONSTRAINT servers_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.shared_threads
ADD CONSTRAINT shared_threads_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.users
ADD CONSTRAINT users_pkey PRIMARY KEY (id);
@ -614,8 +602,6 @@ ALTER TABLE ONLY public.worktree_settings_files
ALTER TABLE ONLY public.worktrees
ADD CONSTRAINT worktrees_pkey PRIMARY KEY (project_id, id);
CREATE INDEX idx_shared_threads_user_id ON public.shared_threads USING btree (user_id);
CREATE INDEX index_breakpoints_on_project_id ON public.breakpoints USING btree (project_id);
CREATE INDEX index_buffers_on_channel_id ON public.buffers USING btree (channel_id);
@ -834,9 +820,6 @@ ALTER TABLE ONLY public.room_participants
ALTER TABLE ONLY public.rooms
ADD CONSTRAINT rooms_channel_id_fkey FOREIGN KEY (channel_id) REFERENCES public.channels(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.shared_threads
ADD CONSTRAINT shared_threads_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;
ALTER TABLE ONLY public.worktree_diagnostic_summaries
ADD CONSTRAINT worktree_diagnostic_summaries_project_id_worktree_id_fkey FOREIGN KEY (project_id, worktree_id) REFERENCES public.worktrees(project_id, id) ON DELETE CASCADE;

View file

@ -1,6 +1,5 @@
use crate::test_both_dbs;
use super::*;
use collab::db::RoomId;
use collab::db::*;
use pretty_assertions::assert_eq;
@ -257,121 +256,3 @@ async fn test_project_count(db: &Arc<Database>) {
.unwrap();
assert_eq!(db.project_count_excluding_admins().await.unwrap(), 0);
}
test_both_dbs!(
test_upsert_shared_thread,
test_upsert_shared_thread_postgres,
test_upsert_shared_thread_sqlite
);
async fn test_upsert_shared_thread(db: &Arc<Database>) {
use collab::db::SharedThreadId;
use uuid::Uuid;
let user_id = new_test_user(db, "user1@example.com").await;
let thread_id = SharedThreadId(Uuid::new_v4());
let title = "My Test Thread";
let data = b"test thread data".to_vec();
db.upsert_shared_thread(thread_id, user_id, title, data.clone())
.await
.unwrap();
let result = db.get_shared_thread(thread_id).await.unwrap();
assert!(result.is_some(), "Should find the shared thread");
let (thread, username) = result.unwrap();
assert_eq!(thread.title, title);
assert_eq!(thread.data, data);
assert_eq!(thread.user_id, user_id);
assert_eq!(username, "user1");
}
test_both_dbs!(
test_upsert_shared_thread_updates_existing,
test_upsert_shared_thread_updates_existing_postgres,
test_upsert_shared_thread_updates_existing_sqlite
);
async fn test_upsert_shared_thread_updates_existing(db: &Arc<Database>) {
use collab::db::SharedThreadId;
use uuid::Uuid;
let user_id = new_test_user(db, "user1@example.com").await;
let thread_id = SharedThreadId(Uuid::new_v4());
// Create initial thread.
db.upsert_shared_thread(
thread_id,
user_id,
"Original Title",
b"original data".to_vec(),
)
.await
.unwrap();
// Update the same thread.
db.upsert_shared_thread(
thread_id,
user_id,
"Updated Title",
b"updated data".to_vec(),
)
.await
.unwrap();
let result = db.get_shared_thread(thread_id).await.unwrap();
let (thread, _) = result.unwrap();
assert_eq!(thread.title, "Updated Title");
assert_eq!(thread.data, b"updated data".to_vec());
}
test_both_dbs!(
test_cannot_update_another_users_shared_thread,
test_cannot_update_another_users_shared_thread_postgres,
test_cannot_update_another_users_shared_thread_sqlite
);
async fn test_cannot_update_another_users_shared_thread(db: &Arc<Database>) {
use collab::db::SharedThreadId;
use uuid::Uuid;
let user1_id = new_test_user(db, "user1@example.com").await;
let user2_id = new_test_user(db, "user2@example.com").await;
let thread_id = SharedThreadId(Uuid::new_v4());
db.upsert_shared_thread(thread_id, user1_id, "User 1 Thread", b"user1 data".to_vec())
.await
.unwrap();
let result = db
.upsert_shared_thread(thread_id, user2_id, "User 2 Title", b"user2 data".to_vec())
.await;
assert!(
result.is_err(),
"Should not allow updating another user's thread"
);
}
test_both_dbs!(
test_get_nonexistent_shared_thread,
test_get_nonexistent_shared_thread_postgres,
test_get_nonexistent_shared_thread_sqlite
);
async fn test_get_nonexistent_shared_thread(db: &Arc<Database>) {
use collab::db::SharedThreadId;
use uuid::Uuid;
let result = db
.get_shared_thread(SharedThreadId(Uuid::new_v4()))
.await
.unwrap();
assert!(result.is_none(), "Should not find non-existent thread");
}