CakeAddresses/config/Migrations/20240117020203_InitialAddre...

606 lines
18 KiB
PHP
Raw Permalink Normal View History

2025-11-18 08:43:34 +00:00
<?php
declare(strict_types=1);
use Migrations\AbstractMigration;
class InitialAddresses extends AbstractMigration
{
/**
* Up Method.
*
* More information on this method is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-up-method
* @return void
*/
public function up(): void
{
$this->table('addresses')
->addColumn('address_name', 'string', [
'default' => null,
'limit' => 255,
'null' => true,
])
->addColumn('contact_name', 'string', [
'default' => null,
'limit' => 255,
'null' => true,
])
->addColumn('address_line1', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
])
->addColumn('address_line2', 'string', [
'default' => null,
'limit' => 255,
'null' => true,
])
->addColumn('city', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
])
->addColumn('city_id', 'integer', [
'default' => null,
'limit' => null,
'null' => true,
'signed' => true,
])
->addColumn('state', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
])
->addColumn('state_id', 'integer', [
'default' => null,
'limit' => null,
'null' => true,
'signed' => true,
])
->addColumn('postal_code', 'string', [
'default' => null,
'limit' => 25,
'null' => false,
])
->addColumn('country', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
])
->addColumn('country_id', 'integer', [
'default' => null,
'limit' => null,
'null' => true,
'signed' => true,
])
->addColumn('phone_number', 'string', [
'default' => null,
'limit' => 25,
'null' => true,
])
->addColumn('email', 'string', [
'default' => null,
'limit' => 255,
'null' => true,
])
->addColumn('notes', 'text', [
'default' => null,
'limit' => null,
'null' => true,
])
->create();
$this->table('cities')
->addColumn('name', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
])
->addColumn('state_id', 'integer', [
'default' => null,
'limit' => null,
'null' => false,
'signed' => false,
])
->addColumn('state_code', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
])
->addColumn('country_id', 'integer', [
'default' => null,
'limit' => null,
'null' => false,
'signed' => false,
])
->addColumn('country_code', 'char', [
'default' => null,
'limit' => 2,
'null' => false,
])
->addColumn('latitude', 'decimal', [
'default' => null,
'null' => false,
'precision' => 10,
'scale' => 8,
'signed' => true,
])
->addColumn('longitude', 'decimal', [
'default' => null,
'null' => false,
'precision' => 11,
'scale' => 8,
'signed' => true,
])
->addColumn('created_at', 'timestamp', [
'default' => '2014-01-01 14:31:01',
'limit' => null,
'null' => false,
])
->addColumn('updated_at', 'timestamp', [
'default' => '2014-01-01 14:31:01',
'limit' => null,
'null' => false,
])
->addColumn('flag', 'boolean', [
'default' => true,
'limit' => null,
'null' => false,
])
->addColumn('wikiDataId', 'string', [
'comment' => 'Rapid API GeoDB Cities',
'default' => null,
'limit' => 255,
'null' => true,
])
// ->addIndex(
// [
// 'state_id',
// ],
// [
// 'name' => 'cities_test_ibfk_1',
// ]
// )
// ->addIndex(
// [
// 'country_id',
// ],
// [
// 'name' => 'cities_test_ibfk_2',
// ]
// )
->create();
$this->table('countries')
->addColumn('name', 'string', [
'default' => null,
'limit' => 100,
'null' => false,
])
->addColumn('iso3', 'char', [
'default' => null,
'limit' => 3,
'null' => true,
])
->addColumn('numeric_code', 'char', [
'default' => null,
'limit' => 3,
'null' => true,
])
->addColumn('iso2', 'char', [
'default' => null,
'limit' => 2,
'null' => true,
])
->addColumn('phonecode', 'string', [
'default' => null,
'limit' => 255,
'null' => true,
])
->addColumn('capital', 'string', [
'default' => null,
'limit' => 255,
'null' => true,
])
->addColumn('currency', 'string', [
'default' => null,
'limit' => 255,
'null' => true,
])
->addColumn('currency_name', 'string', [
'default' => null,
'limit' => 255,
'null' => true,
])
->addColumn('currency_symbol', 'string', [
'default' => null,
'limit' => 255,
'null' => true,
])
->addColumn('tld', 'string', [
'default' => null,
'limit' => 255,
'null' => true,
])
->addColumn('native', 'string', [
'default' => null,
'limit' => 255,
'null' => true,
])
->addColumn('region', 'string', [
'default' => null,
'limit' => 255,
'null' => true,
])
->addColumn('region_id', 'integer', [
'default' => null,
'limit' => null,
'null' => true,
'signed' => false,
])
->addColumn('subregion', 'string', [
'default' => null,
'limit' => 255,
'null' => true,
])
->addColumn('subregion_id', 'integer', [
'default' => null,
'limit' => null,
'null' => true,
'signed' => false,
])
->addColumn('nationality', 'string', [
'default' => null,
'limit' => 255,
'null' => true,
])
->addColumn('timezones', 'text', [
'default' => null,
'limit' => null,
'null' => true,
])
->addColumn('translations', 'text', [
'default' => null,
'limit' => null,
'null' => true,
])
->addColumn('latitude', 'decimal', [
'default' => null,
'null' => true,
'precision' => 10,
'scale' => 8,
'signed' => true,
])
->addColumn('longitude', 'decimal', [
'default' => null,
'null' => true,
'precision' => 11,
'scale' => 8,
'signed' => true,
])
->addColumn('emoji', 'string', [
'default' => null,
'limit' => 191,
'null' => true,
])
->addColumn('emojiU', 'string', [
'default' => null,
'limit' => 191,
'null' => true,
])
->addColumn('created_at', 'timestamp', [
'default' => null,
'limit' => null,
'null' => true,
])
->addColumn('updated_at', 'timestamp', [
'default' => '2014-01-01 14:31:01',
'limit' => null,
'null' => false,
])
->addColumn('flag', 'boolean', [
'default' => true,
'limit' => null,
'null' => false,
])
->addColumn('wikiDataId', 'string', [
'comment' => 'Rapid API GeoDB Cities',
'default' => null,
'limit' => 255,
'null' => true,
])
->addIndex(
[
'region_id',
],
[
'name' => 'country_continent',
]
)
->addIndex(
[
'subregion_id',
],
[
'name' => 'country_subregion',
]
)
->create();
$this->table('regions')
->addColumn('name', 'string', [
'default' => null,
'limit' => 100,
'null' => false,
])
->addColumn('translations', 'text', [
'default' => null,
'limit' => null,
'null' => true,
])
->addColumn('created_at', 'timestamp', [
'default' => null,
'limit' => null,
'null' => true,
])
->addColumn('updated_at', 'timestamp', [
'default' => '2014-01-01 14:31:01',
'limit' => null,
'null' => false,
])
->addColumn('flag', 'boolean', [
'default' => true,
'limit' => null,
'null' => false,
])
->addColumn('wikiDataId', 'string', [
'comment' => 'Rapid API GeoDB Cities',
'default' => null,
'limit' => 255,
'null' => true,
])
->create();
$this->table('states')
->addColumn('name', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
])
->addColumn('country_id', 'integer', [
'default' => null,
'limit' => null,
'null' => false,
'signed' => false,
])
->addColumn('country_code', 'char', [
'default' => null,
'limit' => 2,
'null' => false,
])
->addColumn('fips_code', 'string', [
'default' => null,
'limit' => 255,
'null' => true,
])
->addColumn('iso2', 'string', [
'default' => null,
'limit' => 255,
'null' => true,
])
->addColumn('type', 'string', [
'default' => null,
'limit' => 191,
'null' => true,
])
->addColumn('latitude', 'decimal', [
'default' => null,
'null' => true,
'precision' => 10,
'scale' => 8,
'signed' => true,
])
->addColumn('longitude', 'decimal', [
'default' => null,
'null' => true,
'precision' => 11,
'scale' => 8,
'signed' => true,
])
->addColumn('created_at', 'timestamp', [
'default' => null,
'limit' => null,
'null' => true,
])
->addColumn('updated_at', 'timestamp', [
'default' => '2014-01-01 14:31:01',
'limit' => null,
'null' => false,
])
->addColumn('flag', 'boolean', [
'default' => true,
'limit' => null,
'null' => false,
])
->addColumn('wikiDataId', 'string', [
'comment' => 'Rapid API GeoDB Cities',
'default' => null,
'limit' => 255,
'null' => true,
])
->addIndex(
[
'country_id',
],
[
'name' => 'country_region',
]
)
->create();
$this->table('subregions')
->addColumn('name', 'string', [
'default' => null,
'limit' => 100,
'null' => false,
])
->addColumn('translations', 'text', [
'default' => null,
'limit' => null,
'null' => true,
])
->addColumn('region_id', 'integer', [
'default' => null,
'limit' => null,
'null' => false,
'signed' => false,
])
->addColumn('created_at', 'timestamp', [
'default' => null,
'limit' => null,
'null' => true,
])
->addColumn('updated_at', 'timestamp', [
'default' => '2014-01-01 14:31:01',
'limit' => null,
'null' => false,
])
->addColumn('flag', 'boolean', [
'default' => true,
'limit' => null,
'null' => false,
])
->addColumn('wikiDataId', 'string', [
'comment' => 'Rapid API GeoDB Cities',
'default' => null,
'limit' => 255,
'null' => true,
])
->addIndex(
[
'region_id',
],
[
'name' => 'subregion_continent',
]
)
->create();
// $this->table('cities')
// ->addForeignKey(
// 'country_id',
// 'countries',
// 'id',
// [
// 'update' => 'RESTRICT',
// 'delete' => 'RESTRICT',
// 'constraint' => 'cities_ibfk_2'
// ]
// )
// ->addForeignKey(
// 'state_id',
// 'states',
// 'id',
// [
// 'update' => 'RESTRICT',
// 'delete' => 'RESTRICT',
// 'constraint' => 'cities_ibfk_1'
// ]
// )
// ->update();
// $this->table('countries')
// ->addForeignKey(
// 'subregion_id',
// 'subregions',
// 'id',
// [
// 'update' => 'RESTRICT',
// 'delete' => 'RESTRICT',
// 'constraint' => 'country_subregion_final'
// ]
// )
// ->addForeignKey(
// 'region_id',
// 'regions',
// 'id',
// [
// 'update' => 'RESTRICT',
// 'delete' => 'RESTRICT',
// 'constraint' => 'country_continent_final'
// ]
// )
// ->update();
// $this->table('states')
// ->addForeignKey(
// 'country_id',
// 'countries',
// 'id',
// [
// 'update' => 'RESTRICT',
// 'delete' => 'RESTRICT',
// 'constraint' => 'country_region_final'
// ]
// )
// ->update();
//
// $this->table('subregions')
// ->addForeignKey(
// 'region_id',
// 'regions',
// 'id',
// [
// 'update' => 'RESTRICT',
// 'delete' => 'RESTRICT',
// 'constraint' => 'subregion_continent_final'
// ]
// )
// ->update();
}
/**
* Down Method.
*
* More information on this method is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-down-method
* @return void
*/
public function down(): void
{
$this->table('cities')
->dropForeignKey(
'country_id'
)
->dropForeignKey(
'state_id'
)->save();
$this->table('countries')
->dropForeignKey(
'subregion_id'
)
->dropForeignKey(
'region_id'
)
->save();
$this->table('states')
->dropForeignKey(
'country_id'
)->save();
$this->table('subregions')
->dropForeignKey(
'region_id'
)->save();
$this->table('addresses')->drop()->save();
$this->table('cities')->drop()->save();
$this->table('countries')->drop()->save();
$this->table('regions')->drop()->save();
$this->table('states')->drop()->save();
$this->table('subregions')->drop()->save();
}
}