Browse Source

start sql ddl

Signed-off-by: Christine Dodrill <[email protected]>
main
Cadey Ratio 3 months ago
parent
commit
85e49669eb
  1. 5
      Cargo.toml
  2. 5
      diesel.toml
  3. 0
      migrations/.gitkeep
  4. 2
      migrations/2021-06-18-223436_instances/down.sql
  5. 18
      migrations/2021-06-18-223436_instances/up.sql
  6. 2
      shell.nix
  7. 26
      src/schema.rs
  8. 1
      var/.gitignore

5
Cargo.toml

@ -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

@ -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

2
migrations/2021-06-18-223436_instances/down.sql

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

18
migrations/2021-06-18-223436_instances/up.sql

@ -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)
);

2
shell.nix

@ -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

@ -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

@ -0,0 +1 @@
*.db
Loading…
Cancel
Save