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

Migration system for sqlite #83

Merged
merged 6 commits into from
Feb 18, 2014
Merged

Conversation

fudanchii
Copy link

Hey @bradrydzewski
I tried to integrate your migrate package and write some sqlite specific helper, it turns out quite nice in my opinion. ;)

It has nice wrapper for the migration step, so for most of the time we don't have to write raw sql on our own, for example

some minor caveats:
It still lacks index operation support but it's rather easy to add, I believe.
Also it doesn't have any parameter sanitization, but I'm sure we're not going to write our migration script from the web, so I'll leave it at that for now.

The migration driver implements Operation interface, which is accessible from within migration script. And it's possible to create more drivers for another database just by implementing Operation interface and tell the main program to use that driver.

Anyway, I'm not sure if this is already being worked on, or if it's not being planned to be something like this. So it's okay if you reject this PR just in case. :)

Thanks!

Also change the way we handle columns rename migration.
SQLite restrict column addition not to have PRIMARY KEY and/or
UNIQUE attribute, so we have to change from:

add new column -> migrate data from old column to new column ->
rename old table -> create new table with old columns removed ->
migrate data from old table to the new table -> drop old table

to directly:
rename old table -> create new table with renamed columns ->
migrate data from old table to the new table -> drop old table
Also add migration to tests.
@bradrydzewski
Copy link

thanks! this is really good work 👍 i'll get this merged shortly

@vito
Copy link

vito commented Feb 16, 2014

nice!

bradrydzewski added a commit that referenced this pull request Feb 18, 2014
Migration system for sqlite
@bradrydzewski bradrydzewski merged commit 7ce1e55 into harness:master Feb 18, 2014
@bradrydzewski
Copy link

@fudanchii this is working really well, great job!

One last request. When a column is renamed (table is renamed, new table created, data copied, old table removed) we lose the indexes.

We might be able to retrieve the indexes prior to renaming the column, and then re-execute:

select * from sqlite_master where type = 'index' and tbl_name = 'repos'

thoughts?

@fudanchii
Copy link
Author

Sure, I think I need a couple of steps to fetch all indices info before recreate it,
should check existing index by PRAGMA index_list(repos), filtering the autoindex for unique columns since it will automatically recreated. Then fetching indexed columns e.g. PRAGMA index_info(repo_user_ix). And finally recreate the index after matching it with the renamed/dropped columns just in case.

I'll shoot another PR later tonight (GMT+7 here) :D

Thanks!

notandy pushed a commit to notandy/drone that referenced this pull request Feb 18, 2014
I choosed Rev3, because Rev2 will be about "open invitations" feature.
Tathanen pushed a commit to Tathanen/drone that referenced this pull request Feb 24, 2014
I choosed Rev3, because Rev2 will be about "open invitations" feature.
@rgarcia
Copy link

rgarcia commented Mar 4, 2014

Are there any docs for how to use this?

@fudanchii
Copy link
Author

Not yet as of currently, it's a bit involved to document the components since we haven't document the overall architecture yet. But yes, I plan to setup some wiki article on this.
Thanks for the heads up. 👍

@floatdrop
Copy link

@fudanchii maybe pull migration out of the drone to separate package with docs?

@fudanchii
Copy link
Author

@bradrydzewski what do you think?
I'm not planning to extract migration package out, since the core concept and some of the code is not my own.

I will fork drone/docs repo and put some documentation over there.

Thanks.

@bradrydzewski
Copy link

I actually think your migration package might make a great project that others would find useful :) It is up to you though

johannesHarness pushed a commit that referenced this pull request Sep 26, 2023
* Fix message encoding

* Add prototype for BranchTagSelect component

* Finish BranchAndTag component
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants