first database schema for sqlite3 (done as diesel migration scripts)
This commit is contained in:
parent
1f1c71f533
commit
a5c25e4abc
9
model/sqlite3/Cargo.toml
Normal file
9
model/sqlite3/Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "sqlite3"
|
||||
version = "0.1.0"
|
||||
authors = ["Gulliver <gulliver@traumkristalle.net>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
5
model/sqlite3/diesel.toml
Normal file
5
model/sqlite3/diesel.toml
Normal file
@ -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"
|
@ -0,0 +1 @@
|
||||
-- This file should undo anything in `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
|
||||
);
|
2
model/sqlite3/src/db.rs
Normal file
2
model/sqlite3/src/db.rs
Normal file
@ -0,0 +1,2 @@
|
||||
pub mod models;
|
||||
pub mod schema;
|
0
model/sqlite3/src/db/models.rs
Normal file
0
model/sqlite3/src/db/models.rs
Normal file
120
model/sqlite3/src/db/schema.rs
Normal file
120
model/sqlite3/src/db/schema.rs
Normal file
@ -0,0 +1,120 @@
|
||||
table! {
|
||||
contact_types (id) {
|
||||
id -> Nullable<Integer>,
|
||||
name -> Nullable<Text>,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
experience (id) {
|
||||
id -> Nullable<Integer>,
|
||||
name -> Nullable<Text>,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
language (id) {
|
||||
id -> Nullable<Integer>,
|
||||
name -> Nullable<Text>,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
skill (id) {
|
||||
id -> Nullable<Integer>,
|
||||
name -> Nullable<Text>,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
topic (id) {
|
||||
id -> Nullable<Integer>,
|
||||
name -> Nullable<Text>,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
user (id) {
|
||||
id -> Nullable<Integer>,
|
||||
nickname -> Nullable<Text>,
|
||||
pronouns -> Nullable<Text>,
|
||||
address_1_name -> Nullable<Text>,
|
||||
address_2_additional -> Nullable<Text>,
|
||||
address_4_street -> Nullable<Text>,
|
||||
adress_house_number -> Nullable<Text>,
|
||||
adress_city_code -> Nullable<Text>,
|
||||
adress_country -> Nullable<Text>,
|
||||
Ehrenaemter -> Nullable<Text>,
|
||||
gravatar_email -> Nullable<Text>,
|
||||
Freitext -> Nullable<Text>,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
user_contact (id) {
|
||||
id -> Nullable<Integer>,
|
||||
user_id -> Integer,
|
||||
contact_type_id -> Integer,
|
||||
content_ -> Nullable<Text>,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
user_experience (id) {
|
||||
id -> Nullable<Integer>,
|
||||
user_id -> Integer,
|
||||
description -> Nullable<Text>,
|
||||
start -> Nullable<Date>,
|
||||
end -> Nullable<Date>,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
user_language (id) {
|
||||
id -> Nullable<Integer>,
|
||||
user_id -> Integer,
|
||||
language_id -> Integer,
|
||||
level -> Nullable<Integer>,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
user_search_topic (id) {
|
||||
id -> Nullable<Integer>,
|
||||
user_id -> Integer,
|
||||
topic_id -> Integer,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
user_skill (id) {
|
||||
id -> Nullable<Integer>,
|
||||
user_id -> Integer,
|
||||
skill_id -> Nullable<Integer>,
|
||||
level -> Nullable<Integer>,
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
);
|
Loading…
Reference in New Issue
Block a user