Compare commits
No commits in common. "07a10fae0e6bdf8db65b8562573914012d84dcb4" and "67a8b94a69c1d96a6e566d40f8e09de83ebeedbe" have entirely different histories.
07a10fae0e
...
67a8b94a69
53
Cargo.lock
generated
53
Cargo.lock
generated
@ -187,15 +187,6 @@ dependencies = [
|
|||||||
"crossbeam-utils",
|
"crossbeam-utils",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "convert_case"
|
|
||||||
version = "0.6.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca"
|
|
||||||
dependencies = [
|
|
||||||
"unicode-segmentation",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "core-foundation"
|
name = "core-foundation"
|
||||||
version = "0.9.4"
|
version = "0.9.4"
|
||||||
@ -355,18 +346,6 @@ dependencies = [
|
|||||||
"tokio-postgres",
|
"tokio-postgres",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "diesel-derive-enum"
|
|
||||||
version = "2.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "81c5131a2895ef64741dad1d483f358c2a229a3a2d1b256778cdc5e146db64d4"
|
|
||||||
dependencies = [
|
|
||||||
"heck 0.4.1",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "diesel_derives"
|
name = "diesel_derives"
|
||||||
version = "2.2.4"
|
version = "2.2.4"
|
||||||
@ -434,7 +413,7 @@ checksum = "139ae9aca7527f85f26dd76483eb38533fd84bd571065da1739656ef71c5ff5b"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"darling",
|
"darling",
|
||||||
"either",
|
"either",
|
||||||
"heck 0.5.0",
|
"heck",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn",
|
||||||
@ -449,18 +428,6 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "enum_stringify"
|
|
||||||
version = "0.6.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f9ff9e4dbfa8fb0fd68ff9e4da874ad10774af372f0e2b8d1649c63026434d37"
|
|
||||||
dependencies = [
|
|
||||||
"convert_case",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "envconfig"
|
name = "envconfig"
|
||||||
version = "0.11.0"
|
version = "0.11.0"
|
||||||
@ -733,9 +700,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"diesel",
|
"diesel",
|
||||||
"diesel-async",
|
"diesel-async",
|
||||||
"diesel-derive-enum",
|
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
"enum_stringify",
|
|
||||||
"envconfig",
|
"envconfig",
|
||||||
"serde",
|
"serde",
|
||||||
"teloxide",
|
"teloxide",
|
||||||
@ -768,12 +733,6 @@ dependencies = [
|
|||||||
"hashbrown 0.15.2",
|
"hashbrown 0.15.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "heck"
|
|
||||||
version = "0.4.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "heck"
|
name = "heck"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
@ -1959,7 +1918,7 @@ checksum = "4e9f90acc5ab146a99bf5061a7eb4976b573f560bc898ef3bf8435448dd5e7ad"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
"either",
|
"either",
|
||||||
"heck 0.5.0",
|
"heck",
|
||||||
"hex",
|
"hex",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
@ -2172,7 +2131,7 @@ version = "0.9.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3118a980ed2ec11f73d9495a6606905bd74726e3ffe95a42fbeb187ded8fdbf4"
|
checksum = "3118a980ed2ec11f73d9495a6606905bd74726e3ffe95a42fbeb187ded8fdbf4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"heck 0.5.0",
|
"heck",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn",
|
||||||
@ -2460,12 +2419,6 @@ version = "0.1.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e70f2a8b45122e719eb623c01822704c4e0907e7e426a05927e1a1cfff5b75d0"
|
checksum = "e70f2a8b45122e719eb623c01822704c4e0907e7e426a05927e1a1cfff5b75d0"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicode-segmentation"
|
|
||||||
version = "1.12.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-xid"
|
name = "unicode-xid"
|
||||||
version = "0.2.6"
|
version = "0.2.6"
|
||||||
|
|||||||
@ -8,9 +8,7 @@ edition = "2021"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
diesel = { version = "2.2.8", features = ["postgres"] }
|
diesel = { version = "2.2.8", features = ["postgres"] }
|
||||||
diesel-async = { version = "0.5.2", features = ["bb8", "postgres"] }
|
diesel-async = { version = "0.5.2", features = ["bb8", "postgres"] }
|
||||||
diesel-derive-enum = "2.1.0"
|
|
||||||
dotenvy = "0.15.7"
|
dotenvy = "0.15.7"
|
||||||
enum_stringify = "0.6.3"
|
|
||||||
envconfig = "0.11.0"
|
envconfig = "0.11.0"
|
||||||
serde = { version = "1.0.219", features = ["derive", "serde_derive"] }
|
serde = { version = "1.0.219", features = ["derive", "serde_derive"] }
|
||||||
teloxide = { version = "0.14.0", features = ["macros", "postgres-storage-nativetls"] }
|
teloxide = { version = "0.14.0", features = ["macros", "postgres-storage-nativetls"] }
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
[print_schema]
|
[print_schema]
|
||||||
file = "src/db/schema.rs"
|
file = "src/db/schema.rs"
|
||||||
custom_type_derives = ["diesel_derive_enum::DbEnum", "diesel::query_builder::QueryId", "Clone"]
|
custom_type_derives = ["diesel::query_builder::QueryId", "Clone"]
|
||||||
|
|
||||||
[migrations_directory]
|
[migrations_directory]
|
||||||
dir = "./migrations"
|
dir = "./migrations"
|
||||||
|
|||||||
@ -1,5 +0,0 @@
|
|||||||
ALTER TABLE users
|
|
||||||
DROP COLUMN first_name,
|
|
||||||
DROP COLUMN last_name,
|
|
||||||
DROP COLUMN username,
|
|
||||||
DROP COLUMN language_code;
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
ALTER TABLE users
|
|
||||||
ADD COLUMN first_name VARCHAR(255),
|
|
||||||
ADD COLUMN last_name VARCHAR(255),
|
|
||||||
ADD COLUMN username VARCHAR(255),
|
|
||||||
ADD COLUMN language_code VARCHAR(10);
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
-- This file should undo anything in `up.sql`
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ALTER TABLE "users" ALTER COLUMN "first_name" DROP NOT NULL;
|
|
||||||
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
-- Your SQL goes here
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ALTER TABLE "users" ALTER COLUMN "first_name" SET NOT NULL;
|
|
||||||
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
DROP TABLE events;
|
|
||||||
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
CREATE TABLE events (
|
|
||||||
id SERIAL PRIMARY KEY,
|
|
||||||
time TIMESTAMP UNIQUE NOT NULL
|
|
||||||
);
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
DROP TABLE reservations;
|
|
||||||
DROP TYPE reservation_status;
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
CREATE TYPE reservation_status AS ENUM ('booked', 'paid');
|
|
||||||
|
|
||||||
CREATE TABLE reservations (
|
|
||||||
id SERIAL PRIMARY KEY,
|
|
||||||
user_id INTEGER REFERENCES users(id),
|
|
||||||
entered_name VARCHAR(255),
|
|
||||||
booked_time TIMESTAMP NOT NULL,
|
|
||||||
event_id INTEGER REFERENCES events(id),
|
|
||||||
status reservation_status NOT NULL
|
|
||||||
);
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
CREATE TYPE reservation_status AS ENUM ('booked', 'paid');
|
|
||||||
ALTER TABLE reservations ALTER COLUMN status TYPE reservation_status USING status::reservation_status;
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
ALTER TABLE reservations ALTER COLUMN status TYPE VARCHAR;
|
|
||||||
DROP TYPE reservation_status;
|
|
||||||
18
src/db.rs
18
src/db.rs
@ -9,24 +9,6 @@ use diesel_async::pooled_connection::bb8::Pool;
|
|||||||
use diesel_async::pooled_connection::AsyncDieselConnectionManager;
|
use diesel_async::pooled_connection::AsyncDieselConnectionManager;
|
||||||
use diesel_async::AsyncPgConnection;
|
use diesel_async::AsyncPgConnection;
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
use enum_stringify::EnumStringify;
|
|
||||||
|
|
||||||
#[derive(EnumStringify)]
|
|
||||||
#[enum_stringify(case = "flat")]
|
|
||||||
pub enum ReservationStatus {
|
|
||||||
Booked,
|
|
||||||
Paid,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait GetReservationStatus {
|
|
||||||
fn get_status(&self) -> Option<ReservationStatus>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetReservationStatus for models::Reservation {
|
|
||||||
fn get_status(&self) -> Option<ReservationStatus> {
|
|
||||||
ReservationStatus::try_from(self.status.clone()).ok()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct DB {
|
pub struct DB {
|
||||||
|
|||||||
@ -3,17 +3,8 @@
|
|||||||
#![allow(unused)]
|
#![allow(unused)]
|
||||||
#![allow(clippy::all)]
|
#![allow(clippy::all)]
|
||||||
|
|
||||||
|
|
||||||
use chrono::NaiveDateTime;
|
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
#[derive(Queryable, Debug, Identifiable)]
|
#[derive(Queryable, Debug)]
|
||||||
#[diesel(table_name = events)]
|
|
||||||
pub struct Event {
|
|
||||||
pub id: i32,
|
|
||||||
pub time: NaiveDateTime,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Queryable, Debug, Identifiable)]
|
|
||||||
#[diesel(table_name = literals)]
|
#[diesel(table_name = literals)]
|
||||||
pub struct Literal {
|
pub struct Literal {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
@ -21,7 +12,7 @@ pub struct Literal {
|
|||||||
pub value: String,
|
pub value: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Queryable, Debug, Identifiable)]
|
#[derive(Queryable, Debug)]
|
||||||
#[diesel(table_name = messages)]
|
#[diesel(table_name = messages)]
|
||||||
pub struct Message {
|
pub struct Message {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
@ -30,33 +21,9 @@ pub struct Message {
|
|||||||
pub token: String,
|
pub token: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Queryable, Debug, Identifiable)]
|
|
||||||
#[diesel(table_name = reservations)]
|
|
||||||
pub struct Reservation {
|
|
||||||
pub id: i32,
|
|
||||||
pub user_id: Option<i32>,
|
|
||||||
pub entered_name: Option<String>,
|
|
||||||
pub booked_time: NaiveDateTime,
|
|
||||||
pub event_id: Option<i32>,
|
|
||||||
pub status: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Queryable, Debug, Identifiable)]
|
|
||||||
#[diesel(primary_key(chat_id))]
|
|
||||||
#[diesel(table_name = teloxide_dialogues)]
|
|
||||||
pub struct TeloxideDialogue {
|
|
||||||
pub chat_id: i64,
|
|
||||||
pub dialogue: Vec<u8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Queryable, Debug)]
|
#[derive(Queryable, Debug)]
|
||||||
#[diesel(table_name = users)]
|
#[diesel(table_name = users)]
|
||||||
pub struct User {
|
pub struct User {
|
||||||
pub id: i64,
|
pub id: i64,
|
||||||
pub is_admin: bool,
|
pub is_admin: bool,
|
||||||
pub first_name: String,
|
|
||||||
pub last_name: Option<String>,
|
|
||||||
pub username: Option<String>,
|
|
||||||
pub language_code: Option<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,5 @@
|
|||||||
// @generated automatically by Diesel CLI.
|
// @generated automatically by Diesel CLI.
|
||||||
|
|
||||||
diesel::table! {
|
|
||||||
events (id) {
|
|
||||||
id -> Int4,
|
|
||||||
time -> Timestamp,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
diesel::table! {
|
diesel::table! {
|
||||||
literals (id) {
|
literals (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
@ -26,48 +19,11 @@ diesel::table! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
diesel::table! {
|
|
||||||
reservations (id) {
|
|
||||||
id -> Int4,
|
|
||||||
user_id -> Nullable<Int4>,
|
|
||||||
#[max_length = 255]
|
|
||||||
entered_name -> Nullable<Varchar>,
|
|
||||||
booked_time -> Timestamp,
|
|
||||||
event_id -> Nullable<Int4>,
|
|
||||||
status -> Varchar,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
diesel::table! {
|
|
||||||
teloxide_dialogues (chat_id) {
|
|
||||||
chat_id -> Int8,
|
|
||||||
dialogue -> Bytea,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
diesel::table! {
|
diesel::table! {
|
||||||
users (id) {
|
users (id) {
|
||||||
id -> Int8,
|
id -> Int8,
|
||||||
is_admin -> Bool,
|
is_admin -> Bool,
|
||||||
#[max_length = 255]
|
|
||||||
first_name -> Varchar,
|
|
||||||
#[max_length = 255]
|
|
||||||
last_name -> Nullable<Varchar>,
|
|
||||||
#[max_length = 255]
|
|
||||||
username -> Nullable<Varchar>,
|
|
||||||
#[max_length = 10]
|
|
||||||
language_code -> Nullable<Varchar>,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
diesel::joinable!(reservations -> events (event_id));
|
diesel::allow_tables_to_appear_in_same_query!(literals, messages, users,);
|
||||||
diesel::joinable!(reservations -> users (user_id));
|
|
||||||
|
|
||||||
diesel::allow_tables_to_appear_in_same_query!(
|
|
||||||
events,
|
|
||||||
literals,
|
|
||||||
messages,
|
|
||||||
reservations,
|
|
||||||
teloxide_dialogues,
|
|
||||||
users,
|
|
||||||
);
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user