Skip to content

Command line tool to convert current database to others, except sqlite - #6457

Merged
karlitschek merged 52 commits into
masterfrom
db-convert-tool
May 19, 2014
Merged

karlitschek merged 52 commits into
masterfrom
db-convert-tool

Conversation

@bartv2

@bartv2 bartv2 commented Dec 16, 2013

Copy link
Copy Markdown
Contributor

I think it needs some more help/description what it does, but can't think of what to write.

@karlitschek @butonic @DeepDiver1975 @bantu @ringmaster

@ringmaster

Copy link
Copy Markdown
Contributor

Any chance this could be made generic to move between any database engines?

Comment thread core/command/db/convertfromsqlite.php Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could this use $schemaFrom->getDbStructure($stream); instead to get the actual schema of the source database, and then use the migration methods to create/update the tables in the destination database? Might save those database comparisons later on.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Tried this, the sqlite export misses information. For example converting to postgresql still needs to follow changes:

ALTER TABLE "oc_filecache" ALTER size TYPE BIGINT;
ALTER TABLE "oc_filecache" ALTER unencrypted_size TYPE BIGINT;
ALTER TABLE "oc_locks" ALTER created TYPE BIGINT;
ALTER TABLE "oc_locks" ALTER scope TYPE SMALLINT;
ALTER TABLE "oc_locks" ALTER depth TYPE SMALLINT;
ALTER TABLE "oc_share" ALTER share_type TYPE SMALLINT;
ALTER TABLE "oc_share" ALTER permissions TYPE SMALLINT;
ALTER TABLE "oc_share" ALTER stime TYPE BIGINT;
ALTER TABLE "oc_share" ALTER accepted TYPE SMALLINT;
ALTER TABLE "oc_share" ALTER mail_send TYPE SMALLINT;

And this is only for the core tables, the app tables also have the wrong type in places

@karlitschek

Copy link
Copy Markdown
Contributor

Great. @bartv2 Do you think this could be extended to move between any databases?

Comment thread core/command/db/convertfromsqlite.php Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Inject the config object via the constructor instead

@bantu

bantu commented Dec 18, 2013

Copy link
Copy Markdown

Please make use of dependency injection. The quality of the code in master needs to improve.

@kprovost

kprovost commented Jan 4, 2014

Copy link
Copy Markdown
Contributor

I've been trying to use this code to convert from SQLite to postgreSQL and I've run into a couple of issues.

The biggest one is that the owncloud db uses the 'user' field all over the place and that's a reserved keyword. As a result it needs to be escaped during insert calls, which this code doesn't do. I've hacked around it by adding the escapes in the DBAL layer, but that's probably not the cleanest solution.

I've also had trouble with the size of the mime field in oc_files_trash and the value field in oc_contacts_cards_properties.

I added the following hacks just before the copyTable() foreach:

$toDB->exec("SET CONSTRAINTS ALL DEFERRED;");
$toDB->exec("ALTER TABLE oc_files_trash ALTER mime TYPE character varying(128);");
$toDB->exec("ALTER TABLE oc_contacts_cards_properties ALTER value TYPE text;");
$toDB->exec("DROP INDEX cp_value_index");

Again, these are hacks, but at least they show where the problems lie.

@karlitschek

Copy link
Copy Markdown
Contributor

@bartv2 So what is the status here?

@bartv2

bartv2 commented Jan 5, 2014

Copy link
Copy Markdown
Contributor Author

@kprovost thanks for testing this, i only checked sqlite->mysql, where this apparently wasn't a problem.
@karlitschek still working on this, just been distracted the last couple of weeks

@karlitschek

Copy link
Copy Markdown
Contributor

Cool. Thanks.

@kprovost

kprovost commented Jan 7, 2014

Copy link
Copy Markdown
Contributor

Just ran into another problem: the sequences need to be altered to start from max(id) + 1.

For those unfamiliar with postgres, sequences generate the next ID for index (or any other column you like) columns, much like the MySQL auto_increment. Apparently the conversion left me in a situation where the sequence generated IDs which already existed.

I (manually) fixed it by just doing select max(id) from ...; and then alter sequence ... restart with [max(id) + 1];

@bartv2

bartv2 commented Jan 17, 2014

Copy link
Copy Markdown
Contributor Author

It still only converts from sqlite, next is making it work to also convert from other database types

@bantu

bantu commented Jan 17, 2014

Copy link
Copy Markdown

Is this something you want to try in this PR?

@bartv2

bartv2 commented Jan 17, 2014

Copy link
Copy Markdown
Contributor Author

Is this something you want to try in this PR?

