diff --git a/.gitignore b/.gitignore index 44fb03d..5d73034 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ Cargo.lock -.env \ No newline at end of file +.env + +database.sqlite \ No newline at end of file diff --git a/diesel.toml b/diesel.toml new file mode 100644 index 0000000..c028f4a --- /dev/null +++ b/diesel.toml @@ -0,0 +1,9 @@ +# For documentation on how to configure this file, +# see https://diesel.rs/guides/configuring-diesel-cli + +[print_schema] +file = "src/schema.rs" +custom_type_derives = ["diesel::query_builder::QueryId"] + +[migrations_directory] +dir = "migrations" diff --git a/migrations/.keep b/migrations/.keep new file mode 100644 index 0000000..e69de29 diff --git a/migrations/2023-08-07-063249_create_posts/down.sql b/migrations/2023-08-07-063249_create_posts/down.sql new file mode 100644 index 0000000..90de6dd --- /dev/null +++ b/migrations/2023-08-07-063249_create_posts/down.sql @@ -0,0 +1,2 @@ +DROP TABLE image; +DROP TABLE post; diff --git a/migrations/2023-08-07-063249_create_posts/up.sql b/migrations/2023-08-07-063249_create_posts/up.sql new file mode 100644 index 0000000..cb22c6e --- /dev/null +++ b/migrations/2023-08-07-063249_create_posts/up.sql @@ -0,0 +1,13 @@ +CREATE TABLE post ( + id BIGINT PRIMARY KEY NOT NULL, + description TEXT NOT NULL, + posted_date DATETIME NOT NULL, + crawled_date DATETIME NOT NULL +); + +CREATE TABLE image ( + id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + post_id BIGINT NOT NULL, + url TEXT NOT NULL, + FOREIGN KEY (post_id) REFERENCES post(id) +); diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..4197f02 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,3 @@ +pub mod controllers; +pub mod models; +pub mod schema; diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/src/schema.rs b/src/schema.rs new file mode 100644 index 0000000..41ff85b --- /dev/null +++ b/src/schema.rs @@ -0,0 +1,25 @@ +// @generated automatically by Diesel CLI. + +diesel::table! { + image (id) { + id -> Integer, + post_id -> BigInt, + url -> Text, + } +} + +diesel::table! { + post (id) { + id -> BigInt, + description -> Text, + posted_date -> Timestamp, + crawled_date -> Timestamp, + } +} + +diesel::joinable!(image -> post (post_id)); + +diesel::allow_tables_to_appear_in_same_query!( + image, + post, +);