diff --git a/model/sqlite3/Cargo.toml b/model/sqlite3/Cargo.toml new file mode 100644 index 0000000..bf2dc4d --- /dev/null +++ b/model/sqlite3/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "sqlite3" +version = "0.1.0" +authors = ["Gulliver "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/model/sqlite3/diesel.toml b/model/sqlite3/diesel.toml new file mode 100644 index 0000000..71215db --- /dev/null +++ b/model/sqlite3/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/db/schema.rs" diff --git a/model/sqlite3/migrations/2021-05-29-094109_initial_schema/down.sql b/model/sqlite3/migrations/2021-05-29-094109_initial_schema/down.sql new file mode 100644 index 0000000..291a97c --- /dev/null +++ b/model/sqlite3/migrations/2021-05-29-094109_initial_schema/down.sql @@ -0,0 +1 @@ +-- This file should undo anything in `up.sql` \ No newline at end of file diff --git a/model/sqlite3/migrations/2021-05-29-094109_initial_schema/up.sql b/model/sqlite3/migrations/2021-05-29-094109_initial_schema/up.sql new file mode 100644 index 0000000..8f50631 --- /dev/null +++ b/model/sqlite3/migrations/2021-05-29-094109_initial_schema/up.sql @@ -0,0 +1,84 @@ +CREATE TABLE IF NOT EXISTS user ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + nickname VARCHAR, + pronouns VARCHAR, + address_1_name VARCHAR, + address_2_additional VARCHAR, + address_4_street VARCHAR, + adress_house_number VARCHAR, + adress_city_code VARCHAR, + adress_country VARCHAR, + Ehrenaemter VARCHAR, + gravatar_email VARCHAR, + Freitext VARCHAR +); + +CREATE TABLE IF NOT EXISTS user_skill ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + user_id INTEGER NOT NULL, + skill_id INTEGER OT NULL, + level INTEGER, + FOREIGN KEY(user_id) REFERENCES user(id), + FOREIGN KEY(skill_id) REFERENCES skill(id) +); + +CREATE TABLE IF NOT EXISTS user_language ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + + user_id INTEGER NOT NULL, + language_id INTEGER NOT NULL, + level INTEGER, + FOREIGN KEY(user_id) REFERENCES user(id), + FOREIGN KEY(language_id) REFERENCES language(id) +); + +CREATE TABLE IF NOT EXISTS skill ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name VARCHAR +); + +CREATE TABLE IF NOT EXISTS user_experience ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + user_id INTEGER NOT NULL, + description VARCHAR, + start date, + end date, + FOREIGN KEY (user_id) REFERENCES user(id) +); + +CREATE TABLE IF NOT EXISTS user_search_topic ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + user_id INTEGER NOT NULL, + topic_id INTEGER NOT NULL, + FOREIGN KEY (user_id) REFERENCES user(id), + FOREIGN KEY (topic_id) REFERENCES topic(id) +); + +CREATE TABLE IF NOT EXISTS user_contact ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + user_id INTEGER NOT NULL, + contact_type_id INTEGER NOT NULL, + content_ VARCHAR, + FOREIGN KEY(user_id) REFERENCES user(id), + FOREIGN KEY (contact_type_id) REFERENCES contact_types(id) +); + +CREATE TABLE IF NOT EXISTS topic ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name VARCHAR +); + +CREATE TABLE IF NOT EXISTS language ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name VARCHAR +); + +CREATE TABLE IF NOT EXISTS experience ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name VARCHAR +); + +CREATE TABLE IF NOT EXISTS contact_types ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name VARCHAR +); diff --git a/model/sqlite3/src/db.rs b/model/sqlite3/src/db.rs new file mode 100644 index 0000000..d5cbad7 --- /dev/null +++ b/model/sqlite3/src/db.rs @@ -0,0 +1,2 @@ +pub mod models; +pub mod schema; diff --git a/model/sqlite3/src/db/models.rs b/model/sqlite3/src/db/models.rs new file mode 100644 index 0000000..e69de29 diff --git a/model/sqlite3/src/db/schema.rs b/model/sqlite3/src/db/schema.rs new file mode 100644 index 0000000..54a0044 --- /dev/null +++ b/model/sqlite3/src/db/schema.rs @@ -0,0 +1,120 @@ +table! { + contact_types (id) { + id -> Nullable, + name -> Nullable, + } +} + +table! { + experience (id) { + id -> Nullable, + name -> Nullable, + } +} + +table! { + language (id) { + id -> Nullable, + name -> Nullable, + } +} + +table! { + skill (id) { + id -> Nullable, + name -> Nullable, + } +} + +table! { + topic (id) { + id -> Nullable, + name -> Nullable, + } +} + +table! { + user (id) { + id -> Nullable, + nickname -> Nullable, + pronouns -> Nullable, + address_1_name -> Nullable, + address_2_additional -> Nullable, + address_4_street -> Nullable, + adress_house_number -> Nullable, + adress_city_code -> Nullable, + adress_country -> Nullable, + Ehrenaemter -> Nullable, + gravatar_email -> Nullable, + Freitext -> Nullable, + } +} + +table! { + user_contact (id) { + id -> Nullable, + user_id -> Integer, + contact_type_id -> Integer, + content_ -> Nullable, + } +} + +table! { + user_experience (id) { + id -> Nullable, + user_id -> Integer, + description -> Nullable, + start -> Nullable, + end -> Nullable, + } +} + +table! { + user_language (id) { + id -> Nullable, + user_id -> Integer, + language_id -> Integer, + level -> Nullable, + } +} + +table! { + user_search_topic (id) { + id -> Nullable, + user_id -> Integer, + topic_id -> Integer, + } +} + +table! { + user_skill (id) { + id -> Nullable, + user_id -> Integer, + skill_id -> Nullable, + level -> Nullable, + } +} + +joinable!(user_contact -> contact_types (contact_type_id)); +joinable!(user_contact -> user (user_id)); +joinable!(user_experience -> user (user_id)); +joinable!(user_language -> language (language_id)); +joinable!(user_language -> user (user_id)); +joinable!(user_search_topic -> topic (topic_id)); +joinable!(user_search_topic -> user (user_id)); +joinable!(user_skill -> skill (skill_id)); +joinable!(user_skill -> user (user_id)); + +allow_tables_to_appear_in_same_query!( + contact_types, + experience, + language, + skill, + topic, + user, + user_contact, + user_experience, + user_language, + user_search_topic, + user_skill, +);