Skip to content

Commit

Permalink
refactor: include custom sql type defs in schema.patch
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzSchueler committed Jun 5, 2024
1 parent 2ec4903 commit 3303e0b
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ jobs:
working-directory: sport-log-types
run: |
diesel database setup # --locked-schema TODO
git restore src/schema.rs # patch src/schema.rs src/schema.patch TODO
patch src/schema.rs src/schema.patch # TODO
- name: create sport-log-server.toml file
working-directory: sport-log-server
run: |
Expand Down Expand Up @@ -191,7 +191,7 @@ jobs:
working-directory: sport-log-types
run: |
diesel database setup # --locked-schema TODO
git restore src/schema.rs # patch src/schema.rs src/schema.patch TODO
patch src/schema.rs src/schema.patch # TODO
- name: create sport-log-server.toml file
working-directory: sport-log-server
run: |
Expand Down
2 changes: 1 addition & 1 deletion sport-log-types/diesel.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[print_schema]
file = "src/schema.rs"
import_types = ["diesel::sql_types::*"]
patch_file = "src/schema.patch"
patch_file = "src/schema.patch" # TODO is not applied

[print_schema.filter]
except_tables = [
Expand Down
155 changes: 151 additions & 4 deletions sport-log-types/src/schema.patch
Original file line number Diff line number Diff line change
@@ -1,16 +1,163 @@
135c135
4,5c4,17
< #[derive(diesel::sql_types::SqlType)]
< #[diesel(postgres_type(name = "cardio_type"))]
---
> //https://github.com/diesel-rs/diesel/blob/db6730c9a79135728ec4f87fabdb745d71cb4578/diesel_derives/src/sql_type.rs
> use std::sync::atomic::{AtomicU32, Ordering};
>
> use diesel::pg::PgTypeMetadata;
>
> pub static CUSTOM_TYPES: [&(&str, AtomicU32, AtomicU32); 6] = [
> &CARDIO_TYPE,
> &DISTANCE_UNIT,
> &METCON_TYPE,
> &MOVEMENT_DIMENSION,
> &POSITION,
> &WEEKDAY,
> ];
>
8,9c20,37
< #[derive(diesel::sql_types::SqlType)]
< #[diesel(postgres_type(name = "distance_unit"))]
---
> static CARDIO_TYPE: (&str, AtomicU32, AtomicU32) =
> ("cardio_type", AtomicU32::new(0), AtomicU32::new(0));
>
> impl diesel::sql_types::SqlType for CardioType {
> type IsNull = diesel::sql_types::is_nullable::NotNull;
> }
>
> impl diesel::sql_types::SingleValue for CardioType {}
>
> impl diesel::sql_types::HasSqlType<CardioType> for diesel::pg::Pg {
> fn metadata(_: &mut Self::MetadataLookup) -> PgTypeMetadata {
> PgTypeMetadata::new(
> CARDIO_TYPE.1.load(Ordering::Acquire),
> CARDIO_TYPE.2.load(Ordering::Acquire),
> )
> }
> }
>
12,13c40,57
< #[derive(diesel::sql_types::SqlType)]
< #[diesel(postgres_type(name = "metcon_type"))]
---
> static DISTANCE_UNIT: (&str, AtomicU32, AtomicU32) =
> ("distance_unit", AtomicU32::new(0), AtomicU32::new(0));
>
> impl diesel::sql_types::SqlType for DistanceUnit {
> type IsNull = diesel::sql_types::is_nullable::NotNull;
> }
>
> impl diesel::sql_types::SingleValue for DistanceUnit {}
>
> impl diesel::sql_types::HasSqlType<DistanceUnit> for diesel::pg::Pg {
> fn metadata(_: &mut Self::MetadataLookup) -> PgTypeMetadata {
> PgTypeMetadata::new(
> DISTANCE_UNIT.1.load(Ordering::Acquire),
> DISTANCE_UNIT.2.load(Ordering::Acquire),
> )
> }
> }
>
16,17c60,77
< #[derive(diesel::sql_types::SqlType)]
< #[diesel(postgres_type(name = "movement_dimension"))]
---
> static METCON_TYPE: (&str, AtomicU32, AtomicU32) =
> ("metcon_type", AtomicU32::new(0), AtomicU32::new(0));
>
> impl diesel::sql_types::SqlType for MetconType {
> type IsNull = diesel::sql_types::is_nullable::NotNull;
> }
>
> impl diesel::sql_types::SingleValue for MetconType {}
>
> impl diesel::sql_types::HasSqlType<MetconType> for diesel::pg::Pg {
> fn metadata(_: &mut Self::MetadataLookup) -> PgTypeMetadata {
> PgTypeMetadata::new(
> METCON_TYPE.1.load(Ordering::Acquire),
> METCON_TYPE.2.load(Ordering::Acquire),
> )
> }
> }
>
20,21c80,97
< #[derive(diesel::sql_types::SqlType)]
< #[diesel(postgres_type(name = "position"))]
---
> static MOVEMENT_DIMENSION: (&str, AtomicU32, AtomicU32) =
> ("movement_dimension", AtomicU32::new(0), AtomicU32::new(0));
>
> impl diesel::sql_types::SqlType for MovementDimension {
> type IsNull = diesel::sql_types::is_nullable::NotNull;
> }
>
> impl diesel::sql_types::SingleValue for MovementDimension {}
>
> impl diesel::sql_types::HasSqlType<MovementDimension> for diesel::pg::Pg {
> fn metadata(_: &mut Self::MetadataLookup) -> PgTypeMetadata {
> PgTypeMetadata::new(
> MOVEMENT_DIMENSION.1.load(Ordering::Acquire),
> MOVEMENT_DIMENSION.2.load(Ordering::Acquire),
> )
> }
> }
>
24,25c100,117
< #[derive(diesel::sql_types::SqlType)]
< #[diesel(postgres_type(name = "weekday"))]
---
> static POSITION: (&str, AtomicU32, AtomicU32) =
> ("position", AtomicU32::new(0), AtomicU32::new(0));
>
> impl diesel::sql_types::SqlType for Position {
> type IsNull = diesel::sql_types::is_nullable::NotNull;
> }
>
> impl diesel::sql_types::SingleValue for Position {}
>
> impl diesel::sql_types::HasSqlType<Position> for diesel::pg::Pg {
> fn metadata(_: &mut Self::MetadataLookup) -> PgTypeMetadata {
> PgTypeMetadata::new(
> POSITION.1.load(Ordering::Acquire),
> POSITION.2.load(Ordering::Acquire),
> )
> }
> }
>
26a119,136
>
> static WEEKDAY: (&str, AtomicU32, AtomicU32) =
> ("weekday", AtomicU32::new(0), AtomicU32::new(0));
>
> impl diesel::sql_types::SqlType for Weekday {
> type IsNull = diesel::sql_types::is_nullable::NotNull;
> }
>
> impl diesel::sql_types::SingleValue for Weekday {}
>
> impl diesel::sql_types::HasSqlType<Weekday> for diesel::pg::Pg {
> fn metadata(_: &mut Self::MetadataLookup) -> PgTypeMetadata {
> PgTypeMetadata::new(
> WEEKDAY.1.load(Ordering::Acquire),
> WEEKDAY.2.load(Ordering::Acquire),
> )
> }
> }
109c219
< track -> Nullable<Array<Nullable<Position>>>,
---
> track -> Nullable<Array<Position>>,
137c137
111c221
< cadence -> Nullable<Array<Nullable<Int4>>>,
---
> cadence -> Nullable<Array<Int4>>,
139c139
113c223
< heart_rate -> Nullable<Array<Nullable<Int4>>>,
---
> heart_rate -> Nullable<Array<Int4>>,
342,343c342,343
304,305c414,415
< track -> Nullable<Array<Nullable<Position>>>,
< marked_positions -> Nullable<Array<Nullable<Position>>>,
---
Expand Down

0 comments on commit 3303e0b

Please sign in to comment.