add middlewares, handlers and database models
This commit is contained in:
parent
979a415b95
commit
7e288ea67a
24 changed files with 1045 additions and 14 deletions
25
internal/db/migrations/00002_create_tokens_table.sql
Normal file
25
internal/db/migrations/00002_create_tokens_table.sql
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
-- +goose Up
|
||||
-- +goose StatementBegin
|
||||
CREATE TABLE IF NOT EXISTS tokens (
|
||||
id TEXT PRIMARY KEY,
|
||||
user_id TEXT NOT NULL,
|
||||
type TEXT NOT NULL,
|
||||
token TEXT UNIQUE NOT NULL,
|
||||
expires_at TIMESTAMP NOT NULL,
|
||||
used_at TIMESTAMP,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_tokens_token ON tokens(token);
|
||||
CREATE INDEX IF NOT EXISTS idx_tokens_expires_at ON tokens(expires_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_tokens_user_id ON tokens(user_id);
|
||||
-- +goose StatementEnd
|
||||
|
||||
-- +goose Down
|
||||
-- +goose StatementBegin
|
||||
DROP INDEX IF EXISTS idx_tokens_user_id;
|
||||
DROP INDEX IF EXISTS idx_tokens_expires_at;
|
||||
DROP INDEX IF EXISTS idx_tokens_token;
|
||||
DROP TABLE IF EXISTS tokens;
|
||||
-- +goose StatementEnd
|
||||
19
internal/db/migrations/00003_create_profiles_table.sql
Normal file
19
internal/db/migrations/00003_create_profiles_table.sql
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
-- +goose Up
|
||||
-- +goose StatementBegin
|
||||
CREATE TABLE IF NOT EXISTS profiles (
|
||||
id TEXT PRIMARY KEY,
|
||||
user_id TEXT UNIQUE NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_profiles_user_id ON profiles(user_id);
|
||||
-- +goose StatementEnd
|
||||
|
||||
-- +goose Down
|
||||
-- +goose StatementBegin
|
||||
DROP INDEX IF EXISTS idx_profiles_user_id;
|
||||
DROP TABLE IF EXISTS profiles;
|
||||
-- +goose StatementEnd
|
||||
30
internal/db/migrations/00004_create_files_table.sql
Normal file
30
internal/db/migrations/00004_create_files_table.sql
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
-- +goose Up
|
||||
-- +goose StatementBegin
|
||||
CREATE TABLE IF NOT EXISTS files (
|
||||
id TEXT PRIMARY KEY,
|
||||
user_id TEXT NOT NULL,
|
||||
owner_type TEXT NOT NULL,
|
||||
owner_id TEXT NOT NULL,
|
||||
type TEXT NOT NULL,
|
||||
filename TEXT NOT NULL,
|
||||
original_name TEXT,
|
||||
mime_type TEXT,
|
||||
size INTEGER,
|
||||
storage_path TEXT NOT NULL,
|
||||
public BOOLEAN DEFAULT true,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_files_user_id ON files(user_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_files_owner ON files(owner_type, owner_id);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_files_owner_type ON files(owner_type, owner_id, type) WHERE type IN ('avatar');
|
||||
-- +goose StatementEnd
|
||||
|
||||
-- +goose Down
|
||||
-- +goose StatementBegin
|
||||
DROP INDEX IF EXISTS idx_files_owner_type;
|
||||
DROP INDEX IF EXISTS idx_files_owner;
|
||||
DROP INDEX IF EXISTS idx_files_user_id;
|
||||
DROP TABLE IF EXISTS files;
|
||||
-- +goose StatementEnd
|
||||
Loading…
Add table
Add a link
Reference in a new issue