Skip to content

Commit

Permalink
Merge branch 'main' into quote-traceparentcomment
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel Fernández authored Nov 29, 2023
2 parents 1567853 + 5c4707e commit 6ef9f2c
Show file tree
Hide file tree
Showing 200 changed files with 582 additions and 364 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/publish-prisma-schema-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ on:
inputs:
enginesWrapperVersion:
required: true
description: 'New @prisma/prisma-schema-wasm package version'
enginesHash:
required: true
description: 'prisma-engines commit to build'
npmDistTag:
required: true
default: 'latest'
description: 'npm dist-tag (e.g. latest or integration)'

jobs:
build:
Expand Down Expand Up @@ -50,14 +53,14 @@ jobs:
#
# Failure handlers
#

- name: Set current job url in SLACK_FOOTER env var
if: ${{ failure() }}
run: echo "SLACK_FOOTER=<$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID|Click here to go to the job logs>" >> $GITHUB_ENV
- name: Slack Notification on Failure
if: ${{ failure() }}
uses: rtCamp/[email protected]
env:
SLACK_TITLE: 'prisma-schema-wasm publishing failed :x:'
SLACK_TITLE: 'Building and publishing @prisma/prisma-schema-wasm failed :x:'
SLACK_COLOR: '#FF0000'
SLACK_CHANNEL: feed-prisma-schema-wasm-publish-failures
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_WASM_FAILING }}
70 changes: 70 additions & 0 deletions .github/workflows/publish-query-engine-wasm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Build and publish @prisma/query-engine-wasm
run-name: npm - release @prisma/query-engine-wasm@${{ github.event.inputs.packageVersion }} from ${{ github.event.inputs.enginesHash }} on ${{ github.event.inputs.npmDistTag }}

concurrency: publish-query-engine-wasm

on:
# usually triggered via GH Actions Workflow in prisma/engines-wrapper repo
workflow_dispatch:
inputs:
packageVersion:
required: true
description: 'New @prisma/query-engine-wasm package version'
enginesHash:
required: true
description: 'prisma-engines commit to build'
npmDistTag:
required: true
default: 'latest'
description: 'npm dist-tag (e.g. latest or integration)'

jobs:
build:
name: Build and publish @prisma/query-engine-wasm
runs-on: ubuntu-latest
steps:
- name: Print input
run: echo "${{ toJson(github.event.inputs) }}"

- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.enginesHash }}

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'

- name: Install wasm-pack
run: cargo install wasm-pack

- name: Build @prisma/query-engine-wasm
run: ./build.sh ${{ github.event.inputs.packageVersion }}
working-directory: ./query-engine/query-engine-wasm

- name: Set up NPM token for publishing
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc

- name: Publish @prisma/query-engine-wasm
run: npm publish --access public --tag ${{ github.event.inputs.npmDistTag }}
working-directory: ./query-engine/query-engine-wasm/pkg

#
# Failure handlers
#
- name: Set current job url in SLACK_FOOTER env var
if: ${{ failure() }}
run: echo "SLACK_FOOTER=<$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID|Click here to go to the job logs>" >> $GITHUB_ENV
- name: Slack Notification on Failure
if: ${{ failure() }}
uses: rtCamp/[email protected]
env:
SLACK_TITLE: 'Building and publishing @prisma/query-engine-wasm failed :x:'
SLACK_COLOR: '#FF0000'
SLACK_CHANNEL: feed-prisma-query-engine-wasm-publish-failures
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_WASM_FAILING }}
52 changes: 26 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ members = [
"query-engine/dmmf",
"query-engine/driver-adapters",
"query-engine/metrics",
"query-engine/prisma-models",
"query-engine/query-structure",
"query-engine/query-engine",
"query-engine/query-engine-node-api",
"query-engine/query-engine-wasm",
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ services:
tmpfs: /var/lib/mariadb

vitess-test-8_0:
image: vitess/vttestserver:mysql80@sha256:8bec2644d83cb322eb2cdd596d33c0f858243ba6ade9164c95dfcc519643094e
image: vitess/vttestserver:mysql80@sha256:5a75cf290e45af3ab273bd037bdcf07f799132730f645dbe012684f28d58f8f6
restart: unless-stopped
ports:
- 33807:33807
Expand All @@ -302,7 +302,7 @@ services:
retries: 20

vitess-shadow-8_0:
image: vitess/vttestserver:mysql80@sha256:8bec2644d83cb322eb2cdd596d33c0f858243ba6ade9164c95dfcc519643094e
image: vitess/vttestserver:mysql80@sha256:5a75cf290e45af3ab273bd037bdcf07f799132730f645dbe012684f28d58f8f6
restart: unless-stopped
ports:
- 33808:33807
Expand Down
20 changes: 16 additions & 4 deletions quaint/src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,20 @@ pub trait Visitor<'a> {
Ok(())
}

