7 use Phinx\Migration\AbstractMigration;
19 "idx01" => array(
"cols"=>
"cu"),
20 "idx02" => array(
"cols"=>
"service")
23 $tableName =
"cu_vendorlog";
24 $tableExists = $this->hasTable( $tableName );
26 foreach ($indexNames as $index => $cols) {
27 $indexName = $tableName .
"_" . $index;
28 $indexColumns = $cols[
'cols'];
33 SELECT COUNT(*) FROM pg_class pgc 34 WHERE pgc.relname = '{$indexName}' 35 AND pgc.relkind = 'i'";
37 $idxCount = $this->fetchAll($sql);
38 $idxExists = intval($idxCount[0][
'count']);
40 if ($tableExists && $idxExists == 0) {
41 $sql =
"CREATE INDEX {$indexName} ON {$tableName} USING btree ($indexColumns)";
42 $sqlRs = $this->query($sql);
52 public function down()
56 "idx01" => array(
"cols"=>
"cu"),
57 "idx02" => array(
"cols"=>
"service")
60 $tableName =
"cu_vendorlog";
61 $tableExists = $this->hasTable( $tableName );
63 foreach ($indexNames as $index => $cols) {
64 $indexName = $tableName .
"_" . $index;
65 $indexColumns = $cols[
'cols'];
69 SELECT COUNT(*) FROM pg_class pgc 70 WHERE pgc.relname = '{$indexName}' 71 AND pgc.relkind = 'i'";
73 $idxCount = $this->fetchAll($sql);
74 $idxExists = intval($idxCount[0][
'count']);
76 if ($tableExists && $idxExists > 0) {
77 $sql =
"DROP INDEX {$indexName}";
78 $sqlRs = $this->query($sql);