diff --git a/.gitignore b/.gitignore index 79f0a8d..2d7a42e 100644 --- a/.gitignore +++ b/.gitignore @@ -56,5 +56,6 @@ Cargo.lock backend/target/ +.env .env diff --git a/backend/src/schema.rs b/backend/src/schema.rs new file mode 100644 index 0000000..f1dc5de --- /dev/null +++ b/backend/src/schema.rs @@ -0,0 +1,33 @@ +// @generated automatically by Diesel CLI. + +diesel::table! { + kube_recipe_lines (recipe_id) { + recipe_id -> Uuid, + input_id -> Uuid, + } +} + +diesel::table! { + kube_recipes (id) { + id -> Uuid, + output_id -> Uuid, + } +} + +diesel::table! { + kubes (id) { + id -> Uuid, + #[max_length = 255] + name -> Varchar, + } +} + +diesel::joinable!(kube_recipe_lines -> kube_recipes (recipe_id)); +diesel::joinable!(kube_recipe_lines -> kubes (input_id)); +diesel::joinable!(kube_recipes -> kubes (output_id)); + +diesel::allow_tables_to_appear_in_same_query!( + kube_recipe_lines, + kube_recipes, + kubes, +); diff --git a/diesel.toml b/diesel.toml index c028f4a..be61e3e 100644 --- a/diesel.toml +++ b/diesel.toml @@ -2,7 +2,7 @@ # see https://diesel.rs/guides/configuring-diesel-cli [print_schema] -file = "src/schema.rs" +file = "backend/src/schema.rs" custom_type_derives = ["diesel::query_builder::QueryId"] [migrations_directory] diff --git a/migrations/2024-03-02-174331_create_init_db/down.sql b/migrations/2024-03-02-174331_create_init_db/down.sql new file mode 100644 index 0000000..2488ed7 --- /dev/null +++ b/migrations/2024-03-02-174331_create_init_db/down.sql @@ -0,0 +1,5 @@ +-- This file should undo anything in `up.sql` + +DROP TABLE kubes_recipe_lines; +DROP TABLE kubes_recipes; +DROP TABLE kubes; diff --git a/migrations/2024-03-02-174331_create_init_db/up.sql b/migrations/2024-03-02-174331_create_init_db/up.sql new file mode 100644 index 0000000..fa9479a --- /dev/null +++ b/migrations/2024-03-02-174331_create_init_db/up.sql @@ -0,0 +1,20 @@ +-- Your SQL goes here + +CREATE TABLE kubes ( + id uuid primary key, + name varchar(255) not null +); + +CREATE INDEX k_i on kubes(name); + +CREATE TABLE kube_recipes ( + id uuid primary key, + output_id uuid not null references kubes(id) +); + +CREATE TABLE kube_recipe_lines ( + recipe_id uuid primary key references kube_recipes(id), + input_id uuid not null references kubes(id) +); + +CREATE INDEX krl_i ON kube_recipe_lines(recipe_id, input_id);