<?php

use Phalcon\Db\Column;
use Phalcon\Db\Index;
use Phalcon\Db\Reference;
use Phalcon\Mvc\Model\Migration;

/**
 * Class DiskusiObjekMigration_133
 */
class DiskusiObjekMigration_133 extends Migration
{
	/**
     * Define the table structure
     *
     * @return void
     */
	public function morph()
	{ }

	/**
     * Run the migrations
     *
     * @return void
     */
	public function up()
	{
		self::$connection->execute(
			'
				insert into jaga.diskusi_objek(diskusi_id, objek_id, nama_objek)
				(
					select (select id from jaga.diskusi where uuid=A.id), (select kode_rs from jaga.rumah_sakit where id=A.objek_id), coalesce((select nama from jaga.rumah_sakit where id=A.objek_id),\'-\')
					from jaga.cerita A where produk_id = \'fa1b6d02-4e1b-4be6-8f25-55f6a4731b86\' and objek_id is not null
				);

				insert into jaga.diskusi_objek(diskusi_id, objek_id, nama_objek)
				(
					select (select id from jaga.diskusi where uuid=A.id), (select kode_puskesmas from jaga.puskesmas where id=A.objek_id), coalesce((select nama_puskesmas from jaga.puskesmas where id=A.objek_id),\'-\')
					from jaga.cerita A where produk_id = \'c9e0d05e-39a1-469f-b48b-b320736c1813\' and objek_id is not null
				);

				insert into jaga.diskusi_objek(diskusi_id, objek_id, nama_objek)
				(
					select (select id from jaga.diskusi where uuid=A.id), (select id_ptsp from jaga.perizinan_bkpm where id_uuid=A.objek_id),
					coalesce((select nama_instansi_penyelenggara from jaga.perizinan_bkpm where id_uuid=A.objek_id), \'\')
					from jaga.cerita A where produk_id = \'6764c74d-c742-4740-b36b-e6a60f153436\' and objek_id is not null
				);

				insert into jaga.diskusi_objek(diskusi_id, objek_id, nama_objek)
				(
					select (select id from jaga.diskusi where uuid=A.id), (select id from jaga.desa_master_desa where id=A.objek_id), coalesce((select desa_kelurahan from jaga.desa_master_desa where id=A.objek_id),\'-\')
					from jaga.cerita A where produk_id = \'1ae17fec-0caa-4c85-8eaf-2f90a4a60621\' and objek_id is not null
				);
			'
		);
	}

	/**
     * Reverse the migrations
     *
     * @return void
     */
	public function down()
	{ }
}
