@@ -1,12 +1,12 @@
|
|||||||
CREATE TABLE usrmgr_users (
|
CREATE TABLE usrmgr_users (
|
||||||
id TEXT PRIMARY KEY,
|
id TEXT PRIMARY KEY,
|
||||||
created_at TIMESTAMP NOT NULL DEFAULT now(),
|
created_at TIMESTAMP NOT NULL,
|
||||||
updated_at TIMESTAMP NOT NULL DEFAULT now()
|
updated_at TIMESTAMP NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE usrmgr_sessions (
|
CREATE TABLE usrmgr_sessions (
|
||||||
id TEXT PRIMARY KEY,
|
id TEXT PRIMARY KEY,
|
||||||
user_id TEXT NOT NULL REFERENCES usrmgr_users(id),
|
user_id TEXT NOT NULL REFERENCES usrmgr_users(id),
|
||||||
created_at TIMESTAMP NOT NULL DEFAULT now(),
|
created_at TIMESTAMP NOT NULL,
|
||||||
updated_at TIMESTAMP NOT NULL DEFAULT now()
|
updated_at TIMESTAMP NOT NULL
|
||||||
);
|
);
|
||||||
|
|||||||
5
pkg/usrmgr/coredata/migrations/20250202T141800Z.sql
Normal file
5
pkg/usrmgr/coredata/migrations/20250202T141800Z.sql
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
CREATE EXTENSION citext;
|
||||||
|
|
||||||
|
ALTER TABLE usrmgr_users
|
||||||
|
ADD COLUMN email_address CITEXT NOT NULL,
|
||||||
|
ADD COLUMN hashed_password BYTEA NOT NULL;
|
||||||
1
pkg/usrmgr/coredata/migrations/20250202T180400Z.sql
Normal file
1
pkg/usrmgr/coredata/migrations/20250202T180400Z.sql
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE usrmgr_users ADD UNIQUE (email_address);
|
||||||
1
pkg/usrmgr/coredata/migrations/20250202T201400Z.sql
Normal file
1
pkg/usrmgr/coredata/migrations/20250202T201400Z.sql
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE usrmgr_sessions ADD COLUMN expired_at TIMESTAMP WITH TIME ZONE NOT NULL;
|
||||||
@@ -30,6 +30,7 @@ type (
|
|||||||
Session struct {
|
Session struct {
|
||||||
ID gid.GID
|
ID gid.GID
|
||||||
UserID gid.GID
|
UserID gid.GID
|
||||||
|
ExpiredAt time.Time
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
}
|
}
|
||||||
@@ -42,6 +43,8 @@ func (s Session) CursorKey() page.CursorKey {
|
|||||||
func (s *Session) scan(r pgx.Row) error {
|
func (s *Session) scan(r pgx.Row) error {
|
||||||
return r.Scan(
|
return r.Scan(
|
||||||
&s.ID,
|
&s.ID,
|
||||||
|
&s.UserID,
|
||||||
|
&s.ExpiredAt,
|
||||||
&s.CreatedAt,
|
&s.CreatedAt,
|
||||||
&s.UpdatedAt,
|
&s.UpdatedAt,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ package coredata
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/getprobo/probo/pkg/gid"
|
"github.com/getprobo/probo/pkg/gid"
|
||||||
@@ -28,9 +27,11 @@ import (
|
|||||||
|
|
||||||
type (
|
type (
|
||||||
User struct {
|
User struct {
|
||||||
ID gid.GID
|
ID gid.GID
|
||||||
CreatedAt time.Time
|
EmailAddress string
|
||||||
UpdatedAt time.Time
|
HashedPassword []byte
|
||||||
|
CreatedAt time.Time
|
||||||
|
UpdatedAt time.Time
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -41,6 +42,8 @@ func (u User) CursorKey() page.CursorKey {
|
|||||||
func (u *User) scan(r pgx.Row) error {
|
func (u *User) scan(r pgx.Row) error {
|
||||||
return r.Scan(
|
return r.Scan(
|
||||||
&u.ID,
|
&u.ID,
|
||||||
|
&u.EmailAddress,
|
||||||
|
&u.HashedPassword,
|
||||||
&u.CreatedAt,
|
&u.CreatedAt,
|
||||||
&u.UpdatedAt,
|
&u.UpdatedAt,
|
||||||
)
|
)
|
||||||
@@ -54,6 +57,8 @@ func (u *User) LoadByID(
|
|||||||
q := `
|
q := `
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
|
email_address,
|
||||||
|
hashed_password,
|
||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
FROM
|
FROM
|
||||||
@@ -63,8 +68,6 @@ WHERE
|
|||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
`
|
`
|
||||||
|
|
||||||
q = fmt.Sprintf(q)
|
|
||||||
|
|
||||||
args := pgx.NamedArgs{"user_id": userID}
|
args := pgx.NamedArgs{"user_id": userID}
|
||||||
|
|
||||||
r := conn.QueryRow(ctx, q, args)
|
r := conn.QueryRow(ctx, q, args)
|
||||||
|
|||||||
Reference in New Issue
Block a user