silverstripe / sspak

Tool for managing bundles of db/assets from Silverstripe environments
http://silverstripe.github.io/sspak/
BSD 3-Clause "New" or "Revised" License
47 stars 34 forks source link

FIX Always import to the correct DB #32

Closed dhensby closed 8 years ago

dhensby commented 8 years ago

This fixes an issue where a sql dump has a USE or CREATE statement.

sspak won't handle that well and will end up creating a new DB instead of importing into the target DB.

This change strips out lines starting with USE or CREATE to ensure that the intended DB is used.

tractorcow commented 8 years ago

Someone triple check the sed usage here is correct and we can merge it.

stojg commented 8 years ago

quick question, shouldn't the sspak decide which db to use, ie remove any create db or use db statement? I'm a bit uncertain what is expected here.

halkyon commented 8 years ago

I think any CREATE DATABASE or USE statements aren't needed as all, @stojg. The snapshot restore scripts will choose the database that will be restored, not the SQL itself.

halkyon commented 8 years ago

is there any case where one of those statements would be on a line with other statements, and sed might mangle the SQL?

stojg commented 8 years ago

@halkyon But if the SQL contains a USE mydatabase that will override the the SSPAK derived db?

stojg commented 8 years ago

Sorry, @halkyon just notified me about that it's not a replace Create with Update.. i need to learn how to read properly.

stojg commented 8 years ago

Looks good to me

dhensby commented 8 years ago

well thank you for that :)

dhensby commented 8 years ago

for clarity, what tends to happen is:

  1. Dev takes dump from mysql
  2. dump contains CREATE IF NOT EXISTS for the existing DB name and then a USE to select it
  3. on import sspak picks the right DB, user, etc BUT the dump then says "just kidding, create this DB and use it (as in point 2 above).

this fix removes those create and use statements so it's always imported into the DB defined for the SS site