New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typeorm Migrations ignore existing default value on column #7110
Comments
This is likely to be a posgtgres-specific issue. Explicit type conversions are stripped when loading schema from database, but in some cases this is done inaccurately, which causes this schema change to appear in all further generated migrations. In my case value With the next schema it causes this change to appear again and again in every migration, that I generate:
|
I've submitted a PR to improve parsing default values of columns with Postgres driver: #7681 |
* fix: defaults type cast filtering This fixes column default value in cockroachdb continuously producing schema changes when there should be none Refs: typeorm#7110 * fix: defaults type cast filtering Remove debugging code Refs: typeorm#7110
Issue Description
In Postgres, it's possible to apply current_setting values as a column default value.
Thus, when executing 'SET valuename=value', this value is applied as a default for that column.
What happens actually?
Typeorm ignores such a present default value. From my investigation so far, I suspect that it is related to the function parameter and the quotes ('coffee.current_tenant'). Using a function without parameters (e.g hotfix()) works perfectly.
Here's an example entity:
When executing
$ npm run start:dev
the database is generated (synchronize: true) and contains the default setting as expected.However, it seems that Typeorm Migrations does not recognize this type of default value when generating or checking for migrations using either
typeorm schema:log
ortypeorm migrations:generate -n row-level
.After generating an additional migration, that migration contains the suggested changes. After applying that new migration, Typeorm still adds the same line for further migrations.
Expected Behavior
Actual Behavior
Steps to Reproduce
I created a minimal example that shows the behaviour and a workaround. It's available here: https://github.com/fabianskii/typeorm-migration-ignores-default-bug
$ git clone https://github.com/fabianskii/typeorm-migration-ignores-default-bug
$ cd typeorm-migration-ignores-default-bug/ && npm install
$ docker-compose up -d
$ npm run build
(after each migration change)$ typeorm schema:log
$ npm run build
$ typeorm schema:log
My Environment
Relevant Database Driver(s)
aurora-data-api
aurora-data-api-pg
better-sqlite3
cockroachdb
cordova
expo
mongodb
mysql
nativescript
oracle
postgres
react-native
sap
sqlite
sqlite-abstract
sqljs
sqlserver
Are you willing to resolve this issue by submitting a Pull Request?
The text was updated successfully, but these errors were encountered: