Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(psl): GA fullTextIndex for every supported provider: mysql, mongodb #5052

Merged
merged 11 commits into from
Nov 25, 2024
Merged
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ start-mongodb_5:
dev-mongodb_5: start-mongodb_5
cp $(CONFIG_PATH)/mongodb5 $(CONFIG_FILE)

dev-mongodb_5_single: start-mongodb5-single
cp $(CONFIG_PATH)/mongodb5 $(CONFIG_FILE)

dev-mongodb_4_2: start-mongodb_4_2
cp $(CONFIG_PATH)/mongodb42 $(CONFIG_FILE)

Expand Down
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
7 changes: 3 additions & 4 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 @@ -181,8 +181,7 @@ fn reformat() {
}

generator client {
provider = "prisma-client-js"
previewFeatures = ["fullTextIndex"]
provider = "prisma-client-js"
}

type A {
Expand Down
9 changes: 4 additions & 5 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 All @@ -1022,10 +1021,10 @@ fn empty_fields_must_error() {

let expected = expect![[r#"
error: Error parsing attribute "@@id": The list of fields in an `@@id()` attribute cannot be empty. Please specify at least one field.
--> schema.prisma:15
--> schema.prisma:14
 | 
14 |  name String @db.VarChar(255)
15 |  @@id([])
13 |  name String @db.VarChar(255)
14 |  @@id([])
 | 
"#]];

Expand Down
62 changes: 17 additions & 45 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 All @@ -692,22 +664,22 @@ fn index_without_fields_must_error() {

let expected = expect![[r#"
error: Error parsing attribute "@@index": The list of fields in an index cannot be empty. Please specify at least one field.
--> schema.prisma:18
--> schema.prisma:17
 | 
17 |  @@fulltext(fields:[], map: "a")
18 |  @@index(fields: [ ], map: "b")
16 |  @@fulltext(fields:[], map: "a")
17 |  @@index(fields: [ ], map: "b")
 | 
error: Error parsing attribute "@@unique": The list of fields in an index cannot be empty. Please specify at least one field.
--> schema.prisma:19
--> schema.prisma:18
 | 
18 |  @@index(fields: [ ], map: "b")
19 |  @@unique(fields: [])
17 |  @@index(fields: [ ], map: "b")
18 |  @@unique(fields: [])
 | 
error: Error parsing attribute "@@fulltext": The list of fields in an index cannot be empty. Please specify at least one field.
--> schema.prisma:17
--> schema.prisma:16
 | 
16 | 
17 |  @@fulltext(fields:[], map: "a")
15 | 
16 |  @@fulltext(fields:[], map: "a")
 | 
"#]];

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#"
error: The preview feature "foo" is not known. Expected one of: deno, driverAdapters, fullTextIndex, fullTextSearch, metrics, multiSchema, nativeDistinct, postgresqlExtensions, tracing, views, relationJoins, prismaSchemaFolder, omitApi, strictUndefinedChecks
error: The preview feature "foo" is not known. Expected one of: deno, driverAdapters, fullTextSearch, metrics, multiSchema, nativeDistinct, postgresqlExtensions, tracing, views, relationJoins, prismaSchemaFolder, omitApi, strictUndefinedChecks
--> schema.prisma:3
 | 
 2 |  provider = "prisma-client-js"
Expand Down
Loading
Loading