Add database minimal files

main
kirbylife 2023-08-07 00:34:20 -06:00
parent ea66c99e6c
commit db797e2c34
8 changed files with 55 additions and 4 deletions

4
.gitignore vendored
View File

@ -2,4 +2,6 @@
Cargo.lock
.env
.env
database.sqlite

9
diesel.toml 100644
View File

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

0
migrations/.keep 100644
View File

View File

@ -0,0 +1,2 @@
DROP TABLE image;
DROP TABLE post;

View File

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

3
src/lib.rs 100644
View File

@ -0,0 +1,3 @@
pub mod controllers;
pub mod models;
pub mod schema;

View File

@ -1,3 +0,0 @@
fn main() {
println!("Hello, world!");
}

25
src/schema.rs 100644
View File

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