I’m trying to create a View table for the Users table and the Admin Users table.
I want to create the tables in a migration file.
The SQL for the View I want to create is as follows
CREATE VIEW v_all_users AS
(
SELECT
id,
name,
mail
"Users" AS type
FROM users
)
UNION ALL
(
id,
name,
mail
"AdminUsers" AS type
FROM admin_users
)
The migration file I created is as follows
class CreateVAllUsers extends AbstractMigration
{
/**
* Change Method.
*
* More information on this method is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-change-method
* @return void
*/
public function change()
{
$table = $this->table('v_all_users');
$this->table('v_all_users', ['id' => false])
->addColumn('id', 'integer', [
'default' => '0',
'limit' => null,
'null' => false,
])
->addColumn('name', 'string', [
'default' => '',
'limit' => 255,
'null' => false,
])
->addColumn('mail', 'string', [
'default' => '',
'limit' => 255,
'null' => false,
])
->addColumn('created', 'datetime', [
'default' => '0000-00-00 00:00:00',
'limit' => null,
'null' => false,
])
->addColumn('updated', 'datetime', [
'default' => '0000-00-00 00:00:00',
'limit' => null,
'null' => false,
])
->addColumn('type', 'string', [
'default' => '',
'limit' => 10,
'null' => false,
])
->create();
}
}