make account names unique per user not globally

This commit is contained in:
DSeeLP 2025-03-11 11:12:56 +01:00
parent a4e233398f
commit 83c5768935
5 changed files with 11 additions and 14 deletions

View File

@ -7,8 +7,9 @@ create table users(
create table accounts(
id uuid primary key,
"user" uuid not null references users(id),
name varchar(32) not null unique,
balance bigint not null default 0 constraint positive_balance check (balance >= 0)
name varchar(32) not null,
balance bigint not null default 0 constraint positive_balance check (balance >= 0),
unique ("user", name)
);
create table transactions(

View File

@ -59,7 +59,7 @@ impl User {
tx.execute(&stmt, &[&id, &name, &hash])
.await
.map_err(|err| unique_violation(err, conflict_error))?;
Account::create(&mut tx, Some(id), id, name)
Account::create(&mut tx, Some(id), id, "personal")
.await
.map_err(|err| unique_violation(err, conflict_error))?;
tx.commit().await?;

View File

@ -12,14 +12,12 @@ GET {{host}}/api/accounts?limit=50
Authorization: Bearer {{token}}
HTTP 200
[Asserts]
jsonpath "$.pagination.total" == 7
jsonpath "$.pagination.limit" == 50
jsonpath "$.pagination.offset" == 0
jsonpath "$.result" isCollection
jsonpath "$.result[0].name" == "user1"
jsonpath "$.result[1].name" == "user2"
jsonpath "$.result[2].name" == "user3"
jsonpath "$.result[3].name" == "user4"
jsonpath "$.result[4].name" == "user5"
jsonpath "$.result[5].name" == "user6"
jsonpath "$.result[6].name" == "test-user"
jsonpath "$.result[0].name" == "personal"
jsonpath "$.result[1].name" == "personal"
jsonpath "$.result[2].name" == "personal"
jsonpath "$.result[3].name" == "personal"
jsonpath "$.result[4].name" == "personal"
jsonpath "$.result[5].name" == "personal"

View File

@ -13,5 +13,5 @@ Authorization: Bearer {{token}}
HTTP 200
[Asserts]
jsonpath "$.result" isCollection
jsonpath "$.result[0].name" == "user1"
jsonpath "$.result[0].name" == "personal"
jsonpath "$.result[0].balance" == 100000

View File

@ -12,7 +12,6 @@ GET {{host}}/api/users?limit=50
Authorization: Bearer {{token}}
HTTP 200
[Asserts]
jsonpath "$.pagination.total" == 7
jsonpath "$.pagination.limit" == 50
jsonpath "$.pagination.offset" == 0
jsonpath "$.result" isCollection
@ -22,4 +21,3 @@ jsonpath "$.result[2].name" == "user3"
jsonpath "$.result[3].name" == "user4"
jsonpath "$.result[4].name" == "user5"
jsonpath "$.result[5].name" == "user6"
jsonpath "$.result[6].name" == "test-user"