Skip to content

Commit

Permalink
change the primary key to be more valid
Browse files Browse the repository at this point in the history
chunk ids should only be unique to users, not necessarily across the
whole server
  • Loading branch information
billyb2 committed Aug 18, 2024
1 parent c78b099 commit ae5d5ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions migrations/20240818052859_better_primary_key.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE chunks RENAME CONSTRAINT chunks_pkey TO chunks_pkeyold;
CREATE UNIQUE INDEX chunks_pkey ON chunks (id, user_id);
ALTER TABLE chunks DROP CONSTRAINT chunks_pkeyold;
ALTER TABLE chunks ADD PRIMARY KEY USING INDEX chunks_pkey;
ALTER TABLE chunks ADD CONSTRAINT unique_id_user_id UNIQUE (id, user_id);
2 changes: 1 addition & 1 deletion src/meta_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl MetaDB for PostgresMetaDB {
user_id: i64,
) -> Result<Option<ChunkMetadata>> {
Ok(sqlx::query(
"select chunk_size, nonce, indice from chunks where id = $1 and user_id = $2",
"select chunk_size, nonce, hash, indice from chunks where id = $1 and user_id = $2",
)
.bind(chunk_id.to_string())
.bind(user_id)
Expand Down

0 comments on commit ae5d5ab

Please sign in to comment.