7 use Phinx\Migration\AbstractMigration;
9 class M2M extends AbstractMigration
18 $tableName =
"cu_feature";
19 $row = $this->fetchRow(
"SELECT * FROM cu_feature WHERE feature_code = 'TRNM2M'" );
21 $singleRow = [
"feature_code" =>
"TRNM2M",
22 "description" =>
"Member to member transfer",
26 $table = $this->table( $tableName );
27 $table->insert($singleRow)->saveData();
31 $cuList = $this->fetchAll(
'SELECT cu FROM cuadmin');
33 for ( $i = 0; $i < count( $cuList ); $i++ ) {
34 $cu = strtolower( trim( $cuList[$i][
"cu"] ) );
35 $CU = strtoupper( $cu );
37 $tableName =
"cu_featuremenu";
38 $row = $this->fetchRow(
"SELECT * FROM cu_featuremenu WHERE feature_code = 'TRNM2M' AND cu='{$CU}'" );
40 $singleRow = [
"feature_code" =>
"TRNM2M",
42 "display_order" => 12,
43 "parent_item_id" => 32,
44 "menu_item_type" =>
"D",
45 "menu_item_platform" =>
'["D","M"]',
46 "menu_item_attr" =>
'{"display":{"en_US":"M2M Accounts","es_US":""},"fa-icon":"","href":"hcuM2MAccts.prg","hrefUrlQuery":1,"target":0,"hrefExtraParam":""}' ];
47 $table = $this->table( $tableName );
48 $table->insert($singleRow)->saveData();
52 $tableName =
"{$cu}extaccount";
53 $table = $this->table( $tableName );
54 $hasColumn = $table->hasColumn(
'type');
59 print
"Converting $cu {$tableName}\n";
62 $sql =
"CREATE TABLE {$cu}extaccounttemp ( 63 id SERIAL PRIMARY KEY, 64 user_id integer NOT NULL, 66 display_name varchar(20), 72 $rows = $this->query( $sql );
75 $sql =
"INSERT INTO {$cu}extaccounttemp 76 (id, user_id, type, display_name, 78 SELECT id, user_id, 'EXT' as type, display_name, 79 status, remote_info FROM $tableName";
82 $count = $this->execute( $sql );
84 print
"$count row(s) copied from existing $tableName";
87 $this->dropTable( $tableName );
90 $table = $this->table(
"{$cu}extaccounttemp" );
91 $table->rename( $tableName );
94 $sql =
"CREATE UNIQUE INDEX {$cu}extaccount_name_key on {$cu}extaccount USING btree ( user_id, display_name );";
95 $rows = $this->query( $sql );
98 $sql =
"COMMENT ON COLUMN {$cu}extaccount.user_id is 'User who set it up; foreign key to <cu>user.user_id';";
99 $rows = $this->query( $sql );
101 $sql =
"COMMENT ON COLUMN {$cu}extaccount.type is 'EXT, M2M';";
102 $rows = $this->query( $sql );
104 $sql =
"COMMENT ON COLUMN {$cu}extaccount.display_name is 'Name that displays in Banking';";
105 $rows = $this->query( $sql );
107 $sql =
"COMMENT ON COLUMN {$cu}extaccount.status is 'Pending/Active/Inactive flag';";
108 $rows = $this->query( $sql );
110 $sql =
"COMMENT ON COLUMN {$cu}extaccount.remote_info is 'JSON object that holds the remote account information';";
111 $rows = $this->query( $sql );
122 public function down()
125 $cuList = $this->fetchAll(
'SELECT cu FROM cuadmin');
127 for ( $i = 0; $i < count( $cuList ); $i++ ) {
128 $cu = strtolower( trim( $cuList[$i][
"cu"] ) );
131 $tableName =
"{$cu}extaccount";
132 $hasColumn = $table->hasColumn(
'type');
137 print
"Reverting $cu {$tableName}\n";
140 $table->removeColumn(
'type')->save();