This commit is contained in:
parent
764f2a879d
commit
0850dab882
2 changed files with 29 additions and 0 deletions
24
migrations/0000_users.sql
Normal file
24
migrations/0000_users.sql
Normal file
|
@ -0,0 +1,24 @@
|
|||
CREATE TYPE user_role AS ENUM ('regular', 'admin');
|
||||
CREATE TYPE session_kind AS ENUM ('api', 'user');
|
||||
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
username VARCHAR(255) NOT NULL PRIMARY KEY,
|
||||
"password" text NOT NULL,
|
||||
user_role user_role NOT NULL DEFAULT 'regular'
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS user_session (
|
||||
id UUID NOT NULL PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
token text NOT NULL,
|
||||
"user" varchar(255) NOT NULL,
|
||||
"created" timestamptz NOT NULL DEFAULT NOW(),
|
||||
"csrf" UUID NOT NULL DEFAULT gen_random_uuid(),
|
||||
"name" varchar(255)
|
||||
kind session_kind NOT NULL DEFAULT 'user',
|
||||
FOREIGN KEY("user") REFERENCES users(username)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS user_profile_pic (
|
||||
username VARCHAR(255) NOT NULL PRIMARY KEY,
|
||||
"image" bytea NOT NULL
|
||||
);
|
|
@ -5,6 +5,7 @@
|
|||
// - PkgDB Abstraction
|
||||
// - Pkg Abstraction
|
||||
|
||||
use based::get_pg;
|
||||
use based::page::{Shell, render_page};
|
||||
use based::request::{RequestContext, StringResponse};
|
||||
use maud::html;
|
||||
|
@ -38,6 +39,10 @@ pub async fn index_page(ctx: RequestContext) -> StringResponse {
|
|||
#[rocket::launch]
|
||||
async fn launch() -> _ {
|
||||
env_logger::init();
|
||||
|
||||
let pg = get_pg!();
|
||||
sqlx::migrate!("./migrations").run(pg).await.unwrap();
|
||||
|
||||
rocket::build().mount("/", routes![
|
||||
index_page,
|
||||
routes::pkg_route,
|
||||
|
|
Loading…
Add table
Reference in a new issue