Prisma1: Support Int with id fields and migrations

Created on 2 Oct 2018  Â·  18Comments  Â·  Source: prisma/prisma1

Is your feature request related to a problem? Please describe.
Currently, the id fields can only be either of type ID or UUID.

For use cases that want auto-increment integers for ids can do so now with migrations: false and existing tables.

Describe the solution you'd like
Would be great if Int were supported as well like this

id: Int! @serial @unique

Describe alternatives you've considered
The alternative to this is having an existing schema with integer, write / generate graphql schema using introspection and deploying to the server with migrations: false

kinfeature aredatamodel

Most helpful comment

I think for Int you need to define a sequence

type Test {
  id: Int! @id(strategy: SEQUENCE) @sequence(name: "MY_SEQUENCE" initialValue:1 allocationSize:100)
  name: String!
}

cc @mavilein , please clarify this

All 18 comments

I have just published spec that touches on this topic. We would love to hear your feedback on this one.

@divyenduz I want to use Int for ids. If I don't want prisma to handle db migrations, is there any other problem with using int for id?

@brafdlog : Not that we know of. Some users are already running this in production.

So in theory it's possible to use Ints for id fields ? If I do this and deploy I get this error (at least with demo servers) :

The field `id` is reserved and has to have the format: id: ID! @unique or id: UUID! @unique.

@jide The new datamodel will be available in today's beta release under prototype flag in prisma.yml

I think then you will be able to use it.

That's fantastic !

So adding :

prototype: true

in prisma.yml should enable the new datamodel ?

It is currently in alpha. Please wait till we release today's beta (1.28-beta)

If you want to try it install the alpha version of the cli and use the following config:

port: 4466
prototype: true
databases:
  default:
    connector: postgres
    host: 127.0.0.1
    port: 5432
    user: postgres
    password: prisma
    rawAccess: true

If you are too eager just use the current alpha.

I've tried adding prototype to prisma.yml, both with the alpha and since then with the fresh 1.28 beta. But I keep getting the error :

Invalid prisma.yml file
 â–¸    prisma.yml should NOT have additional properties. additionalProperty: prototype

I use demo servers. Something I overlooked ?

@jide

You need to add this to docker-compose file , not to the prisma.yml

Ah ok thanks, so I guess demo servers are not concerned atm ? they have this flag off I guess.

Yes, demo servers has this off as this is even very new for demo servers

So I set up a docker instance with 1.28 beta, and the new directives seem to work: I can deploy the datamodel.

But it does not seem to have any effect on the generated graphql API, there is no id field in the create* mutations, ids are still auto-generated. If I try using Int for ids, The server errors.

Mutation works, but the id is auto-generated :

type Test {
  id: ID! @id(strategy: NONE)
  title: String!
}

mutation {
  createTest(data: {
    title: "Hello"
  }) {
    id
  }
}

Mutation fails ("Whoops. Looks like...etc") :

type Test {
  id: Int! @id(strategy: NONE)
  title: String!
}

mutation {
  createTest(data: {
    title: "Hello"
  }) {
    id
  }
}

I'm super confused, why is there no change to the prisma graphql API with the new datamodel ?

I think for Int you need to define a sequence

type Test {
  id: Int! @id(strategy: SEQUENCE) @sequence(name: "MY_SEQUENCE" initialValue:1 allocationSize:100)
  name: String!
}

cc @mavilein , please clarify this

@id(strategy: NONE) is not implemented yet. Someone will implement it in the next weeks. cc: @do4gr
The example provided by @pantharshit00 should work.

Ahhh okay makes sense ! Thank you for the explanation.

I think we can close this now as this is already available now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

schickling picture schickling  Â·  3Comments

marktani picture marktani  Â·  3Comments

sedubois picture sedubois  Â·  3Comments

sorenbs picture sorenbs  Â·  3Comments

thomaswright picture thomaswright  Â·  3Comments