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 }}
This repository was archived by the owner on Oct 21, 2020. It is now read-only.
Repository navigation
This repository was archived by the owner on Oct 21, 2020. It is now read-only.
Currently we map all fields of type Int @id always to an int column that is backed by a sequence. Currently it is not possible to have an int column as primary key that is not backed by a sequence.
Example:
The following example currently always maps to an int id field that is backed by a sequence.
modelUser {
idInt@id
}
The spec for PSL does not say anything about the desired behavior in this case at all. We need this to start work on the related epic.
One consideration according to @do4gr: SQLite allows for null primary keys. I don't think this is a use-case we want to support, but if there are existing SQLite databases in the wild with null primary keys, we may run into problems.
@matthewmueller : Have we ever thought of @id @default(autoIncrement()) instead of @id @pg.serial. Would be kind of nice if all the auto generated id stuff would be handled through @default(...).
What would happen if I pass it a NULL value during an update?
Hmm not sure. We would need to define what @default exactly does. My understanding so far was that it just kicks in on creates where the value is not provided by the user.
Does it work for other types?
No only for Ints i guess. I would not know what to expect from incrementing a DateTime. One more millisecond, second, hour, day, year? 🤷♂
My biggest point of feedback would be that we should try to draw a clearer line (both in terms of concepts and syntax) when a feature is implemented on the Prisma level vs when a DB feature is used (See #305).
As I answer each question separately, keep in mind that we are working towards a launch of Photon in early Q1 2020, and explicitly accepting that some questions will have to be left unanswered for the time being.
1) I can imagine a world where we'd provide Prisma-level sequences using an atomic counter.
This is far in the future, and we will have to revisit the schema when we introduce this feature
2) @default(dbProvided()) would not allow us to to spin up a replica of an existing database from a Prisma schema
This is accurate. We will need to introduce extra syntax when we work towards the Lift release following the Photon release.
3) Is it possible to have @default(dbProvided()) on something other than an @id?
Yes. The presence of a database assisted default value on a required field simply makes the input field optional.
4) What does the transition look like to migrate from @default(uuid()) to @default(dbProvided())? How about the other way?
If you have a schema like this
model User {
id String @default(uuid())
}
and change it to this:
model User {
id String @default(dbProvided())
}
then queries that create a User without explicitly setting the id will fail.
Once you migrate the database to actually have a default value for the id field, the query will start working again. You can perform this transition without disrupting your application by migrating the database first.
5) Do you anticipate a future where we transition to native default values for databases that support it?
I think this will be a different syntax. We will not explore this further before the initial Photon release.
Our old behaviour was that Int ids are auto incrementing and therefore cannot be provided by the user and are not part of the CreateInputType therefore. For CUIDs and UUIDs the user could provide them, even when they were defined as default (and only UUIDs were validated I think). Do we want to keep this behaviour? It seems not consistent atm.
id Int @id@default(autoincrement()) # you cannot set it yourself
id String @id@default(cuid()) # you can provide whatever string you want yourself
id String @id@default(uuid()) # you can provide a valid UUID yourself
Do we want to keep this behaviour? It seems not consistent atm.
No. We want it to be consistent. You should be able to provide your own id in all cases. Later we will introduce a way to make a field read-only, but that is orthogonal to this issue.
Activity
matthewmueller commentedon Oct 4, 2019
matt's note: @id jumps to definition postgres.prisma
matthewmueller commentedon Oct 10, 2019
matthewmueller commentedon Oct 18, 2019
I'm in favor of @mavilein's proposal where
@idimplies:
does not imply:
One consideration according to @do4gr: SQLite allows for null primary keys. I don't think this is a use-case we want to support, but if there are existing SQLite databases in the wild with null primary keys, we may run into problems.
mavilein commentedon Oct 18, 2019
@matthewmueller : Have we ever thought of
@id @default(autoIncrement())instead of@id @pg.serial. Would be kind of nice if all the auto generated id stuff would be handled through@default(...).matthewmueller commentedon Oct 18, 2019
Interesting idea! Two questions:
1. What would happen if I pass it a
NULLvalue during an update?Would it maintain the same autoincremented value or would it take the next value?
2. Does it work for other types?
mavilein commentedon Oct 18, 2019
@matthewmueller :
Hmm not sure. We would need to define what
@defaultexactly does. My understanding so far was that it just kicks in on creates where the value is not provided by the user.No only for Ints i guess. I would not know what to expect from incrementing a
DateTime. One more millisecond, second, hour, day, year? 🤷♂35 remaining items
schickling commentedon Dec 4, 2019
Looks mostly good from my side as well. 👍
My biggest point of feedback would be that we should try to draw a clearer line (both in terms of concepts and syntax) when a feature is implemented on the Prisma level vs when a DB feature is used (See #305).
sorenbs commentedon Dec 5, 2019
Thanks Matt!
As I answer each question separately, keep in mind that we are working towards a launch of Photon in early Q1 2020, and explicitly accepting that some questions will have to be left unanswered for the time being.
1) I can imagine a world where we'd provide Prisma-level sequences using an atomic counter.
This is far in the future, and we will have to revisit the schema when we introduce this feature
2) @default(dbProvided()) would not allow us to to spin up a replica of an existing database from a Prisma schema
This is accurate. We will need to introduce extra syntax when we work towards the Lift release following the Photon release.
3) Is it possible to have @default(dbProvided()) on something other than an @id?
Yes. The presence of a database assisted default value on a required field simply makes the input field optional.
4) What does the transition look like to migrate from @default(uuid()) to @default(dbProvided())? How about the other way?
If you have a schema like this
and change it to this:
then queries that create a User without explicitly setting the id will fail.
Once you migrate the database to actually have a default value for the id field, the query will start working again. You can perform this transition without disrupting your application by migrating the database first.
5) Do you anticipate a future where we transition to native default values for databases that support it?
I think this will be a different syntax. We will not explore this further before the initial Photon release.
sorenbs commentedon Dec 5, 2019
We have reached a decision on this issue.
I will transform it into a Spec PR with the aim to have it merged early next week.
@mavilein and @janpio - we can begin implementation.
do4gr commentedon Dec 12, 2019
One question that is not defined in the issue:
Our old behaviour was that Int ids are auto incrementing and therefore cannot be provided by the user and are not part of the CreateInputType therefore. For CUIDs and UUIDs the user could provide them, even when they were defined as default (and only UUIDs were validated I think). Do we want to keep this behaviour? It seems not consistent atm.
sorenbs commentedon Dec 12, 2019
No. We want it to be consistent. You should be able to provide your own id in all cases. Later we will introduce a way to make a field read-only, but that is orthogonal to this issue.
schickling commentedon Dec 12, 2019
Related to this we also thought of introducing a
@default(autoincrement(), writeable: false)feature in this issue.janpio commentedon Mar 3, 2020
What is left to do here @mavilein ?
mavilein commentedon Mar 20, 2020
This is done.