Skip to content

Commit

Permalink
feat(psl): GA "fullTextIndex" for every supported provider: mysql, mo…
Browse files Browse the repository at this point in the history
…ngodb
  • Loading branch information
jkomyno committed Nov 22, 2024
1 parent 90c6eb3 commit a2d615e
Show file tree
Hide file tree
Showing 24 changed files with 80 additions and 130 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
generator js {
provider = "prisma-client-js"
previewFeatures = ["fullTextIndex"]
}

datasource db {
Expand Down
2 changes: 1 addition & 1 deletion psl/psl-core/src/common/preview_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ pub const ALL_PREVIEW_FEATURES: FeatureMap = FeatureMap {
active: enumflags2::make_bitflags!(PreviewFeature::{
Deno
| DriverAdapters
| FullTextIndex
| FullTextSearch
| Metrics
| MultiSchema
Expand All @@ -117,6 +116,7 @@ pub const ALL_PREVIEW_FEATURES: FeatureMap = FeatureMap {
| FieldReference
| FilteredRelationCount
| FilterJson
| FullTextIndex
| GroupBy
| ImprovedQueryRaw
| InteractiveTransactions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ pub(super) fn validate(ctx: &mut Context<'_>) {
indexes::field_length_prefix_supported(index, ctx);
indexes::index_algorithm_is_supported(index, ctx);
indexes::hash_index_must_not_use_sort_param(index, ctx);
indexes::fulltext_index_preview_feature_enabled(index, ctx);
indexes::fulltext_index_supported(index, ctx);
indexes::fulltext_columns_should_not_define_length(index, ctx);
indexes::fulltext_column_sort_is_supported(index, ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::{
datamodel_connector::{walker_ext_traits::*, ConnectorCapability},
diagnostics::DatamodelError,
validate::validation_pipeline::context::Context,
PreviewFeature,
};
use itertools::Itertools;
use parser_database::{walkers::IndexWalker, IndexAlgorithm};
Expand Down Expand Up @@ -87,23 +86,6 @@ pub(crate) fn field_length_prefix_supported(index: IndexWalker<'_>, ctx: &mut Co
}
}

/// `@@fulltext` attribute is not available without `fullTextIndex` preview feature.
pub(crate) fn fulltext_index_preview_feature_enabled(index: IndexWalker<'_>, ctx: &mut Context<'_>) {
if ctx.preview_features.contains(PreviewFeature::FullTextIndex) {
return;
}

if index.is_fulltext() {
let message = "You must enable `fullTextIndex` preview feature to be able to define a @@fulltext index.";

ctx.push_error(DatamodelError::new_attribute_validation_error(
message,
index.attribute_name(),
index.ast_attribute().span,
));
}
}

/// `@@fulltext` should only be available if we support it in the database.
pub(crate) fn fulltext_index_supported(index: IndexWalker<'_>, ctx: &mut Context<'_>) {
if ctx.has_capability(ConnectorCapability::FullTextIndex) {
Expand All @@ -123,10 +105,6 @@ pub(crate) fn fulltext_index_supported(index: IndexWalker<'_>, ctx: &mut Context

/// `@@fulltext` index columns should not define `length` argument.
pub(crate) fn fulltext_columns_should_not_define_length(index: IndexWalker<'_>, ctx: &mut Context<'_>) {
if !ctx.preview_features.contains(PreviewFeature::FullTextIndex) {
return;
}

if !ctx.has_capability(ConnectorCapability::FullTextIndex) {
return;
}
Expand All @@ -148,10 +126,6 @@ pub(crate) fn fulltext_columns_should_not_define_length(index: IndexWalker<'_>,

/// Only MongoDB supports sort order in a fulltext index.
pub(crate) fn fulltext_column_sort_is_supported(index: IndexWalker<'_>, ctx: &mut Context<'_>) {
if !ctx.preview_features.contains(PreviewFeature::FullTextIndex) {
return;
}

if !ctx.has_capability(ConnectorCapability::FullTextIndex) {
return;
}
Expand Down Expand Up @@ -181,10 +155,6 @@ pub(crate) fn fulltext_column_sort_is_supported(index: IndexWalker<'_>, ctx: &mu
/// @@fulltext([a(sort: Asc), b, c(sort: Asc), d])
/// ```
pub(crate) fn fulltext_text_columns_should_be_bundled_together(index: IndexWalker<'_>, ctx: &mut Context<'_>) {
if !ctx.preview_features.contains(PreviewFeature::FullTextIndex) {
return;
}

if !ctx.has_capability(ConnectorCapability::FullTextIndex) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::{
diagnostics::DatamodelError,
parser_database::ast::{WithName, WithSpan},
validate::validation_pipeline::context::Context,
PreviewFeature,
};
use parser_database::walkers::{ModelWalker, PrimaryKeyWalker};
use std::{borrow::Cow, collections::HashMap};
Expand Down Expand Up @@ -175,10 +174,6 @@ pub(crate) fn primary_key_sort_order_supported(model: ModelWalker<'_>, ctx: &mut
}

pub(crate) fn only_one_fulltext_attribute_allowed(model: ModelWalker<'_>, ctx: &mut Context<'_>) {
if !ctx.preview_features.contains(PreviewFeature::FullTextIndex) {
return;
}

if !ctx.has_capability(ConnectorCapability::FullTextIndex) {
return;
}
Expand Down
5 changes: 2 additions & 3 deletions psl/psl/tests/attributes/composite_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn simple_composite_fulltext() {
}
"#};

psl::parse_schema(with_header(schema, crate::Provider::Mongo, &["fullTextIndex"]))
psl::parse_schema(with_header(schema, crate::Provider::Mongo, &[]))
.unwrap()
.assert_has_model("B")
.assert_fulltext_on_fields(&["field"]);
Expand Down Expand Up @@ -171,7 +171,7 @@ fn reformat() {
}
"#};

let datamodel = with_header(schema, crate::Provider::Mongo, &["fullTextIndex"]);
let datamodel = with_header(schema, crate::Provider::Mongo, &[]);
let result = psl::reformat(&datamodel, 2).unwrap_or_else(|| datamodel.to_owned());

let expected = expect![[r#"
Expand All @@ -182,7 +182,6 @@ fn reformat() {
generator client {
provider = "prisma-client-js"
previewFeatures = ["fullTextIndex"]
}
type A {
Expand Down
3 changes: 1 addition & 2 deletions psl/psl/tests/attributes/id_negative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1004,8 +1004,7 @@ fn length_argument_does_not_work_with_int() {
fn empty_fields_must_error() {
let schema = r#"
generator js {
provider = "prisma-client-js"
previewFeatures = ["fullTextIndex"]
provider = "prisma-client-js"
}
datasource db {
Expand Down
44 changes: 8 additions & 36 deletions psl/psl/tests/attributes/index_negative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,33 +361,6 @@ fn hash_index_doesnt_work_on_sqlserver() {
expectation.assert_eq(&error)
}

#[test]
fn fulltext_index_no_preview_feature() {
let dml = indoc! {r#"
model A {
id Int @id
a String
b String
@@fulltext([a, b])
}
"#};

let schema = with_header(dml, Provider::Mysql, &[]);
let error = parse_unwrap_err(&schema);

let expectation = expect![[r#"
error: Error parsing attribute "@@fulltext": You must enable `fullTextIndex` preview feature to be able to define a @@fulltext index.
--> schema.prisma:16
 | 
15 | 
16 |  @@fulltext([a, b])
 | 
"#]];

expectation.assert_eq(&error)
}

#[test]
fn hash_index_doesnt_work_on_mysql() {
let dml = indoc! {r#"
Expand Down Expand Up @@ -426,7 +399,7 @@ fn fulltext_index_length_attribute() {
}
"#};

let schema = with_header(dml, Provider::Mysql, &["fullTextIndex"]);
let schema = with_header(dml, Provider::Mysql, &[]);
let error = parse_unwrap_err(&schema);

let expectation = expect![[r#"
Expand Down Expand Up @@ -479,7 +452,7 @@ fn fulltext_index_sort_attribute() {
}
"#};

let schema = with_header(dml, Provider::Mysql, &["fullTextIndex"]);
let schema = with_header(dml, Provider::Mysql, &[]);
let error = parse_unwrap_err(&schema);

let expectation = expect![[r#"
Expand Down Expand Up @@ -532,7 +505,7 @@ fn fulltext_index_postgres() {
}
"#};

let schema = with_header(dml, Provider::Postgres, &["fullTextIndex"]);
let schema = with_header(dml, Provider::Postgres, &[]);
let error = parse_unwrap_err(&schema);

let expectation = expect![[r#"
Expand All @@ -559,7 +532,7 @@ fn fulltext_index_sql_server() {
}
"#};

let schema = with_header(dml, Provider::SqlServer, &["fullTextIndex"]);
let schema = with_header(dml, Provider::SqlServer, &[]);
let error = parse_unwrap_err(&schema);

let expectation = expect![[r#"
Expand All @@ -586,7 +559,7 @@ fn fulltext_index_sqlite() {
}
"#};

let schema = with_header(dml, Provider::Sqlite, &["fullTextIndex"]);
let schema = with_header(dml, Provider::Sqlite, &[]);
let error = parse_unwrap_err(&schema);

let expectation = expect![[r#"
Expand Down Expand Up @@ -616,7 +589,7 @@ fn only_one_fulltext_index_allowed_per_model_in_mongo() {
}
"#};

let schema = with_header(dml, Provider::Mongo, &["fullTextIndex"]);
let schema = with_header(dml, Provider::Mongo, &[]);
let error = parse_unwrap_err(&schema);

let expectation = expect![[r#"
Expand Down Expand Up @@ -651,7 +624,7 @@ fn fulltext_index_fields_must_follow_each_other_in_mongo() {
}
"#};

let schema = with_header(dml, Provider::Mongo, &["fullTextIndex"]);
let schema = with_header(dml, Provider::Mongo, &[]);
let error = parse_unwrap_err(&schema);

let expectation = expect![[r#"
Expand All @@ -670,8 +643,7 @@ fn fulltext_index_fields_must_follow_each_other_in_mongo() {
fn index_without_fields_must_error() {
let schema = r#"
generator js {
provider = "prisma-client-js"
previewFeatures = ["fullTextIndex"]
provider = "prisma-client-js"
}
datasource db {
Expand Down
10 changes: 5 additions & 5 deletions psl/psl/tests/attributes/index_positive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ fn mysql_fulltext_index() {
}
"#};

psl::parse_schema(with_header(dml, Provider::Mysql, &["fullTextIndex"]))
psl::parse_schema(with_header(dml, Provider::Mysql, &[]))
.unwrap()
.assert_has_model("A")
.assert_fulltext_on_fields(&["a", "b"]);
Expand All @@ -322,7 +322,7 @@ fn mysql_fulltext_index_map() {
}
"#};

psl::parse_schema(with_header(dml, Provider::Mysql, &["fullTextIndex"]))
psl::parse_schema(with_header(dml, Provider::Mysql, &[]))
.unwrap()
.assert_has_model("A")
.assert_fulltext_on_fields(&["a", "b"])
Expand All @@ -341,7 +341,7 @@ fn fulltext_index_mongodb() {
}
"#};

psl::parse_schema(with_header(dml, Provider::Mongo, &["fullTextIndex"]))
psl::parse_schema(with_header(dml, Provider::Mongo, &[]))
.unwrap()
.assert_has_model("A")
.assert_fulltext_on_fields(&["a", "b"]);
Expand Down Expand Up @@ -380,7 +380,7 @@ fn fulltext_index_sort_mongodb() {
}
"#};

psl::parse_schema(with_header(dml, Provider::Mongo, &["fullTextIndex"]))
psl::parse_schema(with_header(dml, Provider::Mongo, &[]))
.unwrap()
.assert_has_model("A")
.assert_fulltext_on_fields(&["a", "b"])
Expand All @@ -403,7 +403,7 @@ fn multiple_fulltext_indexes_allowed_per_model_in_mysql() {
}
"#};

let schema = psl::parse_schema(with_header(dml, Provider::Mysql, &["fullTextIndex"])).unwrap();
let schema = psl::parse_schema(with_header(dml, Provider::Mysql, &[])).unwrap();
let a = schema.assert_has_model("A");

a.assert_fulltext_on_fields(&["a", "b"]);
Expand Down
8 changes: 3 additions & 5 deletions psl/psl/tests/config/generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ fn hidden_preview_features_setting_must_work() {
let schema = indoc! {r#"
generator go {
provider = "go"
previewFeatures = ["fullTextIndex"]
previewFeatures = []
}
"#};

Expand All @@ -133,9 +133,7 @@ fn hidden_preview_features_setting_must_work() {
"output": null,
"config": {},
"binaryTargets": [],
"previewFeatures": [
"fullTextIndex"
]
"previewFeatures": []
}
]"#]];

Expand Down Expand Up @@ -258,7 +256,7 @@ fn nice_error_for_unknown_generator_preview_feature() {
.unwrap_err();

let expectation = expect![[r#"
[1;91merror[0m: [1mThe preview feature "foo" is not known. Expected one of: deno, driverAdapters, fullTextIndex, fullTextSearch, metrics, multiSchema, nativeDistinct, postgresqlExtensions, tracing, views, relationJoins, prismaSchemaFolder, omitApi, strictUndefinedChecks[0m
[1;91merror[0m: [1mThe preview feature "foo" is not known. Expected one of: deno, driverAdapters, fullTextSearch, metrics, multiSchema, nativeDistinct, postgresqlExtensions, tracing, views, relationJoins, prismaSchemaFolder, omitApi, strictUndefinedChecks[0m
--> schema.prisma:3
 | 
 2 |  provider = "prisma-client-js"
Expand Down
6 changes: 2 additions & 4 deletions psl/psl/tests/reformat/reformat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,8 +944,7 @@ fn reformatting_extended_indexes_works() {
fn reformatting_with_empty_indexes() {
let schema = r#"
generator js {
provider = "prisma-client-js"
previewFeatures = ["fullTextIndex"]
provider = "prisma-client-js"
}
datasource db {
Expand All @@ -966,8 +965,7 @@ fn reformatting_with_empty_indexes() {

let expected = expect![[r#"
generator js {
provider = "prisma-client-js"
previewFeatures = ["fullTextIndex"]
provider = "prisma-client-js"
}
datasource db {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
generator client {
provider = "prisma-client-js"
previewFeatures = ["fullTextIndex"]
}

datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}

model Blog {
id String @id @map("_id")
content String
title String
@@fulltext([content, title])
}
// warning: Preview feature "fullTextIndex" is deprecated. The functionality can be used without specifying it as a preview feature.
// --> schema.prisma:3
//  | 
//  2 |  provider = "prisma-client-js"
//  3 |  previewFeatures = ["fullTextIndex"]
//  | 
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
generator client {
provider = "prisma-client-js"
previewFeatures = ["fullTextIndex"]
}

datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}

model Blog {
id Int @unique
content String
title String
@@fulltext([content, title])
}
// warning: Preview feature "fullTextIndex" is deprecated. The functionality can be used without specifying it as a preview feature.
// --> schema.prisma:3
//  | 
//  2 |  provider = "prisma-client-js"
//  3 |  previewFeatures = ["fullTextIndex"]
//  | 
Loading

0 comments on commit a2d615e

Please sign in to comment.