Initial v2.2.0 push

This commit is contained in:
DaXcess
2024-08-12 16:14:24 +02:00
parent d1c01e9274
commit 97c18385dd
97 changed files with 7252 additions and 5211 deletions
View 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();
@@ -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;
@@ -0,0 +1,9 @@
-- Tables
DROP TABLE "account";
DROP TABLE "link_request";
DROP TABLE "user";
-- Trigger functions
DROP FUNCTION IF EXISTS update_last_updated_column();
@@ -0,0 +1,43 @@
-- Trigger functions
CREATE OR REPLACE FUNCTION update_last_updated_column()
RETURNS TRIGGER AS $$
BEGIN
NEW.last_updated = NOW();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
-- Tables
CREATE TABLE "user" (
id VARCHAR PRIMARY KEY,
device_name VARCHAR(32) NOT NULL DEFAULT 'Spoticord'
);
CREATE TABLE "link_request" (
token TEXT PRIMARY KEY,
user_id TEXT UNIQUE NOT NULL,
expires TIMESTAMP NOT NULL,
CONSTRAINT fk_user_id FOREIGN KEY (user_id) REFERENCES "user" (id)
);
CREATE TABLE "account" (
user_id VARCHAR PRIMARY KEY,
username VARCHAR(64) NOT NULL,
access_token VARCHAR(1024) NOT NULL,
refresh_token VARCHAR(1024) NOT NULL,
session_token VARCHAR(1024),
expires TIMESTAMP NOT NULL,
last_updated TIMESTAMP NOT NULL DEFAULT NOW(),
CONSTRAINT fk_account_user_id FOREIGN KEY (user_id) REFERENCES "user" (id)
);
-- Triggers
CREATE TRIGGER update_last_updated_column
BEFORE UPDATE ON "account"
FOR EACH ROW
EXECUTE FUNCTION update_last_updated_column();