Skip to content

Instantly share code, notes, and snippets.

@agungsijawir
Created February 11, 2017 10:33
Show Gist options
  • Save agungsijawir/17f887e43673e453492897209deea972 to your computer and use it in GitHub Desktop.
Save agungsijawir/17f887e43673e453492897209deea972 to your computer and use it in GitHub Desktop.
<?php
use yii\db\Migration;
class m170211_100226_initProvinsi extends Migration
{
public function up()
{
$this->createTable('provinsi', [
'id' => $this->string(128)->notNull(),
'nama' => $this->string(128)->notNull(),
'created_at' => $this->dateTime(),
'updated_at' => $this->dateTime()
]);
$this->addPrimaryKey('PK_id_provinsi', 'provinsi', 'id');
$this->createTable('kabupaten', [
'id' => $this->string(128)->notNull(),
'id_provinsi' => $this->string(128)->notNull(),
'nama' => $this->string(128)->notNull(),
'created_at' => $this->dateTime(),
'updated_at' => $this->dateTime()
]);
$this->addPrimaryKey('PK_id_kabupaten', 'kabupaten', 'id');
$this->addForeignKey('FK_id_prov_in_kab', 'kabupaten', 'id_provinsi', 'provinsi', 'id');
$this->createTable('kecamatan', [
'id' => $this->string(128)->notNull(),
'id_kabupaten' => $this->string(128)->notNull(),
'nama' => $this->string(128)->notNull(),
'created_at' => $this->dateTime(),
'updated_at' => $this->dateTime()
]);
$this->addPrimaryKey('PK_id_kecamatan', 'kecamatan', 'id');
$this->addForeignKey('FK_id_kab_in_kec', 'kecamatan', 'id_kabupaten', 'kabupaten', 'id');
}
public function down()
{
// reverse order
$this->dropForeignKey('FK_id_kab_in_kec', 'kecamatan');
$this->dropPrimaryKey('PK_id_kecamatan', 'kecamatan');
$this->dropTable('kecamatan');
$this->dropForeignKey('FK_id_prov_in_kab', 'kabupaten');
$this->dropPrimaryKey('PK_id_kabupaten', 'kabupaten');
$this->dropTable('kabupaten');
$this->dropPrimaryKey('PK_id_provinsi', 'provinsi');
$this->dropTable('provinsi');
echo "m170211_100226_initProvinsi has been reverted.\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment