Skip to content

Commit

Permalink
qe: fix 20799
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhoule committed Aug 29, 2023
1 parent 08cc777 commit abe5004
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 22 deletions.
18 changes: 1 addition & 17 deletions quaint/src/ast/index.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{Column, Table};
use super::Column;

/// A definition of a database index.
///
Expand All @@ -10,22 +10,6 @@ pub enum IndexDefinition<'a> {
}

impl<'a> IndexDefinition<'a> {
pub(crate) fn set_table<T>(self, table: T) -> Self
where
T: Into<Table<'a>>,
{
let table = table.into();

match self {
Self::Compound(columns) => {
let cols = columns.into_iter().map(|c| c.table(table.clone())).collect();

Self::Compound(cols)
}
Self::Single(column) => Self::Single(Box::new(column.table(table))),
}
}

/// At least one of the index columns has automatically generated default
/// value in the database.
pub fn has_autogen(&self) -> bool {
Expand Down
5 changes: 2 additions & 3 deletions quaint/src/ast/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ impl<'a> Table<'a> {
}

/// Add unique index definition.
pub fn add_unique_index(mut self, i: impl Into<IndexDefinition<'a>>) -> Self {
let definition = i.into();
self.index_definitions.push(definition.set_table(self.clone()));
pub fn add_unique_index(mut self, definition: impl Into<IndexDefinition<'a>>) -> Self {
self.index_definitions.push(definition.into());
self
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod prisma_15607;
mod prisma_16760;
mod prisma_17103;
mod prisma_18517;
mod prisma_20799;
mod prisma_5952;
mod prisma_6173;
mod prisma_7010;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
use query_engine_tests::*;

// before the fix to https://github.com/prisma/prisma/issues/20799, this test would consistently
// run for multiple minutes and crash with an OOM error on a fast desktop machine with 32GB of RAM.
#[test_suite(schema(schema), only(Sqlite))]
mod regression {
fn schema() -> String {
r#"
model Connection {
id Int @id @default(autoincrement())
uid String @unique
ownerId Int
atlassianOnPremiseOAuthCredentialsId Int? @unique
bitbucketCloudOAuthCredentialsId Int? @unique
genericAppCredentialsId Int? @unique
gitlabOAuthCredentialsId Int? @unique
googleSheetsOAuthCredentialsId Int? @unique
githubOAuthCredentialsId Int? @unique
mondayOAuthCredentialsId Int? @unique
serviceNowOAuthCredentialsId Int? @unique
bitbucketOnPremiseOAuthCredentialsId Int? @unique
salesforceOAuthCredentialsId Int? @unique
tempoCloudOAuthCredentialsId Int? @unique
slackCredentialsId Int?
jsmCloudAssetsApiKeyCredentialsId Int? @unique
googleCalendarOAuthCredentialsId Int? @unique
microsoftOAuthCredentialsId Int? @unique
zoomOAuthCredentialsId Int? @unique
statuspageApiKeyCredentialsId Int? @unique
trelloApiKeyCredentialsId Int? @unique
opsgenieApiKeyCredentialsId Int? @unique
one Int? @unique
two Int? @unique
three Int? @unique
four Int? @unique
five Int? @unique
six Int? @unique
seven Int? @unique
eight Int? @unique
nine Int? @unique
ten Int? @unique
}
"#
.to_owned()
}

#[connector_test]
async fn repro(runner: Runner) -> TestResult<()> {
let query = r#"
query {
findManyConnection(
where: {
ownerId: 100,
},
) { id }
}
"#;
runner.query(query).await?.assert_success();
Ok(())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use crate::{
Context,
};
use prisma_models::{walkers, ModelProjection, Relation, RelationField};
use quaint::{ast::Table, prelude::Column};
use quaint::{
ast::Table,
prelude::{Column, IndexDefinition},
};

pub(crate) trait RelationFieldExt {
fn m2m_columns(&self, ctx: &Context<'_>) -> Vec<Column<'static>>;
Expand Down Expand Up @@ -77,7 +80,7 @@ impl AsTable for Relation {
let prefix = model_a.schema_name().unwrap_or_else(|| ctx.schema_name()).to_owned();
let table: Table = (prefix, m.table_name().to_string()).into();

table.add_unique_index(vec![Column::from("A"), Column::from("B")])
table.add_unique_index(IndexDefinition::Compound(vec![Column::from("A"), Column::from("B")]))
}
walkers::RefinedRelationWalker::Inline(ref m) => {
self.dm.find_model_by_id(m.referencing_model().id).as_table(ctx)
Expand Down

0 comments on commit abe5004

Please sign in to comment.