first implementation of document strategy
This commit is contained in:
+189
-129
@@ -8,12 +8,16 @@ package database
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"mediarr/ident"
|
||||
)
|
||||
|
||||
const createAccount = `-- name: CreateAccount :one
|
||||
|
||||
INSERT INTO account (
|
||||
principal_id,
|
||||
login,
|
||||
login_key,
|
||||
password_hash,
|
||||
password_changed_at,
|
||||
must_change_password,
|
||||
@@ -31,13 +35,17 @@ INSERT INTO account (
|
||||
?6,
|
||||
?7,
|
||||
?8,
|
||||
?9
|
||||
?9,
|
||||
?10,
|
||||
?11
|
||||
)
|
||||
RETURNING principal_id, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
||||
RETURNING principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
||||
`
|
||||
|
||||
type CreateAccountParams struct {
|
||||
PrincipalID string
|
||||
PrincipalID ident.UUID
|
||||
Login string
|
||||
LoginKey string
|
||||
PasswordHash sql.NullString
|
||||
PasswordChangedAt sql.NullInt64
|
||||
MustChangePassword int64
|
||||
@@ -54,6 +62,8 @@ type CreateAccountParams struct {
|
||||
func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) (Account, error) {
|
||||
row := q.db.QueryRowContext(ctx, createAccount,
|
||||
arg.PrincipalID,
|
||||
arg.Login,
|
||||
arg.LoginKey,
|
||||
arg.PasswordHash,
|
||||
arg.PasswordChangedAt,
|
||||
arg.MustChangePassword,
|
||||
@@ -66,6 +76,8 @@ func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) (A
|
||||
var i Account
|
||||
err := row.Scan(
|
||||
&i.PrincipalID,
|
||||
&i.Login,
|
||||
&i.LoginKey,
|
||||
&i.PasswordHash,
|
||||
&i.PasswordChangedAt,
|
||||
&i.MustChangePassword,
|
||||
@@ -84,24 +96,21 @@ INSERT INTO membership (
|
||||
group_id,
|
||||
member_id,
|
||||
role,
|
||||
created_at,
|
||||
disabled_at
|
||||
created_at
|
||||
) VALUES (
|
||||
?1,
|
||||
?2,
|
||||
?3,
|
||||
?4,
|
||||
?5
|
||||
?4
|
||||
)
|
||||
RETURNING group_id, member_id, role, created_at, disabled_at
|
||||
RETURNING group_id, member_id, role, created_at
|
||||
`
|
||||
|
||||
type CreateMembershipParams struct {
|
||||
GroupID string
|
||||
MemberID string
|
||||
Role string
|
||||
CreatedAt int64
|
||||
DisabledAt sql.NullInt64
|
||||
GroupID ident.UUID
|
||||
MemberID ident.UUID
|
||||
Role string
|
||||
CreatedAt int64
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
@@ -113,7 +122,6 @@ func (q *Queries) CreateMembership(ctx context.Context, arg CreateMembershipPara
|
||||
arg.MemberID,
|
||||
arg.Role,
|
||||
arg.CreatedAt,
|
||||
arg.DisabledAt,
|
||||
)
|
||||
var i Membership
|
||||
err := row.Scan(
|
||||
@@ -121,7 +129,6 @@ func (q *Queries) CreateMembership(ctx context.Context, arg CreateMembershipPara
|
||||
&i.MemberID,
|
||||
&i.Role,
|
||||
&i.CreatedAt,
|
||||
&i.DisabledAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -134,6 +141,7 @@ INSERT INTO principal (
|
||||
name,
|
||||
public_key,
|
||||
status,
|
||||
successor_id,
|
||||
created_at,
|
||||
disabled_at
|
||||
) VALUES (
|
||||
@@ -143,19 +151,21 @@ INSERT INTO principal (
|
||||
?4,
|
||||
?5,
|
||||
?6,
|
||||
?7
|
||||
?7,
|
||||
?8
|
||||
)
|
||||
RETURNING id, kind, name, public_key, status, created_at, disabled_at
|
||||
RETURNING id, kind, name, public_key, status, successor_id, created_at, disabled_at
|
||||
`
|
||||
|
||||
type CreatePrincipalParams struct {
|
||||
ID string
|
||||
Kind string
|
||||
Name string
|
||||
PublicKey []byte
|
||||
Status string
|
||||
CreatedAt int64
|
||||
DisabledAt sql.NullInt64
|
||||
ID ident.UUID
|
||||
Kind string
|
||||
Name string
|
||||
PublicKey []byte
|
||||
Status string
|
||||
SuccessorID *ident.UUID
|
||||
CreatedAt int64
|
||||
DisabledAt sql.NullInt64
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
@@ -168,6 +178,7 @@ func (q *Queries) CreatePrincipal(ctx context.Context, arg CreatePrincipalParams
|
||||
arg.Name,
|
||||
arg.PublicKey,
|
||||
arg.Status,
|
||||
arg.SuccessorID,
|
||||
arg.CreatedAt,
|
||||
arg.DisabledAt,
|
||||
)
|
||||
@@ -178,6 +189,7 @@ func (q *Queries) CreatePrincipal(ctx context.Context, arg CreatePrincipalParams
|
||||
&i.Name,
|
||||
&i.PublicKey,
|
||||
&i.Status,
|
||||
&i.SuccessorID,
|
||||
&i.CreatedAt,
|
||||
&i.DisabledAt,
|
||||
)
|
||||
@@ -189,7 +201,7 @@ DELETE FROM account
|
||||
WHERE principal_id = ?1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteAccount(ctx context.Context, principalID string) error {
|
||||
func (q *Queries) DeleteAccount(ctx context.Context, principalID ident.UUID) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteAccount, principalID)
|
||||
return err
|
||||
}
|
||||
@@ -201,8 +213,8 @@ WHERE group_id = ?1
|
||||
`
|
||||
|
||||
type DeleteMembershipParams struct {
|
||||
GroupID string
|
||||
MemberID string
|
||||
GroupID ident.UUID
|
||||
MemberID ident.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteMembership(ctx context.Context, arg DeleteMembershipParams) error {
|
||||
@@ -215,75 +227,49 @@ DELETE FROM principal
|
||||
WHERE id = ?1
|
||||
`
|
||||
|
||||
func (q *Queries) DeletePrincipal(ctx context.Context, id string) error {
|
||||
func (q *Queries) DeletePrincipal(ctx context.Context, id ident.UUID) error {
|
||||
_, err := q.db.ExecContext(ctx, deletePrincipal, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const disableMembership = `-- name: DisableMembership :one
|
||||
UPDATE membership
|
||||
SET disabled_at = ?1
|
||||
WHERE group_id = ?2
|
||||
AND member_id = ?3
|
||||
RETURNING group_id, member_id, role, created_at, disabled_at
|
||||
`
|
||||
|
||||
type DisableMembershipParams struct {
|
||||
DisabledAt sql.NullInt64
|
||||
GroupID string
|
||||
MemberID string
|
||||
}
|
||||
|
||||
func (q *Queries) DisableMembership(ctx context.Context, arg DisableMembershipParams) (Membership, error) {
|
||||
row := q.db.QueryRowContext(ctx, disableMembership, arg.DisabledAt, arg.GroupID, arg.MemberID)
|
||||
var i Membership
|
||||
err := row.Scan(
|
||||
&i.GroupID,
|
||||
&i.MemberID,
|
||||
&i.Role,
|
||||
&i.CreatedAt,
|
||||
&i.DisabledAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const enableMembership = `-- name: EnableMembership :one
|
||||
UPDATE membership
|
||||
SET disabled_at = NULL
|
||||
WHERE group_id = ?1
|
||||
AND member_id = ?2
|
||||
RETURNING group_id, member_id, role, created_at, disabled_at
|
||||
`
|
||||
|
||||
type EnableMembershipParams struct {
|
||||
GroupID string
|
||||
MemberID string
|
||||
}
|
||||
|
||||
func (q *Queries) EnableMembership(ctx context.Context, arg EnableMembershipParams) (Membership, error) {
|
||||
row := q.db.QueryRowContext(ctx, enableMembership, arg.GroupID, arg.MemberID)
|
||||
var i Membership
|
||||
err := row.Scan(
|
||||
&i.GroupID,
|
||||
&i.MemberID,
|
||||
&i.Role,
|
||||
&i.CreatedAt,
|
||||
&i.DisabledAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getAccount = `-- name: GetAccount :one
|
||||
SELECT principal_id, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
||||
SELECT principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
||||
FROM account
|
||||
WHERE principal_id = ?1
|
||||
`
|
||||
|
||||
func (q *Queries) GetAccount(ctx context.Context, principalID string) (Account, error) {
|
||||
func (q *Queries) GetAccount(ctx context.Context, principalID ident.UUID) (Account, error) {
|
||||
row := q.db.QueryRowContext(ctx, getAccount, principalID)
|
||||
var i Account
|
||||
err := row.Scan(
|
||||
&i.PrincipalID,
|
||||
&i.Login,
|
||||
&i.LoginKey,
|
||||
&i.PasswordHash,
|
||||
&i.PasswordChangedAt,
|
||||
&i.MustChangePassword,
|
||||
&i.State,
|
||||
&i.FailedAttempts,
|
||||
&i.LockedUntil,
|
||||
&i.LastLoginAt,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getAccountByLoginKey = `-- name: GetAccountByLoginKey :one
|
||||
SELECT principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
||||
FROM account
|
||||
WHERE login_key = ?1
|
||||
`
|
||||
|
||||
func (q *Queries) GetAccountByLoginKey(ctx context.Context, loginKey string) (Account, error) {
|
||||
row := q.db.QueryRowContext(ctx, getAccountByLoginKey, loginKey)
|
||||
var i Account
|
||||
err := row.Scan(
|
||||
&i.PrincipalID,
|
||||
&i.Login,
|
||||
&i.LoginKey,
|
||||
&i.PasswordHash,
|
||||
&i.PasswordChangedAt,
|
||||
&i.MustChangePassword,
|
||||
@@ -297,15 +283,15 @@ func (q *Queries) GetAccount(ctx context.Context, principalID string) (Account,
|
||||
}
|
||||
|
||||
const getMembership = `-- name: GetMembership :one
|
||||
SELECT group_id, member_id, role, created_at, disabled_at
|
||||
SELECT group_id, member_id, role, created_at
|
||||
FROM membership
|
||||
WHERE group_id = ?1
|
||||
AND member_id = ?2
|
||||
`
|
||||
|
||||
type GetMembershipParams struct {
|
||||
GroupID string
|
||||
MemberID string
|
||||
GroupID ident.UUID
|
||||
MemberID ident.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) GetMembership(ctx context.Context, arg GetMembershipParams) (Membership, error) {
|
||||
@@ -316,18 +302,17 @@ func (q *Queries) GetMembership(ctx context.Context, arg GetMembershipParams) (M
|
||||
&i.MemberID,
|
||||
&i.Role,
|
||||
&i.CreatedAt,
|
||||
&i.DisabledAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getPrincipal = `-- name: GetPrincipal :one
|
||||
SELECT id, kind, name, public_key, status, created_at, disabled_at
|
||||
SELECT id, kind, name, public_key, status, successor_id, created_at, disabled_at
|
||||
FROM principal
|
||||
WHERE id = ?1
|
||||
`
|
||||
|
||||
func (q *Queries) GetPrincipal(ctx context.Context, id string) (Principal, error) {
|
||||
func (q *Queries) GetPrincipal(ctx context.Context, id ident.UUID) (Principal, error) {
|
||||
row := q.db.QueryRowContext(ctx, getPrincipal, id)
|
||||
var i Principal
|
||||
err := row.Scan(
|
||||
@@ -336,6 +321,7 @@ func (q *Queries) GetPrincipal(ctx context.Context, id string) (Principal, error
|
||||
&i.Name,
|
||||
&i.PublicKey,
|
||||
&i.Status,
|
||||
&i.SuccessorID,
|
||||
&i.CreatedAt,
|
||||
&i.DisabledAt,
|
||||
)
|
||||
@@ -343,7 +329,7 @@ func (q *Queries) GetPrincipal(ctx context.Context, id string) (Principal, error
|
||||
}
|
||||
|
||||
const getPrincipalByName = `-- name: GetPrincipalByName :one
|
||||
SELECT id, kind, name, public_key, status, created_at, disabled_at
|
||||
SELECT id, kind, name, public_key, status, successor_id, created_at, disabled_at
|
||||
FROM principal
|
||||
WHERE name = ?1
|
||||
`
|
||||
@@ -357,6 +343,35 @@ func (q *Queries) GetPrincipalByName(ctx context.Context, name string) (Principa
|
||||
&i.Name,
|
||||
&i.PublicKey,
|
||||
&i.Status,
|
||||
&i.SuccessorID,
|
||||
&i.CreatedAt,
|
||||
&i.DisabledAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getPrincipalByNameAndKind = `-- name: GetPrincipalByNameAndKind :one
|
||||
SELECT id, kind, name, public_key, status, successor_id, created_at, disabled_at
|
||||
FROM principal
|
||||
WHERE kind = ?1
|
||||
AND name = ?2
|
||||
`
|
||||
|
||||
type GetPrincipalByNameAndKindParams struct {
|
||||
Kind string
|
||||
Name string
|
||||
}
|
||||
|
||||
func (q *Queries) GetPrincipalByNameAndKind(ctx context.Context, arg GetPrincipalByNameAndKindParams) (Principal, error) {
|
||||
row := q.db.QueryRowContext(ctx, getPrincipalByNameAndKind, arg.Kind, arg.Name)
|
||||
var i Principal
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Kind,
|
||||
&i.Name,
|
||||
&i.PublicKey,
|
||||
&i.Status,
|
||||
&i.SuccessorID,
|
||||
&i.CreatedAt,
|
||||
&i.DisabledAt,
|
||||
)
|
||||
@@ -367,14 +382,16 @@ const incrementFailedAttempts = `-- name: IncrementFailedAttempts :one
|
||||
UPDATE account
|
||||
SET failed_attempts = failed_attempts + 1
|
||||
WHERE principal_id = ?1
|
||||
RETURNING principal_id, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
||||
RETURNING principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
||||
`
|
||||
|
||||
func (q *Queries) IncrementFailedAttempts(ctx context.Context, principalID string) (Account, error) {
|
||||
func (q *Queries) IncrementFailedAttempts(ctx context.Context, principalID ident.UUID) (Account, error) {
|
||||
row := q.db.QueryRowContext(ctx, incrementFailedAttempts, principalID)
|
||||
var i Account
|
||||
err := row.Scan(
|
||||
&i.PrincipalID,
|
||||
&i.Login,
|
||||
&i.LoginKey,
|
||||
&i.PasswordHash,
|
||||
&i.PasswordChangedAt,
|
||||
&i.MustChangePassword,
|
||||
@@ -388,7 +405,7 @@ func (q *Queries) IncrementFailedAttempts(ctx context.Context, principalID strin
|
||||
}
|
||||
|
||||
const listActivePrincipals = `-- name: ListActivePrincipals :many
|
||||
SELECT id, kind, name, public_key, status, created_at, disabled_at
|
||||
SELECT id, kind, name, public_key, status, successor_id, created_at, disabled_at
|
||||
FROM principal
|
||||
WHERE status = 'active'
|
||||
ORDER BY name
|
||||
@@ -409,6 +426,7 @@ func (q *Queries) ListActivePrincipals(ctx context.Context) ([]Principal, error)
|
||||
&i.Name,
|
||||
&i.PublicKey,
|
||||
&i.Status,
|
||||
&i.SuccessorID,
|
||||
&i.CreatedAt,
|
||||
&i.DisabledAt,
|
||||
); err != nil {
|
||||
@@ -426,15 +444,14 @@ func (q *Queries) ListActivePrincipals(ctx context.Context) ([]Principal, error)
|
||||
}
|
||||
|
||||
const listGroupMembers = `-- name: ListGroupMembers :many
|
||||
SELECT p.id, p.kind, p.name, p.public_key, p.status, p.created_at, p.disabled_at
|
||||
SELECT p.id, p.kind, p.name, p.public_key, p.status, p.successor_id, p.created_at, p.disabled_at
|
||||
FROM membership m
|
||||
JOIN principal p ON p.id = m.member_id
|
||||
WHERE m.group_id = ?1
|
||||
AND m.disabled_at IS NULL
|
||||
ORDER BY p.name
|
||||
`
|
||||
|
||||
func (q *Queries) ListGroupMembers(ctx context.Context, groupID string) ([]Principal, error) {
|
||||
func (q *Queries) ListGroupMembers(ctx context.Context, groupID ident.UUID) ([]Principal, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listGroupMembers, groupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -449,6 +466,7 @@ func (q *Queries) ListGroupMembers(ctx context.Context, groupID string) ([]Princ
|
||||
&i.Name,
|
||||
&i.PublicKey,
|
||||
&i.Status,
|
||||
&i.SuccessorID,
|
||||
&i.CreatedAt,
|
||||
&i.DisabledAt,
|
||||
); err != nil {
|
||||
@@ -466,15 +484,14 @@ func (q *Queries) ListGroupMembers(ctx context.Context, groupID string) ([]Princ
|
||||
}
|
||||
|
||||
const listMemberGroups = `-- name: ListMemberGroups :many
|
||||
SELECT p.id, p.kind, p.name, p.public_key, p.status, p.created_at, p.disabled_at
|
||||
SELECT p.id, p.kind, p.name, p.public_key, p.status, p.successor_id, p.created_at, p.disabled_at
|
||||
FROM membership m
|
||||
JOIN principal p ON p.id = m.group_id
|
||||
WHERE m.member_id = ?1
|
||||
AND m.disabled_at IS NULL
|
||||
ORDER BY p.name
|
||||
`
|
||||
|
||||
func (q *Queries) ListMemberGroups(ctx context.Context, memberID string) ([]Principal, error) {
|
||||
func (q *Queries) ListMemberGroups(ctx context.Context, memberID ident.UUID) ([]Principal, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listMemberGroups, memberID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -489,6 +506,7 @@ func (q *Queries) ListMemberGroups(ctx context.Context, memberID string) ([]Prin
|
||||
&i.Name,
|
||||
&i.PublicKey,
|
||||
&i.Status,
|
||||
&i.SuccessorID,
|
||||
&i.CreatedAt,
|
||||
&i.DisabledAt,
|
||||
); err != nil {
|
||||
@@ -506,13 +524,13 @@ func (q *Queries) ListMemberGroups(ctx context.Context, memberID string) ([]Prin
|
||||
}
|
||||
|
||||
const listMembershipsByGroup = `-- name: ListMembershipsByGroup :many
|
||||
SELECT group_id, member_id, role, created_at, disabled_at
|
||||
SELECT group_id, member_id, role, created_at
|
||||
FROM membership
|
||||
WHERE group_id = ?1
|
||||
ORDER BY created_at
|
||||
`
|
||||
|
||||
func (q *Queries) ListMembershipsByGroup(ctx context.Context, groupID string) ([]Membership, error) {
|
||||
func (q *Queries) ListMembershipsByGroup(ctx context.Context, groupID ident.UUID) ([]Membership, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listMembershipsByGroup, groupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -526,7 +544,6 @@ func (q *Queries) ListMembershipsByGroup(ctx context.Context, groupID string) ([
|
||||
&i.MemberID,
|
||||
&i.Role,
|
||||
&i.CreatedAt,
|
||||
&i.DisabledAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -542,13 +559,13 @@ func (q *Queries) ListMembershipsByGroup(ctx context.Context, groupID string) ([
|
||||
}
|
||||
|
||||
const listMembershipsByMember = `-- name: ListMembershipsByMember :many
|
||||
SELECT group_id, member_id, role, created_at, disabled_at
|
||||
SELECT group_id, member_id, role, created_at
|
||||
FROM membership
|
||||
WHERE member_id = ?1
|
||||
ORDER BY created_at
|
||||
`
|
||||
|
||||
func (q *Queries) ListMembershipsByMember(ctx context.Context, memberID string) ([]Membership, error) {
|
||||
func (q *Queries) ListMembershipsByMember(ctx context.Context, memberID ident.UUID) ([]Membership, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listMembershipsByMember, memberID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -562,7 +579,6 @@ func (q *Queries) ListMembershipsByMember(ctx context.Context, memberID string)
|
||||
&i.MemberID,
|
||||
&i.Role,
|
||||
&i.CreatedAt,
|
||||
&i.DisabledAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -578,7 +594,7 @@ func (q *Queries) ListMembershipsByMember(ctx context.Context, memberID string)
|
||||
}
|
||||
|
||||
const listPrincipals = `-- name: ListPrincipals :many
|
||||
SELECT id, kind, name, public_key, status, created_at, disabled_at
|
||||
SELECT id, kind, name, public_key, status, successor_id, created_at, disabled_at
|
||||
FROM principal
|
||||
ORDER BY name
|
||||
`
|
||||
@@ -598,6 +614,7 @@ func (q *Queries) ListPrincipals(ctx context.Context) ([]Principal, error) {
|
||||
&i.Name,
|
||||
&i.PublicKey,
|
||||
&i.Status,
|
||||
&i.SuccessorID,
|
||||
&i.CreatedAt,
|
||||
&i.DisabledAt,
|
||||
); err != nil {
|
||||
@@ -615,7 +632,7 @@ func (q *Queries) ListPrincipals(ctx context.Context) ([]Principal, error) {
|
||||
}
|
||||
|
||||
const listPrincipalsByKind = `-- name: ListPrincipalsByKind :many
|
||||
SELECT id, kind, name, public_key, status, created_at, disabled_at
|
||||
SELECT id, kind, name, public_key, status, successor_id, created_at, disabled_at
|
||||
FROM principal
|
||||
WHERE kind = ?1
|
||||
ORDER BY name
|
||||
@@ -636,6 +653,7 @@ func (q *Queries) ListPrincipalsByKind(ctx context.Context, kind string) ([]Prin
|
||||
&i.Name,
|
||||
&i.PublicKey,
|
||||
&i.Status,
|
||||
&i.SuccessorID,
|
||||
&i.CreatedAt,
|
||||
&i.DisabledAt,
|
||||
); err != nil {
|
||||
@@ -657,12 +675,12 @@ UPDATE account
|
||||
SET state = 'locked',
|
||||
locked_until = ?1
|
||||
WHERE principal_id = ?2
|
||||
RETURNING principal_id, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
||||
RETURNING principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
||||
`
|
||||
|
||||
type LockAccountParams struct {
|
||||
LockedUntil sql.NullInt64
|
||||
PrincipalID string
|
||||
PrincipalID ident.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) LockAccount(ctx context.Context, arg LockAccountParams) (Account, error) {
|
||||
@@ -670,6 +688,8 @@ func (q *Queries) LockAccount(ctx context.Context, arg LockAccountParams) (Accou
|
||||
var i Account
|
||||
err := row.Scan(
|
||||
&i.PrincipalID,
|
||||
&i.Login,
|
||||
&i.LoginKey,
|
||||
&i.PasswordHash,
|
||||
&i.PasswordChangedAt,
|
||||
&i.MustChangePassword,
|
||||
@@ -688,12 +708,12 @@ SET last_login_at = ?1,
|
||||
failed_attempts = 0,
|
||||
locked_until = NULL
|
||||
WHERE principal_id = ?2
|
||||
RETURNING principal_id, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
||||
RETURNING principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
||||
`
|
||||
|
||||
type RecordLoginParams struct {
|
||||
LastLoginAt sql.NullInt64
|
||||
PrincipalID string
|
||||
PrincipalID ident.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) RecordLogin(ctx context.Context, arg RecordLoginParams) (Account, error) {
|
||||
@@ -701,6 +721,8 @@ func (q *Queries) RecordLogin(ctx context.Context, arg RecordLoginParams) (Accou
|
||||
var i Account
|
||||
err := row.Scan(
|
||||
&i.PrincipalID,
|
||||
&i.Login,
|
||||
&i.LoginKey,
|
||||
&i.PasswordHash,
|
||||
&i.PasswordChangedAt,
|
||||
&i.MustChangePassword,
|
||||
@@ -718,14 +740,16 @@ UPDATE account
|
||||
SET failed_attempts = 0,
|
||||
locked_until = NULL
|
||||
WHERE principal_id = ?1
|
||||
RETURNING principal_id, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
||||
RETURNING principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
||||
`
|
||||
|
||||
func (q *Queries) ResetFailedAttempts(ctx context.Context, principalID string) (Account, error) {
|
||||
func (q *Queries) ResetFailedAttempts(ctx context.Context, principalID ident.UUID) (Account, error) {
|
||||
row := q.db.QueryRowContext(ctx, resetFailedAttempts, principalID)
|
||||
var i Account
|
||||
err := row.Scan(
|
||||
&i.PrincipalID,
|
||||
&i.Login,
|
||||
&i.LoginKey,
|
||||
&i.PasswordHash,
|
||||
&i.PasswordChangedAt,
|
||||
&i.MustChangePassword,
|
||||
@@ -744,14 +768,16 @@ SET state = 'active',
|
||||
failed_attempts = 0,
|
||||
locked_until = NULL
|
||||
WHERE principal_id = ?1
|
||||
RETURNING principal_id, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
||||
RETURNING principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
||||
`
|
||||
|
||||
func (q *Queries) UnlockAccount(ctx context.Context, principalID string) (Account, error) {
|
||||
func (q *Queries) UnlockAccount(ctx context.Context, principalID ident.UUID) (Account, error) {
|
||||
row := q.db.QueryRowContext(ctx, unlockAccount, principalID)
|
||||
var i Account
|
||||
err := row.Scan(
|
||||
&i.PrincipalID,
|
||||
&i.Login,
|
||||
&i.LoginKey,
|
||||
&i.PasswordHash,
|
||||
&i.PasswordChangedAt,
|
||||
&i.MustChangePassword,
|
||||
@@ -768,12 +794,12 @@ const updateAccountState = `-- name: UpdateAccountState :one
|
||||
UPDATE account
|
||||
SET state = ?1
|
||||
WHERE principal_id = ?2
|
||||
RETURNING principal_id, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
||||
RETURNING principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
||||
`
|
||||
|
||||
type UpdateAccountStateParams struct {
|
||||
State string
|
||||
PrincipalID string
|
||||
PrincipalID ident.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateAccountState(ctx context.Context, arg UpdateAccountStateParams) (Account, error) {
|
||||
@@ -781,6 +807,8 @@ func (q *Queries) UpdateAccountState(ctx context.Context, arg UpdateAccountState
|
||||
var i Account
|
||||
err := row.Scan(
|
||||
&i.PrincipalID,
|
||||
&i.Login,
|
||||
&i.LoginKey,
|
||||
&i.PasswordHash,
|
||||
&i.PasswordChangedAt,
|
||||
&i.MustChangePassword,
|
||||
@@ -798,13 +826,13 @@ UPDATE membership
|
||||
SET role = ?1
|
||||
WHERE group_id = ?2
|
||||
AND member_id = ?3
|
||||
RETURNING group_id, member_id, role, created_at, disabled_at
|
||||
RETURNING group_id, member_id, role, created_at
|
||||
`
|
||||
|
||||
type UpdateMembershipRoleParams struct {
|
||||
Role string
|
||||
GroupID string
|
||||
MemberID string
|
||||
GroupID ident.UUID
|
||||
MemberID ident.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateMembershipRole(ctx context.Context, arg UpdateMembershipRoleParams) (Membership, error) {
|
||||
@@ -815,7 +843,6 @@ func (q *Queries) UpdateMembershipRole(ctx context.Context, arg UpdateMembership
|
||||
&i.MemberID,
|
||||
&i.Role,
|
||||
&i.CreatedAt,
|
||||
&i.DisabledAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -828,13 +855,13 @@ SET password_hash = ?1,
|
||||
failed_attempts = 0,
|
||||
locked_until = NULL
|
||||
WHERE principal_id = ?3
|
||||
RETURNING principal_id, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
||||
RETURNING principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
|
||||
`
|
||||
|
||||
type UpdatePasswordParams struct {
|
||||
PasswordHash sql.NullString
|
||||
PasswordChangedAt sql.NullInt64
|
||||
PrincipalID string
|
||||
PrincipalID ident.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) UpdatePassword(ctx context.Context, arg UpdatePasswordParams) (Account, error) {
|
||||
@@ -842,6 +869,8 @@ func (q *Queries) UpdatePassword(ctx context.Context, arg UpdatePasswordParams)
|
||||
var i Account
|
||||
err := row.Scan(
|
||||
&i.PrincipalID,
|
||||
&i.Login,
|
||||
&i.LoginKey,
|
||||
&i.PasswordHash,
|
||||
&i.PasswordChangedAt,
|
||||
&i.MustChangePassword,
|
||||
@@ -858,12 +887,12 @@ const updatePrincipalName = `-- name: UpdatePrincipalName :one
|
||||
UPDATE principal
|
||||
SET name = ?1
|
||||
WHERE id = ?2
|
||||
RETURNING id, kind, name, public_key, status, created_at, disabled_at
|
||||
RETURNING id, kind, name, public_key, status, successor_id, created_at, disabled_at
|
||||
`
|
||||
|
||||
type UpdatePrincipalNameParams struct {
|
||||
Name string
|
||||
ID string
|
||||
ID ident.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) UpdatePrincipalName(ctx context.Context, arg UpdatePrincipalNameParams) (Principal, error) {
|
||||
@@ -875,6 +904,7 @@ func (q *Queries) UpdatePrincipalName(ctx context.Context, arg UpdatePrincipalNa
|
||||
&i.Name,
|
||||
&i.PublicKey,
|
||||
&i.Status,
|
||||
&i.SuccessorID,
|
||||
&i.CreatedAt,
|
||||
&i.DisabledAt,
|
||||
)
|
||||
@@ -885,12 +915,12 @@ const updatePrincipalPublicKey = `-- name: UpdatePrincipalPublicKey :one
|
||||
UPDATE principal
|
||||
SET public_key = ?1
|
||||
WHERE id = ?2
|
||||
RETURNING id, kind, name, public_key, status, created_at, disabled_at
|
||||
RETURNING id, kind, name, public_key, status, successor_id, created_at, disabled_at
|
||||
`
|
||||
|
||||
type UpdatePrincipalPublicKeyParams struct {
|
||||
PublicKey []byte
|
||||
ID string
|
||||
ID ident.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) UpdatePrincipalPublicKey(ctx context.Context, arg UpdatePrincipalPublicKeyParams) (Principal, error) {
|
||||
@@ -902,6 +932,7 @@ func (q *Queries) UpdatePrincipalPublicKey(ctx context.Context, arg UpdatePrinci
|
||||
&i.Name,
|
||||
&i.PublicKey,
|
||||
&i.Status,
|
||||
&i.SuccessorID,
|
||||
&i.CreatedAt,
|
||||
&i.DisabledAt,
|
||||
)
|
||||
@@ -913,13 +944,13 @@ UPDATE principal
|
||||
SET status = ?1,
|
||||
disabled_at = ?2
|
||||
WHERE id = ?3
|
||||
RETURNING id, kind, name, public_key, status, created_at, disabled_at
|
||||
RETURNING id, kind, name, public_key, status, successor_id, created_at, disabled_at
|
||||
`
|
||||
|
||||
type UpdatePrincipalStatusParams struct {
|
||||
Status string
|
||||
DisabledAt sql.NullInt64
|
||||
ID string
|
||||
ID ident.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) UpdatePrincipalStatus(ctx context.Context, arg UpdatePrincipalStatusParams) (Principal, error) {
|
||||
@@ -931,6 +962,35 @@ func (q *Queries) UpdatePrincipalStatus(ctx context.Context, arg UpdatePrincipal
|
||||
&i.Name,
|
||||
&i.PublicKey,
|
||||
&i.Status,
|
||||
&i.SuccessorID,
|
||||
&i.CreatedAt,
|
||||
&i.DisabledAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updatePrincipalSuccessor = `-- name: UpdatePrincipalSuccessor :one
|
||||
UPDATE principal
|
||||
SET successor_id = ?1
|
||||
WHERE id = ?2
|
||||
RETURNING id, kind, name, public_key, status, successor_id, created_at, disabled_at
|
||||
`
|
||||
|
||||
type UpdatePrincipalSuccessorParams struct {
|
||||
SuccessorID *ident.UUID
|
||||
ID ident.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) UpdatePrincipalSuccessor(ctx context.Context, arg UpdatePrincipalSuccessorParams) (Principal, error) {
|
||||
row := q.db.QueryRowContext(ctx, updatePrincipalSuccessor, arg.SuccessorID, arg.ID)
|
||||
var i Principal
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Kind,
|
||||
&i.Name,
|
||||
&i.PublicKey,
|
||||
&i.Status,
|
||||
&i.SuccessorID,
|
||||
&i.CreatedAt,
|
||||
&i.DisabledAt,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user