Libraries

This commit is contained in:
Abhishek Shroff
2024-03-13 21:34:34 +05:30
parent 970a956f96
commit e29fd4535c
17 changed files with 236 additions and 109 deletions

View File

@@ -1,9 +1,9 @@
CREATE TABLE users(
id SERIAL,
id SERIAL PRIMARY KEY,
display_name TEXT NOT NULL,
username TEXT NOT NULL,
password_hash TEXT NOT NULL,
deleted TIMESTAMP
);
CREATE UNIQUE INDEX unique_username ON users(username) WHERE deleted IS NULL;
CREATE UNIQUE INDEX unique_username ON users(username);

View File

@@ -0,0 +1 @@
DROP TABLE libraries;

View File

@@ -0,0 +1,6 @@
CREATE TABLE libraries(
id uuid PRIMARY KEY,
owner SERIAL NOT NULL REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE,
display_name TEXT NOT NULL,
deleted TIMESTAMP
);

View File

@@ -0,0 +1,9 @@
-- name: LibraryById :one
SELECT * from libraries where id = $1;
-- name: CreateLibrary :exec
INSERT INTO libraries(
id, owner, display_name
) VALUES(
$1, $2, $3
);

View File

@@ -1,9 +1,6 @@
-- name: ResourceById :one
SELECT * from resources WHERE id = $1;
-- name: LibraryByName :one
SELECT * from resources WHERE deleted IS NULL AND parent IS NULL AND name = $1;
-- name: CreateResource :exec
INSERT INTO resources(
id, parent, name, dir, created, modified