fn visit_min(&mut self, min: Minimum<'a>) -> Result {
self.write("MIN")?;
self.surround_with("(", ")", |ref mut s| s.visit_column(min.column))?;

Ok(())
}

fn visit_max(&mut self, max: Maximum<'a>) -> Result {
self.write("MAX")?;
self.surround_with("(", ")", |ref mut s| s.visit_column(max.column))?;

Ok(())
}

fn visit_function(&mut self, fun: Function<'a>) -> Result {
match fun.typ_ {
FunctionType::RowNumber(fun_rownum) => {
Expand Down Expand Up @@ -1046,12 +1060,10 @@ pub trait Visitor<'a> {
self.surround_with("(", ")", |ref mut s| s.visit_expression(*upper.expression))?;
}
FunctionType::Minimum(min) => {
self.write("MIN")?;
self.surround_with("(", ")", |ref mut s| s.visit_column(min.column))?;
self.visit_min(min)?;
}
FunctionType::Maximum(max) => {
self.write("MAX")?;
self.surround_with("(", ")", |ref mut s| s.visit_column(max.column))?;
self.visit_max(max)?;
}
FunctionType::Coalesce(coalesce) => {
self.write("COALESCE")?;
Expand Down
39 changes: 39 additions & 0 deletions quaint/src/visitor/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,34 @@ impl<'a> Visitor<'a> for Postgres<'a> {

Ok(())
}

fn visit_min(&mut self, min: Minimum<'a>) -> visitor::Result {
// If the inner column is a selected enum, then we cast the result of MIN(enum)::text instead of casting the inner enum column, which changes the behavior of MIN.
let should_cast = min.column.is_enum && min.column.is_selected;

self.write("MIN")?;
self.surround_with("(", ")", |ref mut s| s.visit_column(min.column.set_is_selected(false)))?;

if should_cast {
self.write("::text")?;
}

Ok(())
}

fn visit_max(&mut self, max: Maximum<'a>) -> visitor::Result {
// If the inner column is a selected enum, then we cast the result of MAX(enum)::text instead of casting the inner enum column, which changes the behavior of MAX.
let should_cast = max.column.is_enum && max.column.is_selected;

self.write("MAX")?;
self.surround_with("(", ")", |ref mut s| s.visit_column(max.column.set_is_selected(false)))?;

if should_cast {
self.write("::text")?;
}

Ok(())
}
}

#[cfg(test)]
Expand Down Expand Up @@ -1157,4 +1185,15 @@ mod tests {

assert_eq!("SELECT \"User\".*, \"Toto\".* FROM \"User\" LEFT JOIN \"Post\" AS \"p\" ON \"p\".\"userId\" = \"User\".\"id\", \"Toto\"", sql);
}

#[test]
fn enum_cast_text_in_min_max_should_be_outside() {
let enum_col = Column::from("enum").set_is_enum(true).set_is_selected(true);
let q = Select::from_table("User")
.value(min(enum_col.clone()))
.value(max(enum_col));
let (sql, _) = Postgres::build(q).unwrap();

assert_eq!("SELECT MIN(\"enum\")::text, MAX(\"enum\")::text FROM \"User\"", sql);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ mod prisma_7010;
mod prisma_7072;
mod prisma_7434;
mod prisma_8265;
mod prisma_engines_4286;
Loading

0 comments on commit 6ef9f2c

Please sign in to comment.