Store messages into table, required docker container to create table
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
// use std::path::Path;
|
||||
|
||||
use diesel::r2d2::{Pool, ConnectionManager};
|
||||
use diesel::pg::PgConnection;
|
||||
@@ -7,25 +7,39 @@ use diesel::pg::PgConnection;
|
||||
pub mod models;
|
||||
pub mod schema;
|
||||
|
||||
pub fn run_migrations(pool: &Pool<ConnectionManager<PgConnection>>) {
|
||||
let mut connection = pool.get().unwrap();
|
||||
let migrations_dir = Path::new("./migrations");
|
||||
let migrations = std::fs::read_dir(&migrations_dir).unwrap();
|
||||
// pub fn run_migrations(pool: &Pool<ConnectionManager<PgConnection>>) {
|
||||
// let mut connection = pool.get().unwrap();
|
||||
// let migrations_dir = Path::new("./migrations");
|
||||
// let migrations = std::fs::read_dir(&migrations_dir).unwrap();
|
||||
|
||||
for migration in migrations {
|
||||
if migration.as_ref().unwrap().file_type().unwrap().is_dir() {
|
||||
let migration_paths = std::fs::read_dir(&migration.unwrap().path()).unwrap();
|
||||
// for migration in migrations {
|
||||
// if migration.as_ref().unwrap().file_type().unwrap().is_dir() {
|
||||
// let migration_paths = std::fs::read_dir(&migration.unwrap().path()).unwrap();
|
||||
|
||||
for migration_path in migration_paths {
|
||||
if migration_path.as_ref().unwrap().file_name().eq_ignore_ascii_case("up.sql") {
|
||||
let path = &migration_path.unwrap().path();
|
||||
let contents = std::fs::read_to_string(path).expect("Unable to read from file");
|
||||
// connection.build_transaction()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// for migration_path in migration_paths {
|
||||
// if migration_path.as_ref().unwrap().file_name().eq_ignore_ascii_case("up.sql") {
|
||||
// let path = &migration_path.unwrap().path();
|
||||
// let contents = std::fs::read_to_string(path).expect("Unable to read from file");
|
||||
// connection.build_transaction()
|
||||
// connection.build_transaction()
|
||||
// .read_write()
|
||||
// .run(|conn| {
|
||||
// // let read_attempt = users.select(name).load::<String>(conn);
|
||||
// // assert!(read_attempt.is_ok());
|
||||
|
||||
// // let write_attempt = diesel::insert_into(users)
|
||||
// // .values(name.eq("Ruby"))
|
||||
// // .execute(conn);
|
||||
// // assert!(write_attempt.is_ok());
|
||||
// // diesel::migration::CREATE_MIGRATIONS_TABLE
|
||||
|
||||
// // Ok(())
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
pub fn establish_connection() -> Pool<ConnectionManager<PgConnection>> {
|
||||
let database_user = env::var("POSTGRES_USER").expect("Expected a user in the environment");
|
||||
|
||||
@@ -5,7 +5,7 @@ use super::schema::messages;
|
||||
#[derive(Queryable, Selectable)]
|
||||
#[diesel(table_name = messages)]
|
||||
pub struct MessageDB {
|
||||
pub id: i64,
|
||||
pub id: String,
|
||||
pub guild_id: i64,
|
||||
pub channel_id: i64,
|
||||
pub user_id: i64,
|
||||
@@ -20,7 +20,7 @@ pub struct MessageDB {
|
||||
#[derive(Insertable)]
|
||||
#[diesel(table_name = messages)]
|
||||
pub struct NewMessageDB<'a> {
|
||||
pub id: i64,
|
||||
pub id: &'a str,
|
||||
pub guild_id: i64,
|
||||
pub channel_id: i64,
|
||||
pub user_id: i64,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
diesel::table! {
|
||||
messages (id) {
|
||||
id -> BigInt,
|
||||
id -> Text,
|
||||
guild_id -> BigInt,
|
||||
channel_id -> BigInt,
|
||||
user_id -> BigInt,
|
||||
|
||||
Reference in New Issue
Block a user