7 use Phinx\Migration\AbstractMigration;
19 "scheduledtxn" => array(
"title"=>
"cuuser_idx",
"cols"=>
"cu, user_id, id"),
20 "alerts" => array(
"title"=>
"cuuser_idx",
"cols"=>
"cu, user_id, alerttype")
23 foreach ($tableNames as $table => $index) {
24 $tableName =
"cu_" . $table;
25 $tableExists = $this->hasTable( $tableName );
26 $indexName =
"cu_" . $table .
"_" . $index[
'title'];
27 $indexColumns = $index[
'cols'];
31 SELECT COUNT(*) FROM pg_class pgc 32 WHERE pgc.relname = '{$indexName}' 33 AND pgc.relkind = 'i'";
35 $idxCount = $this->fetchAll($sql);
36 $idxExists = intval($idxCount[0][
'count']);
38 if ($tableExists && $idxExists == 0) {
39 $sql =
"CREATE INDEX {$indexName} ON {$tableName} USING btree ($indexColumns)";
40 $sqlRs = $this->query($sql);
50 public function down()
54 "scheduledtxn" => array(
"title"=>
"cuuser_idx",
"cols"=>
"cu, user_id, id"),
55 "alerts" => array(
"title"=>
"cuuser_idx",
"cols"=>
"cu, user_id, alerttype")
58 foreach ($tableNames as $table => $index) {
59 $tableName =
"cu_" . $table;
60 $tableExists = $this->hasTable( $tableName );
61 $indexName =
"cu_" . $table .
"_" . $index[
'title'];
62 $indexColumns = $index[
'cols'];
66 SELECT COUNT(*) FROM pg_class pgc 67 WHERE pgc.relname = '{$indexName}' 68 AND pgc.relkind = 'i'";
70 $idxCount = $this->fetchAll($sql);
71 $idxExists = intval($idxCount[0][
'count']);
73 if ($tableExists && $idxExists > 0) {
74 $sql =
"DROP INDEX {$indexName}";
75 $sqlRs = $this->query($sql);