You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Native Types] Ensure that fields of unsupported types aren't dropped #3673
It is difficult to maintain the schema and using the client for applications dependent on types that are unsupported by Prisma.
More specifically, whenever introspecting the database, columns of unsupported types are commented out. In these situations, using migrate to update the database schema again later will trigger the deletion of the column which isn't wanted.
Suggested solution
Have a way to keep columns of unsupported types around in the database, even if not having these usable within the Prisma client.
Possibilities:
model Bla {
myField Unsupported("MACADDR")
}
// Or
model Bla {
myField Unsupported @Unsupported("MACADDR")
}
Additional context
Using $queryRaw on unsupported field types may trigger errors depending on the type as the Rust engine may not be able to deserialize it properly. I assume that going into that would probably mean to look into supporting these field types as I suspect that could be equivalent to actually supporting them.
Reacted by Jan Piotrowski, Ali, Hervé Labas and Joël Galeran
Currently, PSL does not support certain database schema components:
not all native types available (not even after the native types initiative goes live). Examples: PostGIS geolocation
models that are not valid according to certain Prisma rules, Example: models with no unique column on the table
Behaviour when using first Introspection then Migrate:
Because there is no way to represent these models/fields, introspection will put these behind comments. These comments are merely informative for the user. Since the schema parser will ignore these, they are also ignored by Prisma Migrate, leading to Prisma Migrate trying to drop the fields and columns that are not supported
Behaviour when using Migrate standalone, no introspection:
Users creating native types which are unsupported manually in their migrations, e.g. adding geolocation columns in their SQL migrations, also deal with some undesired effects:
the columns will not be reflected in the Prisma schema
Migrate will try to remove these columns the next time they generate a migration
Behaviour when using Query Engine / Client
The query engine and the client it generates currently have no knowledge of commented out columns. This means when generating the API they do not take into consideration whether there are unsupported required fields on the table. This leads to them exposing an API that contains create operations that will always fail at runtime if there is no db level default for this columns.
Solution
Introducing the Unsupported type
We solve the current problems with a 2 part solution. First we will introduce a new Unsupported type in lieu of commented out types in the Prisma to persist information about not officially supported types during re-parsing of the schema.
modelEvent {idInt@id//Prisma currently does not support this type: `Geolocation` locationUnsupported("Geolocation") @unique@default(degenerated())}
This allows our engines to retain knowledge of the existence of this column even if they are not fully able to handle it. This means:
the migration engine will no longer try to drop it when migrating
the query engine will know when unsupported columns make create operations impossible due to being required and missing defaults
Introducing the @@ignore and @ignore
A second source of commented out entities are tables that do not contain unique identifiers. This can for example be the case for join tables used in relations. Currently these need to be commented out since the query engine cannot handle them and would therefore subsequently be dropped by migrate.
The introduction of @@ignore and @ignore allows us to split missing support in the query engine from support in the migration engine. Models that the query engine cannot handle will be automatically decorated with @@ignore during introspection and not be exposed to the query engine. Migrate will still be able to operate on these and could for example be used to add a unique property. After the manual removal of the @@unique afterwards, the query engine could then operate on these.
We see two main uses cases for these: The first one is to address our current problem of migrate dropping unsupported entities if we merely comment them out. This is shown in the example above. The second use case would be developers not wanting to expose certain parts of their schema in the generated client API. In this case they could manually annotate models or fields with these directives.
Implementation
Schema level: support for Unsupported and dbgenerated(). This includes parsing, rendering and necessary validations. Introspection uses this feature instead of commenting out entities.
Schema level: support for @@ignore. This includes parsing, rendering and necessary validations. Introspection uses this feature instead of commenting out entities.
Schema level: support for @ignore. This includes parsing, rendering and necessary validations. Introspection uses this feature instead of commenting out entities.
Re-Introspection: support for the unsupported type
Re-Introspection: support for the @@ignore directive
Re-Introspection: support for the @ignore directive
Query Engine: Adjust the internal data model generation to exclude these entities from API generation
Query Engine: do not expose create operations for models with required Unsupported fields without defaults
Migrate: add limited diffing and migrate capabilities for Unsupported columns
Docs: documentation and examples for these new properties
Activity
do4gr commentedon Dec 30, 2020
Problem
Currently, PSL does not support certain database schema components:
Behaviour when using first Introspection then Migrate:
Because there is no way to represent these models/fields, introspection will put these behind comments. These comments are merely informative for the user. Since the schema parser will ignore these, they are also ignored by Prisma Migrate, leading to Prisma Migrate trying to drop the fields and columns that are not supported
Behaviour when using Migrate standalone, no introspection:
Users creating native types which are unsupported manually in their migrations, e.g. adding geolocation columns in their SQL migrations, also deal with some undesired effects:
Behaviour when using Query Engine / Client
The query engine and the client it generates currently have no knowledge of commented out columns. This means when generating the API they do not take into consideration whether there are unsupported required fields on the table. This leads to them exposing an API that contains create operations that will always fail at runtime if there is no db level default for this columns.
Solution
Introducing the
UnsupportedtypeWe solve the current problems with a 2 part solution. First we will introduce a new
Unsupportedtype in lieu of commented out types in the Prisma to persist information about not officially supported types during re-parsing of the schema.This allows our engines to retain knowledge of the existence of this column even if they are not fully able to handle it. This means:
Introducing the
@@ignoreand@ignoreA second source of commented out entities are tables that do not contain unique identifiers. This can for example be the case for join tables used in relations. Currently these need to be commented out since the query engine cannot handle them and would therefore subsequently be dropped by migrate.
The introduction of
@@ignoreand@ignoreallows us to split missing support in the query engine from support in the migration engine. Models that the query engine cannot handle will be automatically decorated with@@ignoreduring introspection and not be exposed to the query engine. Migrate will still be able to operate on these and could for example be used to add a unique property. After the manual removal of the@@uniqueafterwards, the query engine could then operate on these.The
@ignoreis the field level pendant to this.We see two main uses cases for these: The first one is to address our current problem of migrate dropping unsupported entities if we merely comment them out. This is shown in the example above. The second use case would be developers not wanting to expose certain parts of their schema in the generated client API. In this case they could manually annotate models or fields with these directives.
Implementation
Unsupportedanddbgenerated(). This includes parsing, rendering and necessary validations. Introspection uses this feature instead of commenting out entities.@@ignore. This includes parsing, rendering and necessary validations. Introspection uses this feature instead of commenting out entities.@ignore. This includes parsing, rendering and necessary validations. Introspection uses this feature instead of commenting out entities.@@ignoredirective@ignoredirectivealbertoperdomo commentedon Feb 3, 2021
Unsupportedis live, keeping this open until@ignoreand@@ignoreare fully implemented.do4gr commentedon Feb 12, 2021
This is now implemented apart from the docs part.