No lets do that in another PR. That should also make this easier to test.

@bartv2

bartv2 commented Jan 31, 2014

Copy link
Copy Markdown
Contributor Author

Any more comments on this? Or can we merge this?

@DeepDiver1975

Copy link
Copy Markdown
Contributor

No lets do that in another PR. That should also make this easier to test.

I'd prefer to do it all at once and right - partial solution would help that much from my point of view.
In addition there is no rush in get this merged now (besides the fact that the branch was kind of rotting the past weeks 😉 )

@scrutinizer-notifier

Copy link
Copy Markdown

The inspection completed: 8 new issues, 22 updated code elements

@ghost

ghost commented May 12, 2014

Copy link
Copy Markdown

@karlitschek

Copy link
Copy Markdown
Contributor

@Nowaker Can you help to review that?

@Nowaker

Nowaker commented May 14, 2014

Copy link
Copy Markdown

@karlitschek I don't think so. I use version 6.

@bantu

bantu commented May 19, 2014

Copy link
Copy Markdown

@karlitschek Consider merging without additional review.

@karlitschek

Copy link
Copy Markdown
Contributor

@schiesbn @PVince81 @DeepDiver1975 Can anyone have a quick look?

@PVince81

Copy link
Copy Markdown
Contributor

The code looks good, didn't test.

Would it make sense to automatically enable maintenance mode before the conversion starts and disable it afterwards ?

@DeepDiver1975

Copy link
Copy Markdown
Contributor

I did review this PR last week already - without testing.

I'm fine with the code as well

@bantu

bantu commented May 19, 2014

Copy link
Copy Markdown

Would it make sense to automatically enable maintenance mode before the conversion starts and disable it afterwards ?

This is being done here. https://github.com/owncloud/core/pull/6457/files#diff-edd78618a1329a6cad8cfffd51901e60R259

@PVince81

Copy link
Copy Markdown
Contributor

@bantu ok got it. Seems I used the search on the wrong page.
👍

@bantu

bantu commented May 19, 2014

Copy link
Copy Markdown

@karlitschek Let's have this then?

@karlitschek

Copy link
Copy Markdown
Contributor

👍

karlitschek pushed a commit that referenced this pull request May 19, 2014
Command line tool to convert current database to others, except sqlite
@karlitschek
karlitschek merged commit 090d127 into master May 19, 2014
@karlitschek
karlitschek deleted the db-convert-tool branch May 19, 2014 15:41
@karlitschek

Copy link
Copy Markdown
Contributor

done :-)

@bantu

bantu commented May 19, 2014

Copy link
Copy Markdown

@karlitschek Merci

@cdamken

cdamken commented May 21, 2014

Copy link
Copy Markdown
Contributor

@karlitschek

It seems this is completed? Has it been tested? I have a need for this script at the moment. If it is ready for release, are there instructions on how to use?

@karlitschek

Copy link
Copy Markdown
Contributor

@cdamken It is now merged and should work. Please not that this is not a simple conversion script but requires complex changes in core. So this works only in ownCloud 7 and is not available in older versions.

@Nowaker

Nowaker commented May 22, 2014

Copy link
Copy Markdown

Will there be owncloud 6 to 7 migration script, so I could then convert my SQLite db to PostgreSQL with your converter?

@holmboe

holmboe commented May 28, 2014

Copy link
Copy Markdown

I am also in need of this. I have a server on it's knees. :)

My current setup is an OC v6 with sqlite3 so an update to OC v7, when it is released, before migrating mysql is totally fine.

@Bugsbane

Copy link
Copy Markdown

"It is now merged and should work. Please not that this is not a simple conversion script but requires complex changes in core. So this works only in ownCloud 7 and is not available in older versions."

@karlitschek - So for someone trying to migrate a v7.0.1 database, how do we go about it? I'm moving my sqlite3 / v7.0.1 instance to a server that only supports Mysql currently, and am keen to not accidentally use one of those DB breaking proceedures that seemed popular previously.

@HeisSpiter

Copy link
Copy Markdown

@Bugsbane Basically, you've to use OwnCloud Console (occ). It's in root directory for your owncloud installation. If you installed it in /var/ww/owncloud, it's /var/www/owncloud/occ. So, basically, you need to:

/var/www/owncloud/occ db:convert-type

For usage, see:

/var/www/owncloud/occ help db:convert-type

@Bugsbane

Copy link
Copy Markdown

Great. Thanks HeisSpiter. That's exactly what I needed!

@ghost ghost mentioned this pull request Apr 18, 2016
@lock lock Bot locked as resolved and limited conversation to collaborators Aug 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.