Skip to content

Commit

Permalink
flow-web: fix CI build by feature-flagging models / sqlx integration
Browse files Browse the repository at this point in the history
Also update runner and wasm-bindgen version
  • Loading branch information
jgraettinger committed Aug 29, 2024
1 parent a851a1f commit 157761d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/flow-web.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:

jobs:
buildAndPublish:
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
Expand All @@ -30,8 +30,8 @@ jobs:

- name: Install wasm-bindgen
run: |
curl -sSL https://github.com/rustwasm/wasm-bindgen/releases/download/0.2.83/wasm-bindgen-0.2.83-x86_64-unknown-linux-musl.tar.gz | tar -zxv
mv wasm-bindgen-0.2.83-x86_64-unknown-linux-musl/wasm* ~/.cargo/bin/
curl -sSL https://github.com/rustwasm/wasm-bindgen/releases/download/0.2.93/wasm-bindgen-0.2.93-x86_64-unknown-linux-musl.tar.gz | tar -zxv
mv wasm-bindgen-0.2.93-x86_64-unknown-linux-musl/wasm* ~/.cargo/bin/
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
Expand Down
2 changes: 1 addition & 1 deletion crates/agent-sql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repository.workspace = true
license.workspace = true

[dependencies]
models = { path = "../models" }
models = { path = "../models", features = ["sqlx-support"] }
proto-flow = { path = "../proto-flow" }
proto-gazette = { path = "../proto-gazette" }
tables = { path = "../tables" }
Expand Down
7 changes: 6 additions & 1 deletion crates/models/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ regex = { workspace = true }
schemars = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
sqlx = { workspace = true }
sqlx = { workspace = true, optional = true }
superslice = { workspace = true }
time = { workspace = true }
unicode-normalization = { workspace = true }
Expand All @@ -29,3 +29,8 @@ validator = { workspace = true }
insta = { workspace = true }
itertools = { workspace = true }
serde_yaml = { workspace = true }

[features]
default = []

sqlx-support = ["sqlx"]
30 changes: 18 additions & 12 deletions crates/models/src/id.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use sqlx::{postgres, Decode, Encode, Type, TypeInfo};
use std::str::FromStr;

#[cfg(feature = "sqlx-support")]
use sqlx::{Decode, TypeInfo};

// Estuary epoch is the first representable timestamp in generated IDs.
// This could be zero, but subtracting |estuary_epoch| results in the
// high bit being zero for the next ~34 years,
Expand Down Expand Up @@ -106,23 +108,26 @@ impl<'de> serde::Deserialize<'de> for Id {
}
}

impl Type<postgres::Postgres> for Id {
fn type_info() -> postgres::PgTypeInfo {
postgres::PgTypeInfo::with_name("flowid")
#[cfg(feature = "sqlx-support")]
impl sqlx::Type<sqlx::postgres::Postgres> for Id {
fn type_info() -> sqlx::postgres::PgTypeInfo {
sqlx::postgres::PgTypeInfo::with_name("flowid")
}
fn compatible(ty: &postgres::PgTypeInfo) -> bool {
fn compatible(ty: &sqlx::postgres::PgTypeInfo) -> bool {
*ty == Self::type_info() || ty.name() == "MACADDR8"
}
}

#[cfg(feature = "sqlx-support")]
impl sqlx::postgres::PgHasArrayType for Id {
fn array_type_info() -> postgres::PgTypeInfo {
postgres::PgTypeInfo::with_name("_flowid")
fn array_type_info() -> sqlx::postgres::PgTypeInfo {
sqlx::postgres::PgTypeInfo::with_name("_flowid")
}
}

impl Encode<'_, postgres::Postgres> for Id {
fn encode_by_ref(&self, buf: &mut postgres::PgArgumentBuffer) -> sqlx::encode::IsNull {
#[cfg(feature = "sqlx-support")]
impl sqlx::Encode<'_, sqlx::postgres::Postgres> for Id {
fn encode_by_ref(&self, buf: &mut sqlx::postgres::PgArgumentBuffer) -> sqlx::encode::IsNull {
buf.extend_from_slice(&self.0);
sqlx::encode::IsNull::No
}
Expand All @@ -131,9 +136,10 @@ impl Encode<'_, postgres::Postgres> for Id {
// TODO(johnny): This works fine for postgres binary format, but breaks for text format.
// Fix with a proper decoder once blocking issue is resolved:
// https://github.com/launchbadge/sqlx/issues/1758
impl Decode<'_, postgres::Postgres> for Id {
fn decode(value: postgres::PgValueRef<'_>) -> Result<Self, sqlx::error::BoxDynError> {
<i64 as Decode<'_, postgres::Postgres>>::decode(value).map(|i| Self(i.to_be_bytes()))
#[cfg(feature = "sqlx-support")]
impl sqlx::Decode<'_, sqlx::postgres::Postgres> for Id {
fn decode(value: sqlx::postgres::PgValueRef<'_>) -> Result<Self, sqlx::error::BoxDynError> {
<i64 as Decode<'_, sqlx::postgres::Postgres>>::decode(value).map(|i| Self(i.to_be_bytes()))
}
}

Expand Down
4 changes: 3 additions & 1 deletion crates/models/src/references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ macro_rules! string_reference_types {
) => {

$(#[$outer])*
#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq, JsonSchema, Eq, PartialOrd, Ord, Hash, sqlx::Decode, sqlx::Encode)]
#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq, JsonSchema, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "sqlx-support", derive(sqlx::Decode, sqlx::Encode))]
#[schemars(example = "Self::example")]
pub struct $Wrapper(#[schemars(schema_with = $WrapperStr)] String);

Expand Down Expand Up @@ -140,6 +141,7 @@ macro_rules! string_reference_types {
}
}

#[cfg(feature = "sqlx-support")]
impl sqlx::Type<sqlx::Postgres> for $Wrapper {
fn type_info() -> <sqlx::Postgres as sqlx::Database>::TypeInfo {
<String as sqlx::Type<sqlx::Postgres>>::type_info()
Expand Down

0 comments on commit 157761d

Please sign in to comment.