multischool migration
This commit is contained in:
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Phinx\Migration\AbstractMigration;
|
||||||
|
|
||||||
|
final class CreateSchoolsTable extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
$this->table('schools', [
|
||||||
|
'id' => false,
|
||||||
|
'primary_key' => ['idschool'],
|
||||||
|
'engine' => 'InnoDB',
|
||||||
|
'collation' => 'utf8mb4_unicode_ci',
|
||||||
|
])
|
||||||
|
->addColumn('idschool', 'integer', ['signed' => false, 'identity' => true])
|
||||||
|
->addColumn('name', 'string', ['limit' => 191])
|
||||||
|
->addColumn('slug', 'string', ['limit' => 100, 'comment' => 'usato per URL/sottodominio/widget'])
|
||||||
|
->addColumn('email', 'string', ['limit' => 191, 'null' => true])
|
||||||
|
->addColumn('phone', 'string', ['limit' => 40, 'null' => true])
|
||||||
|
->addColumn('address', 'string', ['limit' => 255, 'null' => true])
|
||||||
|
->addColumn('city', 'string', ['limit' => 100, 'null' => true])
|
||||||
|
->addColumn('postcode', 'string', ['limit' => 20, 'null' => true])
|
||||||
|
->addColumn('country', 'string', ['limit' => 2, 'default' => 'IT'])
|
||||||
|
->addColumn('vat_number', 'string', ['limit' => 30, 'null' => true])
|
||||||
|
->addColumn('logo', 'string', ['limit' => 191, 'null' => true])
|
||||||
|
->addColumn('timezone', 'string', ['limit' => 50, 'default' => 'Europe/Rome'])
|
||||||
|
->addColumn('locale', 'string', ['limit' => 5, 'default' => 'it'])
|
||||||
|
->addColumn('currency', 'string', ['limit' => 3, 'default' => 'EUR'])
|
||||||
|
->addColumn('status', 'string', ['limit' => 20, 'default' => 'active', 'comment' => 'active|suspended|trial'])
|
||||||
|
->addColumn('created_at', 'timestamp', ['null' => true, 'default' => 'CURRENT_TIMESTAMP'])
|
||||||
|
->addColumn('updated_at', 'timestamp', ['null' => true, 'default' => null, 'update' => 'CURRENT_TIMESTAMP'])
|
||||||
|
->addIndex(['slug'], ['unique' => true, 'name' => 'schools_slug_unique'])
|
||||||
|
->addIndex(['status'], ['name' => 'schools_status_index'])
|
||||||
|
->create();
|
||||||
|
|
||||||
|
// Seregno = scuola 1 (dati da completare poi dal pannello)
|
||||||
|
$this->table('schools')->insert([
|
||||||
|
'idschool' => 1,
|
||||||
|
'name' => 'Scuola Yoga Seregno',
|
||||||
|
'slug' => 'seregno',
|
||||||
|
'city' => 'Seregno',
|
||||||
|
'country' => 'IT',
|
||||||
|
])->saveData();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
$this->table('schools')->drop()->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Phinx\Migration\AbstractMigration;
|
||||||
|
|
||||||
|
final class CreateSchoolUserTable extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
$this->table('school_user', [
|
||||||
|
'id' => false,
|
||||||
|
'primary_key' => ['idschooluser'],
|
||||||
|
'engine' => 'InnoDB',
|
||||||
|
'collation' => 'utf8mb4_unicode_ci',
|
||||||
|
])
|
||||||
|
->addColumn('idschooluser', 'integer', ['signed' => false, 'identity' => true])
|
||||||
|
->addColumn('user_id', 'integer', ['signed' => false, 'comment' => 'auth_users.id'])
|
||||||
|
->addColumn('idschool', 'integer', ['signed' => false])
|
||||||
|
->addColumn('school_role', 'string', ['limit' => 20, 'default' => 'student', 'comment' => 'student|teacher|admin|owner'])
|
||||||
|
->addColumn('active', 'char', ['limit' => 1, 'default' => 'Y'])
|
||||||
|
->addColumn('joined_at', 'timestamp', ['null' => true, 'default' => 'CURRENT_TIMESTAMP'])
|
||||||
|
->addIndex(['user_id', 'idschool'], ['unique' => true, 'name' => 'school_user_unique'])
|
||||||
|
->addIndex(['idschool'], ['name' => 'school_user_idschool_index'])
|
||||||
|
->addForeignKey('user_id', 'auth_users', 'id', ['delete' => 'CASCADE', 'update' => 'NO_ACTION'])
|
||||||
|
->addForeignKey('idschool', 'schools', 'idschool', ['delete' => 'CASCADE', 'update' => 'NO_ACTION'])
|
||||||
|
->create();
|
||||||
|
|
||||||
|
// Tutti gli utenti esistenti appartengono a Seregno (1)
|
||||||
|
$this->execute("
|
||||||
|
INSERT INTO school_user (user_id, idschool, school_role)
|
||||||
|
SELECT id, 1, 'student' FROM auth_users
|
||||||
|
");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
$this->table('school_user')->drop()->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Phinx\Migration\AbstractMigration;
|
||||||
|
|
||||||
|
final class AddIdschoolToDomainTables extends AbstractMigration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Tabelle applicative che diventano "per scuola".
|
||||||
|
* Le tabelle auth_* (Vanguard) restano globali: il legame
|
||||||
|
* utente-scuola passa da school_user.
|
||||||
|
*/
|
||||||
|
private const TABLES = [
|
||||||
|
'associateclass',
|
||||||
|
'bookingclass',
|
||||||
|
'certificateuserprofile',
|
||||||
|
'copyorder',
|
||||||
|
'copyorder_items',
|
||||||
|
'dayoff',
|
||||||
|
'employee',
|
||||||
|
'events',
|
||||||
|
'event_bookings',
|
||||||
|
'event_locations',
|
||||||
|
'expiryparameter',
|
||||||
|
'location',
|
||||||
|
'option',
|
||||||
|
'orderbook',
|
||||||
|
'propagation',
|
||||||
|
'service',
|
||||||
|
'servicecategory',
|
||||||
|
'serviceschedule',
|
||||||
|
'userprofile',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
foreach (self::TABLES as $name) {
|
||||||
|
$this->table($name)
|
||||||
|
->addColumn('idschool', 'integer', [
|
||||||
|
'signed' => false,
|
||||||
|
'null' => false,
|
||||||
|
'default' => 1, // TEMPORANEO: verrà rimosso quando tutte le INSERT passeranno idschool
|
||||||
|
])
|
||||||
|
->addIndex(['idschool'], ['name' => "idx_{$name}_idschool"])
|
||||||
|
->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Slug eventi: unico per scuola, non più globale
|
||||||
|
$this->table('events')
|
||||||
|
->removeIndexByName('events_slug_unique')
|
||||||
|
->addIndex(['idschool', 'slug'], ['unique' => true, 'name' => 'events_school_slug_unique'])
|
||||||
|
->update();
|
||||||
|
|
||||||
|
// Impostazioni: una sola riga per scuola
|
||||||
|
$this->table('option')
|
||||||
|
->addIndex(['idschool'], ['unique' => true, 'name' => 'option_idschool_unique'])
|
||||||
|
->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
$this->table('option')
|
||||||
|
->removeIndexByName('option_idschool_unique')
|
||||||
|
->update();
|
||||||
|
|
||||||
|
$this->table('events')
|
||||||
|
->removeIndexByName('events_school_slug_unique')
|
||||||
|
->addIndex(['slug'], ['unique' => true, 'name' => 'events_slug_unique'])
|
||||||
|
->update();
|
||||||
|
|
||||||
|
foreach (self::TABLES as $name) {
|
||||||
|
$this->table($name)
|
||||||
|
->removeIndexByName("idx_{$name}_idschool")
|
||||||
|
->removeColumn('idschool')
|
||||||
|
->update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Phinx\Migration\AbstractMigration;
|
||||||
|
|
||||||
|
final class AddIdschoolToDomainTables extends AbstractMigration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Tabelle applicative che diventano "per scuola".
|
||||||
|
* Le tabelle auth_* (Vanguard) restano globali: il legame
|
||||||
|
* utente-scuola passa da school_user.
|
||||||
|
*/
|
||||||
|
private const TABLES = [
|
||||||
|
'associateclass',
|
||||||
|
'bookingclass',
|
||||||
|
'certificateuserprofile',
|
||||||
|
'copyorder',
|
||||||
|
'copyorder_items',
|
||||||
|
'dayoff',
|
||||||
|
'employee',
|
||||||
|
'events',
|
||||||
|
'event_bookings',
|
||||||
|
'event_locations',
|
||||||
|
'expiryparameter',
|
||||||
|
'location',
|
||||||
|
'option',
|
||||||
|
'orderbook',
|
||||||
|
'propagation',
|
||||||
|
'service',
|
||||||
|
'servicecategory',
|
||||||
|
'serviceschedule',
|
||||||
|
'userprofile',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
foreach (self::TABLES as $name) {
|
||||||
|
$this->table($name)
|
||||||
|
->addColumn('idschool', 'integer', [
|
||||||
|
'signed' => false,
|
||||||
|
'null' => false,
|
||||||
|
'default' => 1, // TEMPORANEO: verrà rimosso quando tutte le INSERT passeranno idschool
|
||||||
|
])
|
||||||
|
->addIndex(['idschool'], ['name' => "idx_{$name}_idschool"])
|
||||||
|
->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Slug eventi: unico per scuola, non più globale
|
||||||
|
$this->table('events')
|
||||||
|
->removeIndexByName('events_slug_unique')
|
||||||
|
->addIndex(['idschool', 'slug'], ['unique' => true, 'name' => 'events_school_slug_unique'])
|
||||||
|
->update();
|
||||||
|
|
||||||
|
// Impostazioni: una sola riga per scuola
|
||||||
|
$this->table('option')
|
||||||
|
->addIndex(['idschool'], ['unique' => true, 'name' => 'option_idschool_unique'])
|
||||||
|
->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
$this->table('option')
|
||||||
|
->removeIndexByName('option_idschool_unique')
|
||||||
|
->update();
|
||||||
|
|
||||||
|
$this->table('events')
|
||||||
|
->removeIndexByName('events_school_slug_unique')
|
||||||
|
->addIndex(['slug'], ['unique' => true, 'name' => 'events_slug_unique'])
|
||||||
|
->update();
|
||||||
|
|
||||||
|
foreach (self::TABLES as $name) {
|
||||||
|
$this->table($name)
|
||||||
|
->removeIndexByName("idx_{$name}_idschool")
|
||||||
|
->removeColumn('idschool')
|
||||||
|
->update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Phinx\Migration\AbstractMigration;
|
||||||
|
|
||||||
|
final class CreateSchoolUserTable extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
$this->table('school_user', [
|
||||||
|
'id' => false,
|
||||||
|
'primary_key' => ['idschooluser'],
|
||||||
|
'engine' => 'InnoDB',
|
||||||
|
'collation' => 'utf8mb4_unicode_ci',
|
||||||
|
])
|
||||||
|
->addColumn('idschooluser', 'integer', ['signed' => false, 'identity' => true])
|
||||||
|
->addColumn('user_id', 'integer', ['signed' => false, 'comment' => 'auth_users.id'])
|
||||||
|
->addColumn('idschool', 'integer', ['signed' => false])
|
||||||
|
->addColumn('school_role', 'string', ['limit' => 20, 'default' => 'student', 'comment' => 'student|teacher|admin|owner'])
|
||||||
|
->addColumn('active', 'char', ['limit' => 1, 'default' => 'Y'])
|
||||||
|
->addColumn('joined_at', 'timestamp', ['null' => true, 'default' => 'CURRENT_TIMESTAMP'])
|
||||||
|
->addIndex(['user_id', 'idschool'], ['unique' => true, 'name' => 'school_user_unique'])
|
||||||
|
->addIndex(['idschool'], ['name' => 'school_user_idschool_index'])
|
||||||
|
->addForeignKey('user_id', 'auth_users', 'id', ['delete' => 'CASCADE', 'update' => 'NO_ACTION'])
|
||||||
|
->addForeignKey('idschool', 'schools', 'idschool', ['delete' => 'CASCADE', 'update' => 'NO_ACTION'])
|
||||||
|
->create();
|
||||||
|
|
||||||
|
// Tutti gli utenti esistenti appartengono a Seregno (1)
|
||||||
|
$this->execute("
|
||||||
|
INSERT INTO school_user (user_id, idschool, school_role)
|
||||||
|
SELECT id, 1, 'student' FROM auth_users
|
||||||
|
");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
$this->table('school_user')->drop()->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Phinx\Migration\AbstractMigration;
|
||||||
|
|
||||||
|
final class CreateSchoolsTable extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
$this->table('schools', [
|
||||||
|
'id' => false,
|
||||||
|
'primary_key' => ['idschool'],
|
||||||
|
'engine' => 'InnoDB',
|
||||||
|
'collation' => 'utf8mb4_unicode_ci',
|
||||||
|
])
|
||||||
|
->addColumn('idschool', 'integer', ['signed' => false, 'identity' => true])
|
||||||
|
->addColumn('name', 'string', ['limit' => 191])
|
||||||
|
->addColumn('slug', 'string', ['limit' => 100, 'comment' => 'usato per URL/sottodominio/widget'])
|
||||||
|
->addColumn('email', 'string', ['limit' => 191, 'null' => true])
|
||||||
|
->addColumn('phone', 'string', ['limit' => 40, 'null' => true])
|
||||||
|
->addColumn('address', 'string', ['limit' => 255, 'null' => true])
|
||||||
|
->addColumn('city', 'string', ['limit' => 100, 'null' => true])
|
||||||
|
->addColumn('postcode', 'string', ['limit' => 20, 'null' => true])
|
||||||
|
->addColumn('country', 'string', ['limit' => 2, 'default' => 'IT'])
|
||||||
|
->addColumn('vat_number', 'string', ['limit' => 30, 'null' => true])
|
||||||
|
->addColumn('logo', 'string', ['limit' => 191, 'null' => true])
|
||||||
|
->addColumn('timezone', 'string', ['limit' => 50, 'default' => 'Europe/Rome'])
|
||||||
|
->addColumn('locale', 'string', ['limit' => 5, 'default' => 'it'])
|
||||||
|
->addColumn('currency', 'string', ['limit' => 3, 'default' => 'EUR'])
|
||||||
|
->addColumn('status', 'string', ['limit' => 20, 'default' => 'active', 'comment' => 'active|suspended|trial'])
|
||||||
|
->addColumn('created_at', 'timestamp', ['null' => true, 'default' => 'CURRENT_TIMESTAMP'])
|
||||||
|
->addColumn('updated_at', 'timestamp', ['null' => true, 'default' => null, 'update' => 'CURRENT_TIMESTAMP'])
|
||||||
|
->addIndex(['slug'], ['unique' => true, 'name' => 'schools_slug_unique'])
|
||||||
|
->addIndex(['status'], ['name' => 'schools_status_index'])
|
||||||
|
->create();
|
||||||
|
|
||||||
|
// Seregno = scuola 1 (dati da completare poi dal pannello)
|
||||||
|
$this->table('schools')->insert([
|
||||||
|
'idschool' => 1,
|
||||||
|
'name' => 'Scuola Yoga Seregno',
|
||||||
|
'slug' => 'seregno',
|
||||||
|
'city' => 'Seregno',
|
||||||
|
'country' => 'IT',
|
||||||
|
])->saveData();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
$this->table('schools')->drop()->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user