Skip to content

Commit

Permalink
create migration
Browse files Browse the repository at this point in the history
  • Loading branch information
shunm-999 committed Jun 5, 2024
1 parent 8cd523e commit 37f1aaf
Show file tree
Hide file tree
Showing 11 changed files with 291 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SERVER_URL="127.0.0.1"
SERVER_PORT=8080

DATABASE_URL="postgres://postgres:postgres@database:5432/talkhub"
DATABASE_URL="postgres://postgres:postgres@database:5432/talk_hub"
161 changes: 156 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions crates/database/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,32 @@ repository.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
chrono = { workspace = true }
serde = { workspace = true }
serde_with = { workspace = true }
url = { workspace = true }
serde_json = { workspace = true }
bcrypt = { workspace = true }
diesel = { workspace = true, features = [
"postgres",
"chrono",
"serde_json",
"uuid",
] }
diesel-derive-newtype = { workspace = true }
diesel-derive-enum = { workspace = true }
diesel_migrations = { workspace = true }
diesel-async = { workspace = true, features = [
"postgres",
"deadpool",
] }
regex = { workspace = true }
once_cell = { workspace = true }
diesel_ltree = { workspace = true }
async-trait = { workspace = true }
tracing = { workspace = true }
deadpool = { version = "0.12.1", features = ["rt_tokio_1"] }
tokio = { workspace = true }
tokio-postgres = { workspace = true }
uuid = { workspace = true, features = ["v4"] }
anyhow = { workspace = true }
2 changes: 2 additions & 0 deletions crates/database/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod schema;

pub fn add(left: usize, right: usize) -> usize {
left + right
}
Expand Down
23 changes: 23 additions & 0 deletions crates/database/src/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
diesel::table! {
channel(id) {
id -> Int4,
name -> Text,
description -> Text,
created_at -> Timestamp,
updated_at -> Timestamp,
}
}

diesel::table! {
message(id) {
id -> Int4,
content -> Text,
channel_id -> Int4,
created_at -> Timestamp,
updated_at -> Timestamp,
}
}

diesel::joinable!(message -> channel (channel_id));

diesel::allow_tables_to_appear_in_same_query!(channel, message);
9 changes: 9 additions & 0 deletions diesel.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# For documentation on how to configure this file,
# see https://diesel.rs/guides/configuring-diesel-cli

[print_schema]
file = "crates/database/src/schema.rs"
custom_type_derives = ["diesel::query_builder::QueryId", "Clone"]

[migrations_directory]
dir = "./migrations"
4 changes: 4 additions & 0 deletions docker/Dockerfile_database
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM postgres:16.2

RUN localedef -i ja_JP -c -f UTF-8 -A /usr/share/locale/locale.alias ja_JP.UTF-8
ENV LANG ja_JP.utf8
Loading

0 comments on commit 37f1aaf

Please sign in to comment.