Init user database

This commit is contained in:
Zoe Roux 2024-08-24 00:43:58 +02:00
parent 73e3c6c64b
commit 629660bb79
No known key found for this signature in database
8 changed files with 98 additions and 0 deletions

2
auth/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
# generated via sqlc
db/

11
auth/go.mod Normal file
View File

@ -0,0 +1,11 @@
module github.com/zoriya/kyoo/keibi
go 1.22.5
require (
github.com/golang-migrate/migrate/v4 v4.17.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
go.uber.org/atomic v1.7.0 // indirect
)

16
auth/go.sum Normal file
View File

@ -0,0 +1,16 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang-migrate/migrate/v4 v4.17.1 h1:4zQ6iqL6t6AiItphxJctQb3cFqWiSpMnX7wLTPnnYO4=
github.com/golang-migrate/migrate/v4 v4.17.1/go.mod h1:m8hinFyWBn0SA4QKHuKh175Pm9wjmxj3S2Mia7dbXzM=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=

View File

@ -0,0 +1,15 @@
begin;
create table users(
id uuid primary key,
username varchar(256) not null unique,
email varchar(320) not null unique,
password text,
external_handle jsonb not null,
claims jsonb not null,
created_date timestampz not null default now()::timestampz,
last_seen timestampz not null default now()::timestampz
);
commit;

View File

@ -0,0 +1,44 @@
-- name: GetAllUsers :many
select
*
from
users
order by
created_date
limit $1;
-- name: GetUser :one
select
*
from
users
where
id = $1
limit 1;
-- name: CreateUser :one
insert into users(username, email, password, external_handle, claims)
values ($1, $2, $3, $4, $5)
returning
*;
-- name: UpdateUser :one
update
users
set
username = $2,
email = $3,
password = $4,
external_handle = $5,
claims = $6
where
id = $1
returning
*;
-- name: DeleteUser :one
delete from users
where id = $1
returning
*;

9
auth/sqlc.yaml Normal file
View File

@ -0,0 +1,9 @@
version: "2"
sql:
- engine: "postgresql"
queries: "sql/queries"
schema: "sql/migrations"
gen:
go:
package: "db"
out: "db"

View File

@ -38,6 +38,7 @@ in
biome
kubernetes-helm
go-migrate
sqlc
];
DOTNET_ROOT = "${dotnet}";