KorzhCom / Korzh.DbUtils

Helps to initialize your database and seed it with some data in a most simple and convenient way.
MIT License
76 stars 11 forks source link

Import not possible when there's a Timestamp|RowVersion field #7

Closed nstohler closed 5 years ago

nstohler commented 5 years ago

One of my EF Core was set up to have a concurrency token as described in https://docs.microsoft.com/en-us/ef/core/modeling/concurrency#timestamprow-version

With the following field present, dbtool export ... was able to export the table contents into a JSON file.

[Timestamp]
public byte[] RowVersion { get; set; }

But dbtool import ... was then unable to create the records in the same DB (which I've previously deleted). It does not output any error message either, which made it quite hard to track down what exactly prevented the import.

When I manually remove the RowVersion entry in the "data" section of every record in the JSON, the import succeeds.

korzh commented 5 years ago

Thanks for the report. We will find out the reason of this error and fix it in the next update.

antifree commented 5 years ago

Done here #8

korzh commented 5 years ago

Version 1.1.5 is published.

nstohler commented 5 years ago

Thanks

I've just tried it, but it did't work.

Result: Normal tables work as expected, but those with a RowVersion did not.

When I manually removed all the "RowVersion" lines of the data records, the import works.

korzh commented 5 years ago

Version 1.1.6 is published.

nstohler commented 5 years ago

I've updated to 1.1.6, but now I'm getting the following when trying to import:

$ dbtool import -i:./demo/ blazor-boilerplate
Openning blazor-boilerplate connection...
Importing data to [blazor-boilerplate]...

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at Korzh.DbUtils.BaseDbBridge.GetTableFullName(DatasetInfo table) in d:\a\1\s\src\Korzh.DbUtils\DbBridge\BaseDbBridge.cs:line 358
   at Korzh.DbUtils.SqlServer.SqlServerBridge.TurnOnConstraints() in d:\a\1\s\src\Korzh.DbUtils.SqlServer\SqlServerBridge.cs:line 165
   at Korzh.DbUtils.BaseDbBridge.FinishSeeding() in d:\a\1\s\src\Korzh.DbUtils\DbBridge\BaseDbBridge.cs:line 343
   at Korzh.DbUtils.Import.DbImporter.Import() in d:\a\1\s\src\Korzh.DbUtils.Import\DbImporter.cs:line 57
   at Korzh.DbTool.ImportCommand.Run() in d:\a\1\s\src\Korzh.DbTool\Commands\ImportCommand.cs:line 201
   at Korzh.DbTool.Program.Main(String[] args) in d:\a\1\s\src\Korzh.DbTool\Program.cs:line 27
Segmentation fault
korzh commented 5 years ago

That's really strange because that line contains only var result = "" assignment.

nstohler commented 5 years ago

That's really strange because that line contains only var result = "" assignment.

I agree.

I might have time later today or tomorrow to compile dbtool on my machine and run it through the debugger.

korzh commented 5 years ago

I guess I know a possible reason of the problem. Will publish an update in a few minutes.

nstohler commented 5 years ago

Debugging it too, found some other problem

nstohler commented 5 years ago

https://github.com/nstohler/Korzh.DbUtils/commit/a78fbdae9b867b705b41386c84092de7903c8964

I had to patch in the Database schema name to make it work on my database. Otherwise there was an error about not finding/accessing the table.

korzh commented 5 years ago

There was some inconsistency in Import method - it called FinishSeeding without StartSeeding if the imported file is empty. I have fixed this and will publish an update in 5 minutes.

nstohler commented 5 years ago

Please include the schema fix as well!

https://github.com/kedonec/Korzh.DbUtils/blob/873110a9b560af9b4a359a5040b23cb20a818b76/src/Korzh.DbUtils/DbBridge/BaseDbBridge.cs#L356 GetTableFullName will return the wrong database tablename in case there's a db schema name!

My quick fix above works, but I guess it can be done cleaner.

korzh commented 5 years ago

OK. I've stopped the release and included your fix for Schema. The update is building now and will be published soon.

korzh commented 5 years ago

Done. Version 1.1.7 has been published and is validated on NuGet now. Will be listed in a few minutes.