loopbackio/loopback-connector-postgresql

autoupdate not working properly with indexes

animesh32 opened this issue · 2 comments

Steps to reproduce

i am using datasource autoupdate
my current model definition is -
{
"id": {
"id": true,
"name": "id",
"type": "number",
"generated": true
},
"age": {
"name": "age",
"type": "number",
"unique": true,
"postgresql": {
"dataType": "numeric",
"columnName": "age"
}
},
"name": {
"name": "name",
"type": "string",
"postgresql": {
"dataType": "varchar",
"columnName": "name"
}
},
"loanId": {
"name": "loanId",
"type": "number",
"postgresql": {
"dataType": "numeric",
"columnName": "loan_id"
}
}
}
i want to autoupdate it to -
{
"modelDefinition": [
{
"name": "name",
"type": "string",
"unique": false,
"required": false,
"id": false,
"default": ""
},
{
"name": "loan_id",
"type": "number",
"unique": false,
"required": false,
"id": false,
"default": ""
}
]
}

Current Behavior

After using DEBUG=loopback:connector* npm start command t
following sql queries were executed

  1. loopback:connector:postgresql SQL: ALTER TABLE "ani"."test" ALTER COLUMN "name" TYPE VARCHAR USING "name"::VARCHAR +11ms
  2. loopback:connector:postgresql SQL: ALTER TABLE "ani"."test" DROP COLUMN "age" +2ms
    (this command drops the column along with the unique index )
    but
  3. loopback:connector:postgresql SQL: DROP INDEX "ani"."test_age_idx" +3ms
    loopback:connector:postgresql error: index "test_age_idx" does not exist
    loopback:connector:postgresql at Connection.parseE (/home/myPath/node_modules/pg/lib/connection.js:614:13)
    loopback:connector:postgresql at Connection.parseMessage (/home/myPath/node_modules/pg/lib/connection.js:413:19)
    loopback:connector:postgresql at Socket. (/home/myPath/node_modules/pg/lib/connection.js:129:22)
    loopback:connector:postgresql at Socket.emit (events.js:310:20)
    loopback:connector:postgresql at Socket.EventEmitter.emit (domain.js:482:12)
    loopback:connector:postgresql at addChunk (_stream_readable.js:286:12)
    loopback:connector:postgresql at readableAddChunk (_stream_readable.js:268:9)
    loopback:connector:postgresql at Socket.Readable.push (_stream_readable.js:209:10)
    loopback:connector:postgresql at TCP.onStreamRead (internal/stream_base_commons.js:186:23) +1ms
    this query tries to drop index which has been dropped already

Expected Behavior

expected drop index query not to execute as drop column already does that

Link to reproduction sandbox

it's based on working of datasource autoupdate or maybe i am making my model definition wrong

Additional information

Related Issues

See Reporting Issues for more tips on writing good issues

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale commented

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.