start sql ddl

Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
Cadey Ratio 2021-06-18 18:51:28 -04:00
parent 430fb20f57
commit 85e49669eb
8 changed files with 59 additions and 0 deletions

View File

@ -9,10 +9,15 @@ repository = "https://github.com/Xe/waifud"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
diesel_migrations = "1"
r2d2_redis = "0.14.0"
serde_json = "1"
uuid = "0.8"
[dependencies.diesel]
version = "1"
features = [ "sqlite", "r2d2", "chrono" ]
[dependencies.rocket]
version = "0.5.0-rc.1"
features = [ "secrets", "json", "uuid" ]

5
diesel.toml Normal file
View File

@ -0,0 +1,5 @@
# For documentation on how to configure this file,
# see diesel.rs/guides/configuring-diesel-cli
[print_schema]
file = "src/schema.rs"

0
migrations/.gitkeep Normal file
View File

View File

@ -0,0 +1,2 @@
DROP TABLE connections;
DROP TABLE instances;

View File

@ -0,0 +1,18 @@
CREATE TABLE IF NOT EXISTS connections
( hostname TEXT NOT NULL PRIMARY KEY
, connection_uri TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS instances
( id TEXT NOT NULL PRIMARY KEY
, "name" TEXT UNIQUE NOT NULL
, ram INTEGER NOT NULL DEFAULT 512
, cores INTEGER NOT NULL DEFAULT 2
, zvol TEXT NOT NULL
, zvol_size INTEGER NOT NULL DEFAULT 25
, use_sata BOOLEAN DEFAULT FALSE
, owner TEXT NOT NULL
, FOREIGN KEY(owner) REFERENCES connections(hostname)
);

View File

@ -30,6 +30,8 @@ in pkgs.mkShell {
redis
];
DATABASE_URL = "./var/waifud.db";
# shellHook = ''
# rm ./public/static/gruvbox.css
# ln -s ${gcss}/gruvbox.css ./public/static/gruvbox.css

26
src/schema.rs Normal file
View File

@ -0,0 +1,26 @@
table! {
connections (hostname) {
hostname -> Text,
connection_uri -> Text,
}
}
table! {
instances (id) {
id -> Text,
name -> Text,
ram -> Integer,
cores -> Integer,
zvol -> Text,
zvol_size -> Integer,
use_sata -> Nullable<Bool>,
owner -> Text,
}
}
joinable!(instances -> connections (owner));
allow_tables_to_appear_in_same_query!(
connections,
instances,
);

1
var/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.db