loopbackio / loopbackio/loopback-connector-postgresql

Incremental migration does not configure existing PK column to enable auto-generated values

Aperta
#381 11 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

feature help wanted major
Lingua principale
JavaScript
Stelle
118
Fork
184
Merge medio
1g 22h
PR unite (30g)
5

Descrizione

Description/Steps to reproduce

From my testing using LoopBack 4 and this connector, the migration performed by npm run migrate does not configure the id (primary key) column to be auto-generated when generated: true is enabled on the property.

Link to reproduction sandbox

I've set up a branch on my loopback-next fork with a recreate. The branch is here:

https://github.com/aharbis/loopback-next/tree/postgres-pk-auto-gen

The recreate uses the todo application. There are two commits on the branch:

https://github.com/aharbis/loopback-next/commit/cdee3cb60305a02e5e1e5a49069e043079615289 - Adds the Postgres data source
https://github.com/aharbis/loopback-next/commit/43368cc4687521f06a79102b6484494cda6e27be - Sets generated: true on todo model

Steps to recreate

  1. Checkout first commit (that adds the datasource)
  2. Install dependencies (npm i)
  3. Run migration (npm run migrate)
  4. Start app (npm start)
  5. Try to create todo with ID, to confirm this works
  6. Stop app
  7. Checkout second commit (that sets generated: true)
  8. Run migration (npm run migrate)
  9. Start app (npm start)
  10. Try to create todo without ID

Expected result

In step 10, this create should succeed and the ID should be auto-generated.

Actual result

In step 10, this create yields a 500 error:

Unhandled error in POST /todos: 500 error: null value in column "id" violates not-null constraint
    at Connection.parseE (/Users/aharbis/git/loopback-next/examples/todo/node_modules/pg/lib/connection.js:602:11)
    at Connection.parseMessage (/Users/aharbis/git/loopback-next/examples/todo/node_modules/pg/lib/connection.js:399:19)
    at Socket.<anonymous> (/Users/aharbis/git/loopback-next/examples/todo/node_modules/pg/lib/connection.js:121:22)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)
    at TCP.onread (net.js:601:20)

Additional information

$ node -e 'console.log(process.platform, process.arch, process.versions.node)'
darwin x64 8.12.0

$ npm ls --prod --depth 0 | grep loopback
@loopback/example-todo@1.6.2 /Users/aharbis/git/loopback-next/examples/todo
├── @loopback/boot@1.4.1
├── @loopback/context@1.19.1
├── @loopback/core@1.8.2
├── @loopback/openapi-v3@1.6.2
├── @loopback/openapi-v3-types@1.1.2
├── @loopback/repository@1.7.0
├── @loopback/rest@1.16.0
├── @loopback/rest-explorer@1.2.2
├── @loopback/service-proxy@1.2.2
├── loopback-connector-postgresql@3.6.1
└── loopback-connector-rest@3.4.1

$ psql --version
psql (PostgreSQL) 10.5

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Riproduci il problema nell’applicazione todo di loopback-next usando il branch collegato postgres-pk-auto-gen e i suoi due commit. Esegui npm migrate prima e dopo aver abilitato generated: true, quindi conferma se la creazione di un todo senza ID riesce e se l’ID viene generato automaticamente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, node.js, postgresql
Ambito
backend, database
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.