@@ -1030,3 +1030,76 @@ fn partial_index_object_syntax_rejects_boolean_for_enum_field() {
10301030 "# ] ] ;
10311031 expected. assert_eq ( & err) ;
10321032}
1033+
1034+ #[ test]
1035+ fn field_level_partial_unique_with_raw_on_postgres ( ) {
1036+ let dml = indoc ! { r#"
1037+ model User {
1038+ id Int @id
1039+ email String @unique(where: raw("status = 'active'"))
1040+ status String
1041+ }
1042+ "# } ;
1043+
1044+ psl:: parse_schema_without_extensions ( with_header ( dml, Provider :: Postgres , & [ "partialIndexes" ] ) )
1045+ . unwrap ( )
1046+ . assert_has_model ( "User" )
1047+ . assert_unique_on_fields ( & [ "email" ] )
1048+ . assert_raw_where_clause ( "status = 'active'" ) ;
1049+ }
1050+
1051+ #[ test]
1052+ fn field_level_partial_unique_with_object_syntax ( ) {
1053+ let dml = indoc ! { r#"
1054+ model User {
1055+ id Int @id
1056+ email String @unique(where: { active: true })
1057+ active Boolean
1058+ }
1059+ "# } ;
1060+
1061+ psl:: parse_schema_without_extensions ( with_header ( dml, Provider :: Postgres , & [ "partialIndexes" ] ) )
1062+ . unwrap ( )
1063+ . assert_has_model ( "User" )
1064+ . assert_unique_on_fields ( & [ "email" ] )
1065+ . assert_where_object ( & [ ( "active" , WhereCondition :: Equals ( WhereValue :: Boolean ( true ) ) ) ] ) ;
1066+ }
1067+
1068+ #[ test]
1069+ fn field_level_partial_unique_requires_preview_feature ( ) {
1070+ let dml = indoc ! { r#"
1071+ model User {
1072+ id Int @id
1073+ email String @unique(where: raw("status = 'active'"))
1074+ status String
1075+ }
1076+ "# } ;
1077+
1078+ let err = parse_unwrap_err ( & with_header ( dml, Provider :: Postgres , & [ ] ) ) ;
1079+ let expected = expect ! [ [ r#"
1080+ [1;91merror[0m: [1mError parsing attribute "@unique": Partial indexes are a preview feature. Add "partialIndexes" to previewFeatures in your generator block.[0m
1081+ [1;94m-->[0m [4mschema.prisma:12[0m
1082+ [1;94m | [0m
1083+ [1;94m11 | [0m id Int @id
1084+ [1;94m12 | [0m email String @unique([1;91mwhere: raw("status = 'active'")[0m)
1085+ [1;94m | [0m
1086+ "# ] ] ;
1087+ expected. assert_eq ( & err) ;
1088+ }
1089+
1090+ #[ test]
1091+ fn field_level_partial_unique_with_map ( ) {
1092+ let dml = indoc ! { r#"
1093+ model User {
1094+ id Int @id
1095+ email String @unique(map: "email_active_idx", where: raw("status = 'active'"))
1096+ status String
1097+ }
1098+ "# } ;
1099+
1100+ psl:: parse_schema_without_extensions ( with_header ( dml, Provider :: Postgres , & [ "partialIndexes" ] ) )
1101+ . unwrap ( )
1102+ . assert_has_model ( "User" )
1103+ . assert_unique_on_fields ( & [ "email" ] )
1104+ . assert_raw_where_clause ( "status = 'active'" ) ;
1105+ }
0 commit comments