rf/removes account.username
seems unneccessary because email is already a unique identifier
This commit is contained in:
parent
fb6735c630
commit
921250056b
@ -14,7 +14,6 @@ CREATE TABLE "mails" (
|
|||||||
|
|
||||||
CREATE TABLE "accounts" (
|
CREATE TABLE "accounts" (
|
||||||
"ID" bigserial UNIQUE PRIMARY KEY NOT NULL,
|
"ID" bigserial UNIQUE PRIMARY KEY NOT NULL,
|
||||||
"username" varchar UNIQUE NOT NULL,
|
|
||||||
"passwordhash" varchar NOT NULL,
|
"passwordhash" varchar NOT NULL,
|
||||||
"firstname" varchar NOT NULL,
|
"firstname" varchar NOT NULL,
|
||||||
"lastname" varchar NOT NULL,
|
"lastname" varchar NOT NULL,
|
||||||
|
@ -4,7 +4,6 @@ WHERE "ID" = $1 LIMIT 1;
|
|||||||
|
|
||||||
-- name: CreateAccount :one
|
-- name: CreateAccount :one
|
||||||
INSERT INTO accounts (
|
INSERT INTO accounts (
|
||||||
username,
|
|
||||||
passwordhash,
|
passwordhash,
|
||||||
firstname,
|
firstname,
|
||||||
lastname,
|
lastname,
|
||||||
@ -18,19 +17,18 @@ INSERT INTO accounts (
|
|||||||
creator,
|
creator,
|
||||||
changer
|
changer
|
||||||
) VALUES (
|
) VALUES (
|
||||||
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13
|
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $11
|
||||||
) RETURNING *;
|
) RETURNING *;
|
||||||
|
|
||||||
-- name: ListAccounts :many
|
-- name: ListAccounts :many
|
||||||
SELECT * FROM accounts
|
SELECT * FROM accounts
|
||||||
ORDER BY username
|
ORDER BY lastname, firstname
|
||||||
LIMIT $1
|
LIMIT $1
|
||||||
OFFSET $2;
|
OFFSET $2;
|
||||||
|
|
||||||
-- name: UpdateAccount :one
|
-- name: UpdateAccount :one
|
||||||
UPDATE accounts
|
UPDATE accounts
|
||||||
SET
|
SET
|
||||||
username = COALESCE(sqlc.narg(username), username),
|
|
||||||
passwordhash = COALESCE(sqlc.narg(passwordhash), passwordhash),
|
passwordhash = COALESCE(sqlc.narg(passwordhash), passwordhash),
|
||||||
firstname = COALESCE(sqlc.narg(firstname), firstname),
|
firstname = COALESCE(sqlc.narg(firstname), firstname),
|
||||||
lastname = COALESCE(sqlc.narg(lastname), lastname),
|
lastname = COALESCE(sqlc.narg(lastname), lastname),
|
||||||
|
@ -13,7 +13,6 @@ import (
|
|||||||
|
|
||||||
const createAccount = `-- name: CreateAccount :one
|
const createAccount = `-- name: CreateAccount :one
|
||||||
INSERT INTO accounts (
|
INSERT INTO accounts (
|
||||||
username,
|
|
||||||
passwordhash,
|
passwordhash,
|
||||||
firstname,
|
firstname,
|
||||||
lastname,
|
lastname,
|
||||||
@ -27,12 +26,11 @@ INSERT INTO accounts (
|
|||||||
creator,
|
creator,
|
||||||
changer
|
changer
|
||||||
) VALUES (
|
) VALUES (
|
||||||
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13
|
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $11
|
||||||
) RETURNING "ID", username, passwordhash, firstname, lastname, birthday, "privacyAccepted", "privacyAcceptedDate", email, phone, city, zip, street, country, token, "tokenValid", "tokenExpiration", creator, created, changer, changed
|
) RETURNING "ID", passwordhash, firstname, lastname, birthday, "privacyAccepted", "privacyAcceptedDate", email, phone, city, zip, street, country, token, "tokenValid", "tokenExpiration", creator, created, changer, changed
|
||||||
`
|
`
|
||||||
|
|
||||||
type CreateAccountParams struct {
|
type CreateAccountParams struct {
|
||||||
Username string `json:"username"`
|
|
||||||
Passwordhash string `json:"passwordhash"`
|
Passwordhash string `json:"passwordhash"`
|
||||||
Firstname string `json:"firstname"`
|
Firstname string `json:"firstname"`
|
||||||
Lastname string `json:"lastname"`
|
Lastname string `json:"lastname"`
|
||||||
@ -44,12 +42,10 @@ type CreateAccountParams struct {
|
|||||||
Street string `json:"street"`
|
Street string `json:"street"`
|
||||||
Country string `json:"country"`
|
Country string `json:"country"`
|
||||||
Creator string `json:"creator"`
|
Creator string `json:"creator"`
|
||||||
Changer string `json:"changer"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) (Account, error) {
|
func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) (Account, error) {
|
||||||
row := q.db.QueryRowContext(ctx, createAccount,
|
row := q.db.QueryRowContext(ctx, createAccount,
|
||||||
arg.Username,
|
|
||||||
arg.Passwordhash,
|
arg.Passwordhash,
|
||||||
arg.Firstname,
|
arg.Firstname,
|
||||||
arg.Lastname,
|
arg.Lastname,
|
||||||
@ -61,12 +57,10 @@ func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) (A
|
|||||||
arg.Street,
|
arg.Street,
|
||||||
arg.Country,
|
arg.Country,
|
||||||
arg.Creator,
|
arg.Creator,
|
||||||
arg.Changer,
|
|
||||||
)
|
)
|
||||||
var i Account
|
var i Account
|
||||||
err := row.Scan(
|
err := row.Scan(
|
||||||
&i.ID,
|
&i.ID,
|
||||||
&i.Username,
|
|
||||||
&i.Passwordhash,
|
&i.Passwordhash,
|
||||||
&i.Firstname,
|
&i.Firstname,
|
||||||
&i.Lastname,
|
&i.Lastname,
|
||||||
@ -101,7 +95,7 @@ func (q *Queries) DeleteAccount(ctx context.Context, id int64) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getAccount = `-- name: GetAccount :one
|
const getAccount = `-- name: GetAccount :one
|
||||||
SELECT "ID", username, passwordhash, firstname, lastname, birthday, "privacyAccepted", "privacyAcceptedDate", email, phone, city, zip, street, country, token, "tokenValid", "tokenExpiration", creator, created, changer, changed FROM accounts
|
SELECT "ID", passwordhash, firstname, lastname, birthday, "privacyAccepted", "privacyAcceptedDate", email, phone, city, zip, street, country, token, "tokenValid", "tokenExpiration", creator, created, changer, changed FROM accounts
|
||||||
WHERE "ID" = $1 LIMIT 1
|
WHERE "ID" = $1 LIMIT 1
|
||||||
`
|
`
|
||||||
|
|
||||||
@ -110,7 +104,6 @@ func (q *Queries) GetAccount(ctx context.Context, id int64) (Account, error) {
|
|||||||
var i Account
|
var i Account
|
||||||
err := row.Scan(
|
err := row.Scan(
|
||||||
&i.ID,
|
&i.ID,
|
||||||
&i.Username,
|
|
||||||
&i.Passwordhash,
|
&i.Passwordhash,
|
||||||
&i.Firstname,
|
&i.Firstname,
|
||||||
&i.Lastname,
|
&i.Lastname,
|
||||||
@ -135,8 +128,8 @@ func (q *Queries) GetAccount(ctx context.Context, id int64) (Account, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const listAccounts = `-- name: ListAccounts :many
|
const listAccounts = `-- name: ListAccounts :many
|
||||||
SELECT "ID", username, passwordhash, firstname, lastname, birthday, "privacyAccepted", "privacyAcceptedDate", email, phone, city, zip, street, country, token, "tokenValid", "tokenExpiration", creator, created, changer, changed FROM accounts
|
SELECT "ID", passwordhash, firstname, lastname, birthday, "privacyAccepted", "privacyAcceptedDate", email, phone, city, zip, street, country, token, "tokenValid", "tokenExpiration", creator, created, changer, changed FROM accounts
|
||||||
ORDER BY username
|
ORDER BY lastname, firstname
|
||||||
LIMIT $1
|
LIMIT $1
|
||||||
OFFSET $2
|
OFFSET $2
|
||||||
`
|
`
|
||||||
@ -157,7 +150,6 @@ func (q *Queries) ListAccounts(ctx context.Context, arg ListAccountsParams) ([]A
|
|||||||
var i Account
|
var i Account
|
||||||
if err := rows.Scan(
|
if err := rows.Scan(
|
||||||
&i.ID,
|
&i.ID,
|
||||||
&i.Username,
|
|
||||||
&i.Passwordhash,
|
&i.Passwordhash,
|
||||||
&i.Firstname,
|
&i.Firstname,
|
||||||
&i.Lastname,
|
&i.Lastname,
|
||||||
@ -194,27 +186,25 @@ func (q *Queries) ListAccounts(ctx context.Context, arg ListAccountsParams) ([]A
|
|||||||
const updateAccount = `-- name: UpdateAccount :one
|
const updateAccount = `-- name: UpdateAccount :one
|
||||||
UPDATE accounts
|
UPDATE accounts
|
||||||
SET
|
SET
|
||||||
username = COALESCE($3, username),
|
passwordhash = COALESCE($3, passwordhash),
|
||||||
passwordhash = COALESCE($4, passwordhash),
|
firstname = COALESCE($4, firstname),
|
||||||
firstname = COALESCE($5, firstname),
|
lastname = COALESCE($5, lastname),
|
||||||
lastname = COALESCE($6, lastname),
|
birthday = COALESCE($6, birthday),
|
||||||
birthday = COALESCE($7, birthday),
|
email = COALESCE($7, email),
|
||||||
email = COALESCE($8, email),
|
phone = COALESCE($8, phone),
|
||||||
phone = COALESCE($9, phone),
|
city = COALESCE($9, city),
|
||||||
city = COALESCE($10, city),
|
zip = COALESCE($10, zip),
|
||||||
zip = COALESCE($11, zip),
|
street = COALESCE($11, street),
|
||||||
street = COALESCE($12, street),
|
country = COALESCE($12, country),
|
||||||
country = COALESCE($13, country),
|
|
||||||
changer = $2,
|
changer = $2,
|
||||||
changed = now()
|
changed = now()
|
||||||
WHERE "ID" = $1
|
WHERE "ID" = $1
|
||||||
RETURNING "ID", username, passwordhash, firstname, lastname, birthday, "privacyAccepted", "privacyAcceptedDate", email, phone, city, zip, street, country, token, "tokenValid", "tokenExpiration", creator, created, changer, changed
|
RETURNING "ID", passwordhash, firstname, lastname, birthday, "privacyAccepted", "privacyAcceptedDate", email, phone, city, zip, street, country, token, "tokenValid", "tokenExpiration", creator, created, changer, changed
|
||||||
`
|
`
|
||||||
|
|
||||||
type UpdateAccountParams struct {
|
type UpdateAccountParams struct {
|
||||||
ID int64 `json:"ID"`
|
ID int64 `json:"ID"`
|
||||||
Changer string `json:"changer"`
|
Changer string `json:"changer"`
|
||||||
Username sql.NullString `json:"username"`
|
|
||||||
Passwordhash sql.NullString `json:"passwordhash"`
|
Passwordhash sql.NullString `json:"passwordhash"`
|
||||||
Firstname sql.NullString `json:"firstname"`
|
Firstname sql.NullString `json:"firstname"`
|
||||||
Lastname sql.NullString `json:"lastname"`
|
Lastname sql.NullString `json:"lastname"`
|
||||||
@ -231,7 +221,6 @@ func (q *Queries) UpdateAccount(ctx context.Context, arg UpdateAccountParams) (A
|
|||||||
row := q.db.QueryRowContext(ctx, updateAccount,
|
row := q.db.QueryRowContext(ctx, updateAccount,
|
||||||
arg.ID,
|
arg.ID,
|
||||||
arg.Changer,
|
arg.Changer,
|
||||||
arg.Username,
|
|
||||||
arg.Passwordhash,
|
arg.Passwordhash,
|
||||||
arg.Firstname,
|
arg.Firstname,
|
||||||
arg.Lastname,
|
arg.Lastname,
|
||||||
@ -246,7 +235,6 @@ func (q *Queries) UpdateAccount(ctx context.Context, arg UpdateAccountParams) (A
|
|||||||
var i Account
|
var i Account
|
||||||
err := row.Scan(
|
err := row.Scan(
|
||||||
&i.ID,
|
&i.ID,
|
||||||
&i.Username,
|
|
||||||
&i.Passwordhash,
|
&i.Passwordhash,
|
||||||
&i.Firstname,
|
&i.Firstname,
|
||||||
&i.Lastname,
|
&i.Lastname,
|
||||||
|
@ -15,7 +15,6 @@ func createRandomAccount(t *testing.T) Account {
|
|||||||
creator := util.RandomUser()
|
creator := util.RandomUser()
|
||||||
|
|
||||||
arg := CreateAccountParams{
|
arg := CreateAccountParams{
|
||||||
Username: util.RandomUser(),
|
|
||||||
Passwordhash: util.RandomString(30),
|
Passwordhash: util.RandomString(30),
|
||||||
Firstname: util.RandomUser(),
|
Firstname: util.RandomUser(),
|
||||||
Lastname: util.RandomUser(),
|
Lastname: util.RandomUser(),
|
||||||
@ -30,14 +29,12 @@ func createRandomAccount(t *testing.T) Account {
|
|||||||
Street: util.RandomString(20),
|
Street: util.RandomString(20),
|
||||||
Country: util.RandomString(15),
|
Country: util.RandomString(15),
|
||||||
Creator: creator,
|
Creator: creator,
|
||||||
Changer: creator,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
account, err := testQueries.CreateAccount(context.Background(), arg)
|
account, err := testQueries.CreateAccount(context.Background(), arg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotEmpty(t, account)
|
require.NotEmpty(t, account)
|
||||||
|
|
||||||
require.Equal(t, arg.Username, account.Username)
|
|
||||||
require.Equal(t, arg.Passwordhash, account.Passwordhash)
|
require.Equal(t, arg.Passwordhash, account.Passwordhash)
|
||||||
require.Equal(t, arg.Firstname, account.Firstname)
|
require.Equal(t, arg.Firstname, account.Firstname)
|
||||||
require.Equal(t, arg.Lastname, account.Lastname)
|
require.Equal(t, arg.Lastname, account.Lastname)
|
||||||
@ -49,7 +46,7 @@ func createRandomAccount(t *testing.T) Account {
|
|||||||
require.Equal(t, arg.Street, account.Street)
|
require.Equal(t, arg.Street, account.Street)
|
||||||
require.Equal(t, arg.Country, account.Country)
|
require.Equal(t, arg.Country, account.Country)
|
||||||
require.Equal(t, arg.Creator, account.Creator)
|
require.Equal(t, arg.Creator, account.Creator)
|
||||||
require.Equal(t, arg.Changer, account.Changer)
|
require.Equal(t, arg.Creator, account.Changer)
|
||||||
|
|
||||||
require.NotZero(t, account.ID)
|
require.NotZero(t, account.ID)
|
||||||
require.NotZero(t, account.Created)
|
require.NotZero(t, account.Created)
|
||||||
@ -69,7 +66,6 @@ func TestGetAccount(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotEmpty(t, account)
|
require.NotEmpty(t, account)
|
||||||
|
|
||||||
require.Equal(t, newAccount.Username, account.Username)
|
|
||||||
require.Equal(t, newAccount.Passwordhash, account.Passwordhash)
|
require.Equal(t, newAccount.Passwordhash, account.Passwordhash)
|
||||||
require.Equal(t, newAccount.Firstname, account.Firstname)
|
require.Equal(t, newAccount.Firstname, account.Firstname)
|
||||||
require.Equal(t, newAccount.Lastname, account.Lastname)
|
require.Equal(t, newAccount.Lastname, account.Lastname)
|
||||||
@ -114,7 +110,7 @@ func TestUpdateAccount(t *testing.T) {
|
|||||||
require.NotEmpty(t, account2)
|
require.NotEmpty(t, account2)
|
||||||
|
|
||||||
require.Equal(t, account1.ID, account2.ID)
|
require.Equal(t, account1.ID, account2.ID)
|
||||||
require.Equal(t, account1.Username, account2.Username)
|
require.Equal(t, account1.Lastname, account2.Lastname)
|
||||||
require.NotEqual(t, account1.Phone, account2.Phone)
|
require.NotEqual(t, account1.Phone, account2.Phone)
|
||||||
require.NotEqual(t, account1.Changer, account2.Changer)
|
require.NotEqual(t, account1.Changer, account2.Changer)
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
|
|
||||||
type Account struct {
|
type Account struct {
|
||||||
ID int64 `json:"ID"`
|
ID int64 `json:"ID"`
|
||||||
Username string `json:"username"`
|
|
||||||
Passwordhash string `json:"passwordhash"`
|
Passwordhash string `json:"passwordhash"`
|
||||||
Firstname string `json:"firstname"`
|
Firstname string `json:"firstname"`
|
||||||
Lastname string `json:"lastname"`
|
Lastname string `json:"lastname"`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user