Skip to content

Commit

Permalink
Remove v2 prefix from mutation permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
codedmart authored and danieljharvey committed Oct 25, 2024
1 parent 25971a8 commit 60a96e6
Show file tree
Hide file tree
Showing 26 changed files with 315 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ pub fn generate_delete_by_unique(
)?;

let name = format!(
"{}_delete_{collection_name}_by_{constraint_name}",
super::VERSION
"delete_{collection_name}_by_{constraint_name}"
)
.into();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn generate(
collection_name: &models::CollectionName,
table_info: &database::TableInfo,
) -> (models::ProcedureName, InsertMutation) {
let name = format!("{}_insert_{collection_name}", super::VERSION).into();
let name = format!("insert_{collection_name}").into();

let description = format!("Insert into the {collection_name} table");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//!
//! * A single insert procedure is generated per table of the form:
//!
//! > v2_insert_<table>(
//! > insert_<table>(
//! > objects: [<object>],
//! > post_check: <boolexpr>
//! > )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ pub fn generate_update_by_unique(
)?;

let name = format!(
"{}_update_{collection_name}_by_{constraint_name}",
super::VERSION
"update_{collection_name}_by_{constraint_name}"
)
.into();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"operations": [
{
"type": "procedure",
"name": "v2_insert_Artist",
"name": "insert_Artist",
"arguments": {
"objects": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"operations": [
{
"type": "procedure",
"name": "v2_insert_Dog",
"name": "insert_Dog",
"arguments": {
"objects": [{}, {}, {}, {}],
"post_check": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
source: crates/query-engine/translation/tests/tests.rs
assertion_line: 414
expression: result
---
BEGIN
ISOLATION LEVEL READ COMMITTED READ WRITE;

WITH "%0_generated_mutation" AS (
INSERT INTO
"public"."Artist"("ArtistId", "Name")
VALUES
(276, cast($1 as "pg_catalog"."varchar")),
(DEFAULT, cast($2 as "pg_catalog"."varchar")) RETURNING *,
false AS "%check__constraint"
)
SELECT
(
SELECT
json_build_object('result', row_to_json("%4_universe"), 'type', $3) AS "universe"
FROM
(
SELECT
*
FROM
(
SELECT
coalesce(json_agg(row_to_json("%5_returning")), '[]') AS "returning"
FROM
(
SELECT
"%1_Artist"."ArtistId" AS "artist_id",
"%1_Artist"."Name" AS "name"
FROM
"%0_generated_mutation" AS "%1_Artist"
) AS "%5_returning"
) AS "%5_returning"
CROSS JOIN (
SELECT
COUNT(*) AS "affected_rows"
FROM
(
SELECT
"%2_Artist".*
FROM
"%0_generated_mutation" AS "%2_Artist"
) AS "%3_Artist"
) AS "%6_aggregates"
) AS "%4_universe"
) AS "%results",
(
SELECT
coalesce(
bool_and("%7_insert_Artist"."%check__constraint"),
true
) AS "%check__constraint"
FROM
"%0_generated_mutation" AS "%7_insert_Artist"
) AS "%check__constraint";

COMMIT;

[[(1, String("Olympians")), (2, String("The Other Band")), (3, String("procedure"))]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
source: crates/query-engine/translation/tests/tests.rs
assertion_line: 423
expression: result
---
BEGIN
ISOLATION LEVEL READ COMMITTED READ WRITE;

WITH "%0_generated_mutation" AS (
INSERT INTO
"public"."Dog"
SELECT
FROM
generate_series(1, 4) RETURNING *,
true AS "%check__constraint"
)
SELECT
(
SELECT
json_build_object('result', row_to_json("%4_universe"), 'type', $1) AS "universe"
FROM
(
SELECT
*
FROM
(
SELECT
coalesce(json_agg(row_to_json("%5_returning")), '[]') AS "returning"
FROM
(
SELECT
"%1_Dog"."id" AS "id",
"%1_Dog"."adopter_name" AS "adopter_name"
FROM
"%0_generated_mutation" AS "%1_Dog"
) AS "%5_returning"
) AS "%5_returning"
CROSS JOIN (
SELECT
COUNT(*) AS "affected_rows"
FROM
(
SELECT
"%2_Dog".*
FROM
"%0_generated_mutation" AS "%2_Dog"
) AS "%3_Dog"
) AS "%6_aggregates"
) AS "%4_universe"
) AS "%results",
(
SELECT
coalesce(
bool_and("%7_insert_Dog"."%check__constraint"),
true
) AS "%check__constraint"
FROM
"%0_generated_mutation" AS "%7_insert_Dog"
) AS "%check__constraint";

COMMIT;

[[(1, String("procedure"))]]
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ SELECT
(
SELECT
coalesce(
bool_and("%7_v2_insert_Artist"."%check__constraint"),
bool_and("%7_insert_Artist"."%check__constraint"),
true
) AS "%check__constraint"
FROM
"%0_generated_mutation" AS "%7_v2_insert_Artist"
"%0_generated_mutation" AS "%7_insert_Artist"
) AS "%check__constraint";

COMMIT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ SELECT
(
SELECT
coalesce(
bool_and("%7_v2_insert_Dog"."%check__constraint"),
bool_and("%7_insert_Dog"."%check__constraint"),
true
) AS "%check__constraint"
FROM
"%0_generated_mutation" AS "%7_v2_insert_Dog"
"%0_generated_mutation" AS "%7_insert_Dog"
) AS "%check__constraint";

COMMIT;
Expand Down
8 changes: 4 additions & 4 deletions crates/query-engine/translation/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,17 +407,17 @@ mod mutations {
}

#[tokio::test]
async fn v2_insert() {
let result = common::test_mutation_translation(IsolationLevel::default(), "v2_insert")
async fn insert() {
let result = common::test_mutation_translation(IsolationLevel::default(), "insert")
.await
.unwrap();
insta::assert_snapshot!(result);
}

#[tokio::test]
async fn v2_insert_empty_objects() {
async fn insert_empty_objects() {
let result =
common::test_mutation_translation(IsolationLevel::default(), "v2_insert_empty_objects")
common::test_mutation_translation(IsolationLevel::default(), "insert_empty_objects")
.await
.unwrap();
insta::assert_snapshot!(result);
Expand Down
12 changes: 6 additions & 6 deletions crates/tests/databases-tests/src/postgres/explain_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,18 @@ mod mutation {
}

#[tokio::test]
async fn v2_insert_custom_dog() {
let result = run_mutation_explain(create_router().await, "v2_insert_custom_dog").await;
async fn insert_custom_dog() {
let result = run_mutation_explain(create_router().await, "insert_custom_dog").await;
is_contained_in_lines(
&["Insert", "Aggregate"],
result
.details
.get("0 v2_insert_custom_dog Execution Plan")
.get("0 insert_custom_dog Execution Plan")
.unwrap(),
);
insta::assert_snapshot!(result
.details
.get("0 v2_insert_custom_dog SQL Mutation")
.get("0 insert_custom_dog SQL Mutation")
.unwrap());
}

Expand All @@ -195,9 +195,9 @@ mod mutation {
}

#[tokio::test]
async fn v2_insert_update_custom_dog() {
async fn insert_update_custom_dog() {
let result =
run_mutation_explain(create_router().await, "v2_insert_update_custom_dog").await;
run_mutation_explain(create_router().await, "insert_update_custom_dog").await;
is_contained_in_lines(
&["Update", "Aggregate"],
result
Expand Down
Loading

0 comments on commit 60a96e6

Please sign in to comment.