Skip to content

Commit

Permalink
Add patch file to use TimestamptzSqlite instead of Timestamp, act…
Browse files Browse the repository at this point in the history
…ually insert users
  • Loading branch information
auguwu committed Oct 29, 2024
1 parent 341dd6f commit 43e33e1
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 29 deletions.
1 change: 1 addition & 0 deletions crates/database/diesel.sqlite.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
file = "src/schema/sqlite.rs"
generate_missing_sql_type_definitions = false
import_types = ["diesel::sql_types::*", "crate::schema::sql_types::*"]
patch_file = "src/schema/sqlite.rs.patch"

[migrations_directory]
dir = "./migrations/sqlite"
32 changes: 16 additions & 16 deletions crates/database/src/schema/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ diesel::table! {

api_keys (id) {
description -> Nullable<Text>,
created_at -> Timestamp,
updated_at -> Timestamp,
created_at -> TimestamptzSqlite,
updated_at -> TimestamptzSqlite,
expires_in -> Nullable<Timestamp>,
scopes -> BigInt,
owner -> Text,
Expand All @@ -39,8 +39,8 @@ diesel::table! {
display_name -> Nullable<Text>,
organization -> Text,
permissions -> BigInt,
updated_at -> Timestamp,
joined_at -> Timestamp,
updated_at -> TimestamptzSqlite,
joined_at -> TimestamptzSqlite,
account -> Text,
id -> Text,
}
Expand All @@ -55,8 +55,8 @@ diesel::table! {
twitter_handle -> Nullable<Text>,
gravatar_email -> Nullable<Text>,
display_name -> Nullable<Text>,
created_at -> Timestamp,
updated_at -> Timestamp,
created_at -> TimestamptzSqlite,
updated_at -> TimestamptzSqlite,
icon_hash -> Nullable<Text>,
private -> Bool,
owner -> Text,
Expand All @@ -72,8 +72,8 @@ diesel::table! {
repositories (id) {
description -> Nullable<Text>,
deprecated -> Bool,
created_at -> Timestamp,
updated_at -> Timestamp,
created_at -> TimestamptzSqlite,
updated_at -> TimestamptzSqlite,
icon_hash -> Nullable<Text>,
private -> Bool,
owner -> Text,
Expand All @@ -94,8 +94,8 @@ diesel::table! {
display_name -> Nullable<Text>,
permissions -> BigInt,
repository -> Text,
updated_at -> Timestamp,
joined_at -> Timestamp,
updated_at -> TimestamptzSqlite,
joined_at -> TimestamptzSqlite,
account -> Text,
id -> Text,
}
Expand All @@ -108,8 +108,8 @@ diesel::table! {
repository_releases (id) {
repository -> Text,
update_text -> Nullable<Text>,
created_at -> Timestamp,
updated_at -> Timestamp,
created_at -> TimestamptzSqlite,
updated_at -> TimestamptzSqlite,
tag -> Text,
id -> Text,
}
Expand All @@ -136,8 +136,8 @@ diesel::table! {
google_account_id -> Nullable<Text>,
github_account_id -> Nullable<Text>,
apple_account_id -> Nullable<Text>,
created_at -> Timestamp,
updated_at -> Timestamp,
created_at -> TimestamptzSqlite,
updated_at -> TimestamptzSqlite,
account -> Text,
id -> Text,
}
Expand All @@ -152,8 +152,8 @@ diesel::table! {
gravatar_email -> Nullable<Text>,
description -> Nullable<Text>,
avatar_hash -> Nullable<Text>,
created_at -> Timestamp,
updated_at -> Timestamp,
created_at -> TimestamptzSqlite,
updated_at -> TimestamptzSqlite,
username -> Text,
password -> Nullable<Text>,
email -> Text,
Expand Down
139 changes: 139 additions & 0 deletions crates/database/src/schema/sqlite.rs.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
diff --git a/crates/database/src/schema/sqlite.rs b/crates/database/src/schema/sqlite.rs
index 1287d455..7c5c312a 100644
--- a/crates/database/src/schema/sqlite.rs
+++ b/crates/database/src/schema/sqlite.rs
@@ -16,14 +16,14 @@
diesel::table! {
use diesel::sql_types::*;
use crate::schema::sql_types::*;

api_keys (id) {
description -> Nullable<Text>,
- created_at -> Timestamp,
- updated_at -> Timestamp,
+ created_at -> TimestamptzSqlite,
+ updated_at -> TimestamptzSqlite,
expires_in -> Nullable<Timestamp>,
scopes -> BigInt,
owner -> Text,
token -> Text,
name -> Text,
id -> Text,
@@ -36,14 +36,14 @@ diesel::table! {

organization_members (id) {
public_visibility -> Bool,
display_name -> Nullable<Text>,
organization -> Text,
permissions -> BigInt,
- updated_at -> Timestamp,
- joined_at -> Timestamp,
+ updated_at -> TimestamptzSqlite,
+ joined_at -> TimestamptzSqlite,
account -> Text,
id -> Text,
}
}

diesel::table! {
@@ -52,14 +52,14 @@ diesel::table! {

organizations (id) {
verified_publisher -> Bool,
twitter_handle -> Nullable<Text>,
gravatar_email -> Nullable<Text>,
display_name -> Nullable<Text>,
- created_at -> Timestamp,
- updated_at -> Timestamp,
+ created_at -> TimestamptzSqlite,
+ updated_at -> TimestamptzSqlite,
icon_hash -> Nullable<Text>,
private -> Bool,
owner -> Text,
name -> Text,
id -> Text,
}
@@ -69,14 +69,14 @@ diesel::table! {
use diesel::sql_types::*;
use crate::schema::sql_types::*;

repositories (id) {
description -> Nullable<Text>,
deprecated -> Bool,
- created_at -> Timestamp,
- updated_at -> Timestamp,
+ created_at -> TimestamptzSqlite,
+ updated_at -> TimestamptzSqlite,
icon_hash -> Nullable<Text>,
private -> Bool,
owner -> Text,
name -> Text,
#[sql_name = "type"]
type_ -> Text,
@@ -91,28 +91,28 @@ diesel::table! {

repository_members (id) {
public_visibility -> Bool,
display_name -> Nullable<Text>,
permissions -> BigInt,
repository -> Text,
- updated_at -> Timestamp,
- joined_at -> Timestamp,
+ updated_at -> TimestamptzSqlite,
+ joined_at -> TimestamptzSqlite,
account -> Text,
id -> Text,
}
}

diesel::table! {
use diesel::sql_types::*;
use crate::schema::sql_types::*;

repository_releases (id) {
repository -> Text,
update_text -> Nullable<Text>,
- created_at -> Timestamp,
- updated_at -> Timestamp,
+ created_at -> TimestamptzSqlite,
+ updated_at -> TimestamptzSqlite,
tag -> Text,
id -> Text,
}
}

diesel::table! {
@@ -133,14 +133,14 @@ diesel::table! {

user_connections (id) {
noelware_account_id -> Nullable<BigInt>,
google_account_id -> Nullable<Text>,
github_account_id -> Nullable<Text>,
apple_account_id -> Nullable<Text>,
- created_at -> Timestamp,
- updated_at -> Timestamp,
+ created_at -> TimestamptzSqlite,
+ updated_at -> TimestamptzSqlite,
account -> Text,
id -> Text,
}
}

diesel::table! {
@@ -149,14 +149,14 @@ diesel::table! {

users (id) {
verified_publisher -> Bool,
gravatar_email -> Nullable<Text>,
description -> Nullable<Text>,
avatar_hash -> Nullable<Text>,
- created_at -> Timestamp,
- updated_at -> Timestamp,
+ created_at -> TimestamptzSqlite,
+ updated_at -> TimestamptzSqlite,
username -> Text,
password -> Nullable<Text>,
email -> Text,
admin -> Bool,
name -> Nullable<Text>,
id -> Text,
25 changes: 13 additions & 12 deletions crates/server/src/routing/v1/user/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,28 +291,29 @@ pub async fn create_user(
};

connection!(@raw conn {
PostgreSQL(conn) => conn.build_transaction().read_write().run::<(), eyre::Report, _>(|txn| {
PostgreSQL(conn) => conn.build_transaction().read_write().run::<_, eyre::Report, _>(|txn| {
use postgresql::users::table;

let _ = diesel::insert_into(table)
diesel::insert_into(table)
.values(&user)
.get_result(txn)
.context("failed to insert user into database")?;

Ok(())
.execute(txn)
.context("failed to insert user into database")
});

SQLite(conn) => conn.immediate_transaction(|txn| {
use sqlite::users::table;

let _ = diesel::insert_into(table)
diesel::insert_into(table)
.values(&user)
.get_result(txn)
.context("failed to insert user into database")?;

Ok(())
.execute(txn)
.context("failed to insert user into database")
});
});
})
.inspect_err(|e| {
error!(error = %e, "failed to persist user into database");
sentry_eyre::capture_report(e);
})
.map_err(|_| api::internal_server_error())?;

ops::charts::create_index(&cx, &user)
.await
Expand Down
2 changes: 1 addition & 1 deletion crates/types/src/newtypes/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use diesel::{
deserialize::{FromSql, FromSqlRow},
expression::AsExpression,
pg::Pg,
serialize::{self, IsNull, Output, ToSql},
serialize::{self, Output, ToSql},
sql_types::{Timestamp, Timestamptz, TimestamptzSqlite},
sqlite::Sqlite,
};
Expand Down

0 comments on commit 43e33e1

Please sign in to comment.