Skip to content
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

Fix Bulk Imports #199

Merged
merged 7 commits into from
May 12, 2018
Merged

Conversation

Blacksmoke16
Copy link
Contributor

This PR addresses some issues i uncovered recently, removing too much when implementing the batch size, while the tests passed.

  1. Re add the extra params for ignore_on_duplicate and update_on_duplicate
  2. Add Granite::ORM::Collection(self) typing to model_array param so that records can be fetched from DB, iterated upon, and reimported easily. See This Spec
  3. Greatly expands the test suite of bulk imports to cover standard usages, batch_size, ignore_on_duplicate and update_on_duplicate for each of the following:
    • Non AUTO INCREMENT default name PK
    • AUTO INCREMENT default name PK
    • Non AUTO INCREMENT custom name PK
    • AUTO INCREMENT custom name PK

Copy link
Member

@drujensen drujensen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Blacksmoke16 can you add tests that verify the timestamps are set? We should verify that created_at and updated_at are properly set when imported.

@Blacksmoke16
Copy link
Contributor Author

Oo good call, yea can do.

@faustinoaq faustinoaq requested review from drujensen, robacarp and eliasjpr and removed request for drujensen, robacarp and eliasjpr May 11, 2018 02:55
@Blacksmoke16
Copy link
Contributor Author

@drujensen That ought to be good.

Copy link
Member

@drujensen drujensen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you confirm that on_duplicate_key_update does not change the created_at? If so, this is approved.

@Blacksmoke16
Copy link
Contributor Author

I'll look into it. Will add a spec for this as well.

@Blacksmoke16
Copy link
Contributor Author

@drujensen How would i see what sqlite version the tests use?

@drujensen
Copy link
Member

good question. In the Docker file, we include the library here:

https://github.com/amberframework/granite/blob/master/Dockerfile#L3

You can run docker-compose run spec bash to get a bash shell inside the docker image. Not sure what command to use to get the sqlite version from there though. Maybe write a small crystal test to run select sqlite_version();?

@Blacksmoke16
Copy link
Contributor Author

Am a total noob when it comes to sqlite, best i could do was add sqlite3 package to Dockerfile then run sqlite3 --version and seems it installs 3.11.0.

Anyway, reason i ask is https://www.sqlite.org/draft/releaselog/3_24_0.html. Once that gets released, if we use it, will allow sqlite to support updates like PG does. This'll prob allow the timestamps to get updated in sqlite, so could add sqlite to timestamps spec.

Regardless, we can worry about that later when it actually is released. This PR should be good to go. Got a spec added that checks created_at and updated_at when using bulk imports.

@drujensen drujensen requested a review from robacarp May 12, 2018 13:26
@drujensen
Copy link
Member

ok, this needs a second reviewer and then we can merge.

@drujensen drujensen requested a review from a team May 12, 2018 13:29
@Blacksmoke16
Copy link
Contributor Author

Blacksmoke16 commented May 12, 2018

I'll update this with new spec stuff, sec.

EDIT: Some things broke, i'll look into it.

@drujensen
Copy link
Member

@Blacksmoke16 I resolved some of the conflicts in the spec_models.cr. @maiha added a migrator module that allows you to drop and create databases without specifying the schema.

@Blacksmoke16
Copy link
Contributor Author

Rgr, seems some of the specs fail now, ill see what's wrong.

@Blacksmoke16
Copy link
Contributor Author

There is a bug with the migrator that doesn't apply PRIMARY KEY to column that is not AUTO INCREMENT.

I logged out the table_name k/value of the PK by doing
puts "#{@quoted_table_name} - #{k} #{v}"

"kvss" - "k" VARCHAR(255)
"people" - "id" INTEGER NOT NULL PRIMARY KEY
"companies" - "id" INTEGER NOT NULL PRIMARY KEY
"books" - "id" INTEGER NOT NULL PRIMARY KEY
"book_reviews" - "id" INTEGER NOT NULL PRIMARY KEY
"items" - "item_id" VARCHAR(255)
"non_auto_default_pk" - "id" INTEGER
"non_auto_custom_pk" - "custom_id" INTEGER

Notice how all the models with auto: false do not have PRIMARY KEY

@drujensen
Copy link
Member

@Blacksmoke16 ahhh, yup. Let me push a fix for that. thanks!

@drujensen
Copy link
Member

Here #203 is a fix for the PRIMARY KEY auto:false

@drujensen
Copy link
Member

@Blacksmoke16 go ahead and rebase. Let's get this merged.

@drujensen drujensen merged commit 2b85634 into amberframework:master May 12, 2018
@Blacksmoke16 Blacksmoke16 deleted the fix-bulk-import branch May 12, 2018 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants