|
- <?php
- declare(strict_types=1);
-
- use Migrations\BaseMigration;
-
- class CreateAddresses extends BaseMigration
- {
- /**
- * Change Method.
- *
- * More information on this method is available here:
- * https://book.cakephp.org/migrations/5/guides/writing-migrations/migration-methods.html#the-change-method
- *
- * @return void
- */
- public function change(): void
- {
- $table = $this->table('addresses');
- $table->addColumn('territory_id', 'integer', [
- 'default' => null,
- 'limit' => 11,
- 'null' => false,
- ]);
- $table->addColumn('osm_type', 'string', [
- 'default' => null,
- 'limit' => 255,
- 'null' => false,
- ]);
- $table->addColumn('osm_id', 'biginteger', [
- 'default' => null,
- 'limit' => 20,
- 'null' => false,
- ]);
- $table->addColumn('house_number', 'string', [
- 'default' => null,
- 'limit' => 255,
- 'null' => true,
- ]);
- $table->addColumn('street', 'string', [
- 'default' => null,
- 'limit' => 255,
- 'null' => true,
- ]);
- $table->addColumn('full_address', 'string', [
- 'default' => null,
- 'limit' => 255,
- 'null' => false,
- ]);
- $table->addColumn('lat', 'decimal', [
- 'default' => null,
- 'null' => false,
- 'precision' => 10,
- 'scale' => 7,
- ]);
- $table->addColumn('lng', 'decimal', [
- 'default' => null,
- 'null' => false,
- 'precision' => 10,
- 'scale' => 7,
- ]);
- $table->addColumn('created', 'datetime', [
- 'default' => null,
- 'null' => false,
- ]);
- $table->addIndex(['territory_id']);
- $table->addIndex(['territory_id', 'osm_type', 'osm_id'], ['unique' => true, 'name' => 'idx_territory_osm_unique']);
- $table->addForeignKey('territory_id', 'territories', 'id', ['delete' => 'CASCADE', 'update' => 'NO_ACTION']);
- $table->create();
- }
- }
|