Add basic db structure
This commit is contained in:
0
migrations/.diesel_lock
Normal file
0
migrations/.diesel_lock
Normal file
6
migrations/00000000000000_diesel_initial_setup/down.sql
Normal file
6
migrations/00000000000000_diesel_initial_setup/down.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
-- This file was automatically created by Diesel to setup helper functions
|
||||
-- and other internal bookkeeping. This file is safe to edit, any future
|
||||
-- changes will be added to existing projects as new migrations.
|
||||
|
||||
DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass);
|
||||
DROP FUNCTION IF EXISTS diesel_set_updated_at();
|
||||
36
migrations/00000000000000_diesel_initial_setup/up.sql
Normal file
36
migrations/00000000000000_diesel_initial_setup/up.sql
Normal file
@@ -0,0 +1,36 @@
|
||||
-- This file was automatically created by Diesel to setup helper functions
|
||||
-- and other internal bookkeeping. This file is safe to edit, any future
|
||||
-- changes will be added to existing projects as new migrations.
|
||||
|
||||
|
||||
|
||||
|
||||
-- Sets up a trigger for the given table to automatically set a column called
|
||||
-- `updated_at` whenever the row is modified (unless `updated_at` was included
|
||||
-- in the modified columns)
|
||||
--
|
||||
-- # Example
|
||||
--
|
||||
-- ```sql
|
||||
-- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW());
|
||||
--
|
||||
-- SELECT diesel_manage_updated_at('users');
|
||||
-- ```
|
||||
CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$
|
||||
BEGIN
|
||||
EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s
|
||||
FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl);
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$
|
||||
BEGIN
|
||||
IF (
|
||||
NEW IS DISTINCT FROM OLD AND
|
||||
NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at
|
||||
) THEN
|
||||
NEW.updated_at := current_timestamp;
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
1
migrations/2026-01-13-095817-0000_users/down.sql
Normal file
1
migrations/2026-01-13-095817-0000_users/down.sql
Normal file
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS users;
|
||||
18
migrations/2026-01-13-095817-0000_users/up.sql
Normal file
18
migrations/2026-01-13-095817-0000_users/up.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
username TEXT NOT NULL UNIQUE,
|
||||
email TEXT NOT NULL UNIQUE,
|
||||
password_hash TEXT NOT NULL,
|
||||
password_salt TEXT NOT NULL,
|
||||
first_name TEXT NOT NULL,
|
||||
last_name TEXT NOT NULL,
|
||||
display_name TEXT,
|
||||
date_of_birth DATE,
|
||||
phone_number TEXT,
|
||||
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
last_login_at TIMESTAMPTZ,
|
||||
|
||||
-- u128 bitfield for permissions
|
||||
permissions NUMERIC(39,0) NOT NULL DEFAULT 0
|
||||
)
|
||||
1
migrations/2026-01-13-095838-0000_clients/down.sql
Normal file
1
migrations/2026-01-13-095838-0000_clients/down.sql
Normal file
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS clients;
|
||||
21
migrations/2026-01-13-095838-0000_clients/up.sql
Normal file
21
migrations/2026-01-13-095838-0000_clients/up.sql
Normal file
@@ -0,0 +1,21 @@
|
||||
CREATE TABLE IF NOT EXISTS clients (
|
||||
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
email TEXT NOT NULL UNIQUE,
|
||||
|
||||
first_name TEXT NOT NULL,
|
||||
last_name TEXT NOT NULL,
|
||||
|
||||
date_of_birth DATE,
|
||||
phone_number TEXT,
|
||||
gov_id_number TEXT,
|
||||
house_number TEXT,
|
||||
address_line TEXT,
|
||||
city TEXT,
|
||||
state TEXT,
|
||||
postal_code TEXT,
|
||||
country TEXT,
|
||||
|
||||
worker_user_id BIGINT,
|
||||
|
||||
CONSTRAINT fk_worker_user_id FOREIGN KEY (worker_user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
)
|
||||
1
migrations/2026-01-13-095842-0000_warehouses/down.sql
Normal file
1
migrations/2026-01-13-095842-0000_warehouses/down.sql
Normal file
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS warehouses;
|
||||
5
migrations/2026-01-13-095842-0000_warehouses/up.sql
Normal file
5
migrations/2026-01-13-095842-0000_warehouses/up.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
CREATE TABLE IF NOT EXISTS warehouses (
|
||||
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS inventory_catalog;
|
||||
@@ -0,0 +1,6 @@
|
||||
CREATE TABLE IF NOT EXISTS inventory_catalog (
|
||||
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
description TEXT,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
)
|
||||
1
migrations/2026-01-13-095844-0000_inventory/down.sql
Normal file
1
migrations/2026-01-13-095844-0000_inventory/down.sql
Normal file
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS inventory;
|
||||
11
migrations/2026-01-13-095844-0000_inventory/up.sql
Normal file
11
migrations/2026-01-13-095844-0000_inventory/up.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
CREATE TABLE IF NOT EXISTS inventory (
|
||||
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
warehouse_id BIGINT NOT NULL,
|
||||
catalog_id BIGINT NOT NULL,
|
||||
count BIGINT NOT NULL DEFAULT 0,
|
||||
|
||||
UNIQUE (warehouse_id, catalog_id),
|
||||
|
||||
CONSTRAINT fk_warehouse_id FOREIGN KEY (warehouse_id) REFERENCES warehouses(id) ON DELETE CASCADE,
|
||||
CONSTRAINT fk_catalog_id FOREIGN KEY (catalog_id) REFERENCES inventory_catalog(id) ON DELETE CASCADE
|
||||
)
|
||||
1
migrations/2026-01-13-095855-0000_tickets/down.sql
Normal file
1
migrations/2026-01-13-095855-0000_tickets/down.sql
Normal file
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS tickets;
|
||||
3
migrations/2026-01-13-095855-0000_tickets/up.sql
Normal file
3
migrations/2026-01-13-095855-0000_tickets/up.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
CREATE TABLE IF NOT EXISTS tickets (
|
||||
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY
|
||||
)
|
||||
2
migrations/2026-01-13-101555-0000_invoices/down.sql
Normal file
2
migrations/2026-01-13-101555-0000_invoices/down.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
DROP TABLE IF EXISTS invoices;
|
||||
|
||||
7
migrations/2026-01-13-101555-0000_invoices/up.sql
Normal file
7
migrations/2026-01-13-101555-0000_invoices/up.sql
Normal file
@@ -0,0 +1,7 @@
|
||||
CREATE TABLE IF NOT EXISTS invoices (
|
||||
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
client_id BIGINT NOT NULL,
|
||||
amount REAL NOT NULL, -- f32
|
||||
|
||||
CONSTRAINT fk_client_id FOREIGN KEY (client_id) REFERENCES clients(id) ON DELETE CASCADE
|
||||
)
|
||||
2
migrations/2026-01-13-101601-0000_services/down.sql
Normal file
2
migrations/2026-01-13-101601-0000_services/down.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
DROP TABLE IF EXISTS services;
|
||||
|
||||
7
migrations/2026-01-13-101601-0000_services/up.sql
Normal file
7
migrations/2026-01-13-101601-0000_services/up.sql
Normal file
@@ -0,0 +1,7 @@
|
||||
CREATE TABLE IF NOT EXISTS services (
|
||||
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
client_id BIGINT NOT NULL,
|
||||
|
||||
CONSTRAINT fk_client_id FOREIGN KEY (client_id) REFERENCES clients(id) ON DELETE CASCADE
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS assigned_warehouse_managers;
|
||||
@@ -0,0 +1,9 @@
|
||||
CREATE TABLE IF NOT EXISTS assigned_warehouse_managers (
|
||||
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
user_id BIGINT NOT NULL,
|
||||
warehouse_id BIGINT NOT NULL,
|
||||
assigned_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
|
||||
CONSTRAINT fk_warehouse_id FOREIGN KEY (warehouse_id) REFERENCES warehouses(id) ON DELETE CASCADE,
|
||||
CONSTRAINT fk_user_id FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS warehouse_actions;
|
||||
11
migrations/2026-01-13-103443-0000_warehouse_actions/up.sql
Normal file
11
migrations/2026-01-13-103443-0000_warehouse_actions/up.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
CREATE TABLE IF NOT EXISTS warehouse_actions (
|
||||
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||
user_id BIGINT NOT NULL,
|
||||
warehouse_id BIGINT NOT NULL,
|
||||
count BIGINT NOT NULL,
|
||||
reason TEXT NOT NULL,
|
||||
timestamp TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
|
||||
CONSTRAINT fk_warehouse_id FOREIGN KEY (warehouse_id) REFERENCES warehouses(id) ON DELETE CASCADE,
|
||||
CONSTRAINT fk_user_id FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
)
|
||||
Reference in New Issue
Block a user