-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Prevent errors when synchronizing Sqlite or MSSql DBs with simple-enum
types
#4005
Prevent errors when synchronizing Sqlite or MSSql DBs with simple-enum
types
#4005
Conversation
simple-enum
types
We can't simply remove exist line of code.. I appreciate research you did and possible bugs you found, but please ping author of those changes and ask him why he added them here. |
Hello @borremosch, you are the author of #3700 and your input here would be very much appreciated :-) Do you remember the rationale for adding the "inverse transformation" of "varchar + CHECK()" back to |
Hello again @borremosch, your input on this issue ↑ is more than welcome :-) |
Hey @louisremi, apologies for the delay, I have been quite busy lately. I have taken a quick look and it looks like you might be right. I thought it would be nice if Typeorm would infer certain check statements back to a simple enum so that's probably why I added the code for the inverse transformation, but if this is causing issues then it is probably a good idea to remove that part of the code. |
@@ -128,14 +128,8 @@ describe("database schema > column types > sqlite", () => { | |||
table!.findColumnByName("datetime")!.type.should.be.equal("datetime"); | |||
table!.findColumnByName("simpleArray")!.type.should.be.equal("text"); | |||
table!.findColumnByName("simpleJson")!.type.should.be.equal("text"); | |||
table!.findColumnByName("simpleEnum")!.type.should.be.equal("simple-enum"); | |||
table!.findColumnByName("simpleEnum")!.enum![0].should.be.equal("A"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you tell why did you remove those checks for data equality?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It isn't data equality that is checked here. Data equality is still tested on line 118. These tests were written to ensure that findByColumnName("simpleEnum")
returned the original definition of the simple-enum
, (instead of the actual nvarchar
used by Sqlite). This is the behavior I am proposing to fix. So these tests are no longer relevant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test that confirms that this change allows the intended behavior to work as expected. I think it's that when you do a second sync it will work correctly?
And that changes to the enum are still reflected - unless there's already a test for that.
Issue type:
[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ]
cordova
[ ]
mongodb
[ ]
mssql
[ ]
mysql
/mariadb
[ ]
oracle
[ ]
postgres
[ ]
cockroachdb
[x]
sqlite
[ ]
sqljs
[ ]
react-native
[ ]
expo
TypeORM version:
[x]
latest
[ ]
@next
[ ]
0.x.x
(or put your version here)Steps to reproduce:
I tried to use the new (and undocumented)
simple-enum
type with sqlite. I'm surprised to see that Typeorm is able to synchronize only once when the table hasn't been created yet. Once the table has been created, synchronizing throws with the following error message:I am a complete noob with Typeorm, but from poking around the source code, here's what I'm guessing is going wrong:
loadTables
is executed to detect a difference between the entity and the actual Table layout.loadTables()
to returnsimple-enum
instead of the actualvarchar
type that was used when creating the table in sqlite, seetypeorm/src/driver/sqlite-abstract/AbstractSqliteQueryRunner.ts
Line 818 in 63d993b
simple-*
types such assimple-json
andsimple-array
simple-enum
as the column type in the query, which causes the above error.I removed the "inverse conversion" code blocks in both Sqlite and MSSql query runners, and I removed the tests that were expecting
findColumnByName
to return the entity definition instead of the actual table layout. Again, the reason I did this is because the implementation and tests ofsimple-array
andsimple-json
don't have this behavior and assertions… and also because usingsimple-enum
only appears to work in sqlite when I remove this code.I'm willing to add documentation for simple-enum to this PR if you are OK with the proposed changes.