db-migration icon indicating copy to clipboard operation
db-migration copied to clipboard

Add method for execute SQL from file

Open vjik opened this issue 4 years ago • 4 comments

For example, $b->executeSqlFromFile().

Need to come up with a good name. Variants:

  • loadDump()
  • loadSql()
  • executeSqlFromFile()
  • executeSql()

vjik avatar Oct 16 '21 06:10 vjik

That could be a bit tricky: https://stackoverflow.com/questions/6346674/pdo-support-for-multiple-queries-pdo-mysql-pdo-mysqlnd/6461110#6461110

samdark avatar Oct 18 '21 10:10 samdark

It could be implemented in two ways:

  1. A method accepting a string with many SQL statements. File reading isn't involved and is done with file_get_contents. Not good for huge dumps.
  2. A method accepting a file path. There we can open a file and seek it till next SQL statement executing previous one. Would be memory efficient but could be a bit slow.

samdark avatar Oct 18 '21 10:10 samdark

There is execute() method which executes SQL strings.

Name executeFile() looks good for executing SQL files.

The method should be added to CommandInterface and realized in AbstractCommand as execute() method. After we can add a wrapper to MigrationBuilder

Tigrov avatar Nov 04 '23 03:11 Tigrov

If this functionality is needed, then need to create issue in Yii DB.

vjik avatar Nov 07 '23 15:11 vjik