Created a base to build on
This commit is contained in:
3
db/migrations/20251222211500_add_auth_to_users.down.sql
Normal file
3
db/migrations/20251222211500_add_auth_to_users.down.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE users
|
||||
DROP COLUMN email,
|
||||
DROP COLUMN password_hash;
|
||||
3
db/migrations/20251222211500_add_auth_to_users.up.sql
Normal file
3
db/migrations/20251222211500_add_auth_to_users.up.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE users
|
||||
ADD COLUMN email TEXT NOT NULL UNIQUE,
|
||||
ADD COLUMN password_hash TEXT NOT NULL;
|
||||
67
db/query.sql
Normal file
67
db/query.sql
Normal file
@@ -0,0 +1,67 @@
|
||||
-- name: GetUser :one
|
||||
SELECT * FROM users
|
||||
WHERE id = $1 LIMIT 1;
|
||||
|
||||
-- name: ListUsers :many
|
||||
SELECT * FROM users
|
||||
ORDER BY name;
|
||||
|
||||
-- name: CreateUser :one
|
||||
INSERT INTO users (
|
||||
name, bio
|
||||
) VALUES (
|
||||
$1, $2
|
||||
)
|
||||
RETURNING *;
|
||||
|
||||
-- name: DeleteUser :exec
|
||||
DELETE FROM users
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: CreatePlatform :one
|
||||
INSERT INTO platform (
|
||||
name
|
||||
) VALUES (
|
||||
$1
|
||||
)
|
||||
RETURNING *;
|
||||
|
||||
-- name: ListPlatforms :many
|
||||
SELECT * FROM platform
|
||||
ORDER BY name;
|
||||
|
||||
-- name: CreateGame :one
|
||||
INSERT INTO game (
|
||||
name, platform_id, score, release_year, finished
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, $5
|
||||
)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetGame :one
|
||||
SELECT * FROM game
|
||||
WHERE id = $1 LIMIT 1;
|
||||
|
||||
-- name: ListGames :many
|
||||
SELECT * FROM game
|
||||
ORDER BY name;
|
||||
|
||||
-- name: UpdateGame :one
|
||||
UPDATE game
|
||||
SET name = $2, platform_id = $3, score = $4, release_year = $5, finished = $6
|
||||
WHERE id = $1
|
||||
RETURNING *;
|
||||
|
||||
-- name: DeleteGame :exec
|
||||
DELETE FROM game
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: UpdatePlatform :one
|
||||
UPDATE platform
|
||||
SET name = $2
|
||||
WHERE id = $1
|
||||
RETURNING *;
|
||||
|
||||
-- name: DeletePlatform :exec
|
||||
DELETE FROM platform
|
||||
WHERE id = $1;
|
||||
21
db/schema.sql
Normal file
21
db/schema.sql
Normal file
@@ -0,0 +1,21 @@
|
||||
CREATE TABLE users (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
name text NOT NULL,
|
||||
email text NOT NULL UNIQUE,
|
||||
password_hash text NOT NULL,
|
||||
bio text
|
||||
);
|
||||
|
||||
CREATE TABLE platform (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
name text NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE game (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
name text NOT NULL,
|
||||
platform_id BIGINT NOT NULL REFERENCES platform(id),
|
||||
score INT NOT NULL,
|
||||
release_year DATE NOT NULL,
|
||||
finished DATE
|
||||
);
|
||||
Reference in New Issue
Block a user