Skip to content

Commit ae5d5ab

Browse files
committed
change the primary key to be more valid
chunk ids should only be unique to users, not necessarily across the whole server
1 parent c78b099 commit ae5d5ab

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ALTER TABLE chunks RENAME CONSTRAINT chunks_pkey TO chunks_pkeyold;
2+
CREATE UNIQUE INDEX chunks_pkey ON chunks (id, user_id);
3+
ALTER TABLE chunks DROP CONSTRAINT chunks_pkeyold;
4+
ALTER TABLE chunks ADD PRIMARY KEY USING INDEX chunks_pkey;
5+
ALTER TABLE chunks ADD CONSTRAINT unique_id_user_id UNIQUE (id, user_id);

src/meta_db.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl MetaDB for PostgresMetaDB {
153153
user_id: i64,
154154
) -> Result<Option<ChunkMetadata>> {
155155
Ok(sqlx::query(
156-
"select chunk_size, nonce, indice from chunks where id = $1 and user_id = $2",
156+
"select chunk_size, nonce, hash, indice from chunks where id = $1 and user_id = $2",
157157
)
158158
.bind(chunk_id.to_string())
159159
.bind(user_id)

0 commit comments

Comments
 (0)