forked from Roflin/gamenight
Splits database into a separate crate
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
-- This file should undo anything in `up.sql`
|
||||
|
||||
drop table pwd;
|
||||
drop table users;
|
||||
|
||||
drop type Role;
|
||||
@@ -0,0 +1,28 @@
|
||||
CREATE TYPE Role AS ENUM ('user', 'admin');
|
||||
|
||||
CREATE TABLE users (
|
||||
id UUID NOT NULL PRIMARY KEY,
|
||||
username VARCHAR UNIQUE NOT NULL,
|
||||
email VARCHAR UNIQUE NOT NULL,
|
||||
role Role NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE pwd (
|
||||
user_id UUID NOT NULL PRIMARY KEY,
|
||||
password VARCHAR NOT NULL,
|
||||
CONSTRAINT FK_UserId FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
--Initialize default admin user, with password "gamenight!"
|
||||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||
DO $$
|
||||
DECLARE
|
||||
admin_uuid uuid = uuid_generate_v4();
|
||||
BEGIN
|
||||
INSERT INTO users (id, username, email, role)
|
||||
values(admin_uuid, 'admin', '', 'admin');
|
||||
|
||||
insert INTO pwd (user_id, password)
|
||||
values(admin_uuid, '$argon2id$v=19$m=4096,t=3,p=1$zEdUjCAnZqd8DziYWzlFHw$YBLQhKvYIZBY43B8zM6hyBvLKuqTeh0EM5pKOfbWQSI');
|
||||
END $$;
|
||||
|
||||
Reference in New Issue
Block a user