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 aeff9be
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 17 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
175 changes: 161 additions & 14 deletions sport-log-types/src/schema.patch
Original file line number Diff line number Diff line change
@@ -1,18 +1,165 @@
135c135
< track -> Nullable<Array<Nullable<Position>>>,
4,17c4,5
< //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,
< ];
<
---
> track -> Nullable<Array<Position>>,
137c137
< cadence -> Nullable<Array<Nullable<Int4>>>,
> #[derive(diesel::sql_types::SqlType)]
> #[diesel(postgres_type(name = "cardio_type"))]
20,37c8,9
< 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),
< )
< }
< }
<
---
> cadence -> Nullable<Array<Int4>>,
139c139
< heart_rate -> Nullable<Array<Nullable<Int4>>>,
> #[derive(diesel::sql_types::SqlType)]
> #[diesel(postgres_type(name = "distance_unit"))]
40,57c12,13
< 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),
< )
< }
< }
<
---
> heart_rate -> Nullable<Array<Int4>>,
342,343c342,343
< track -> Nullable<Array<Nullable<Position>>>,
< marked_positions -> Nullable<Array<Nullable<Position>>>,
> #[derive(diesel::sql_types::SqlType)]
> #[diesel(postgres_type(name = "metcon_type"))]
60,77c16,17
< 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),
< )
< }
< }
<
---
> track -> Nullable<Array<Position>>,
> marked_positions -> Nullable<Array<Position>>,
> #[derive(diesel::sql_types::SqlType)]
> #[diesel(postgres_type(name = "movement_dimension"))]
80,97c20,21
< 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),
< )
< }
< }
<
---
> #[derive(diesel::sql_types::SqlType)]
> #[diesel(postgres_type(name = "position"))]
100,117c24,25
< 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),
< )
< }
< }
<
---
> #[derive(diesel::sql_types::SqlType)]
> #[diesel(postgres_type(name = "weekday"))]
119,136d26
<
< 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),
< )
< }
< }
219c109
< track -> Nullable<Array<Position>>,
---
> track -> Nullable<Array<Nullable<Position>>>,
221c111
< cadence -> Nullable<Array<Int4>>,
---
> cadence -> Nullable<Array<Nullable<Int4>>>,
223c113
< heart_rate -> Nullable<Array<Int4>>,
---
> heart_rate -> Nullable<Array<Nullable<Int4>>>,
414,415c304,305
< track -> Nullable<Array<Position>>,
< marked_positions -> Nullable<Array<Position>>,
---
> track -> Nullable<Array<Nullable<Position>>>,
> marked_positions -> Nullable<Array<Nullable<Position>>>,

0 comments on commit aeff9be

Please sign in to comment.