I want to make all provided migration scripts more readable. They now have some RAW SQL queries and I want you to replace them with migration framework calls.
Rewrite each INSERT and UPDATE query based on these rules:
- instead of
$this->addSqlcall$this->addInsertSqlor$this->addUpdateSql(they are already provided by used migration framework); - first argument in both cases should be table name from the rewritten query;
- second argument in both cases should be associative array, where key is a column name and value is column value from the rewritten query;
- third argument used only on UPDATE queries and should contain WHERE clause wrapped in callback like this:
static fn (Parameters $_) => "{HERE THE ORIGINAL WHERE CLAUSE WITHOUT WHERE}"- if value from the query is not static rather dynamic expression (like
NOW()) then pass value wrapped in callback like this (for example):
static fn (Parameters $_) => "NOW()"- use the same version which is used by the file. If you don't know the version, use the latest PHP version you know;
- use original names of tables and columns;
- do not try import Parameters class from provided callback, I'll do it manually after your fixes;
- if you don't know how to rewrite the query, then keep it as it is;
Given task to write down method, write it so that it would contain method calls which revert database changes in reverse order.
- use
$this->addDeleteWhereSqlmethod to delete INSERTED rows like this:
$this->addDeleteWhereSql('some_table', 'FIELD_1 = ? AND FIELD_2 = ?', ['VALUE_1', 'VALUE_2']);-
use
$this->addDropTableSql('some_table')to drop previously created tables; -
use
$this->addUpdateSqllike were described before. If you don't know previous data, then do not useaddUpdateSql, but leave comment like this:// Невозможно отменить изменения в записи.; -
I want impementation both for
upanddownif you can handle it. If now then write// TODO; -
when you see a hardcoded value in query, then try to write dynamic query for it, for example:
$this->addInsertSql('any_table', [
'DYNAMIC_ID' => static fn (Parameters $_) => "(
SELECT ID FROM some_table WHERE XML_ID = {$_(self::SOME_KNOWN_ID_REFERENCE)}
)",
]);- when you see serialized value in query, try to deserialize it and put deserialized value into code, then serialize it value:
$this->addInsertSql('any_table', [
'SETTINGS' => serialize('a:6:{s:4:..'),
]);