My Yii2 application should allow customers to use MySQL or PostgreSQL as database backends. So I need to write code which runs for both databases.
I started supporting MySQL and need to eleminate MySQL specific code, e.g. in migrations:
public function up() {
$this->execute('ALTER SCHEMA DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci');
$this->execute('ALTER SCHEMA CHARACTER SET utf8 COLLATE utf8_general_ci');
$this->createTable('user', [
'id' => $this->primaryKey(),
...
],
'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB'
);
}
How to rewrite this piece of code?
Are there repos which have tackled this? What are best practices for MySQL and PostgreSQL compatibility?