Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 6a0c1a7

Browse files
Michael GraueryuzhengZ
authored andcommitted
BUG: refs #0283. Got this setup working for postgres.
I had not tested the setup for postgres, and the previous setup actually copied a mysql.ini testing config file over the pgsql.ini testing config file. This version fixes that, and some other bugs that I found when cleaning up the pgsql test and getting them to work. Furthermore, there are some fixes and improvements to the helloworld module that were useful in testing this script.
1 parent e0f2474 commit 6a0c1a7

File tree

5 files changed

+30
-29
lines changed

5 files changed

+30
-29
lines changed

modules/helloworld/database/mysql/1.0.0.sql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
CREATE TABLE IF NOT EXISTS `helloworld_hello` (
33
`hello_id` bigint(20) NOT NULL AUTO_INCREMENT,
44
PRIMARY KEY (`hello_id`)
5-
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;
5+
) DEFAULT CHARSET=utf8 ;
66

7-
8-
INSERT INTO `midas`.`helloworld_hello` (`hello_id`) VALUES ('1');
7+
INSERT INTO `helloworld_hello` (`hello_id`) VALUES (default(`hello_id`));
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATE TABLE helloworld_hello (
2+
hello_id serial PRIMARY KEY
3+
);
4+
5+
INSERT INTO helloworld_hello DEFAULT VALUES;

modules/helloworld/database/upgrade/1.0.1.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ public function mysql()
2828

2929
public function pgsql()
3030
{
31-
31+
$sql = "CREATE TABLE helloworld_helloupgrade1 (
32+
id serial PRIMARY KEY
33+
);";
34+
$this->db->query($sql);
3235
}
3336

3437
public function postUpgrade()

modules/helloworld/database/upgrade/1.0.2.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ public function mysql()
3232

3333
public function pgsql()
3434
{
35-
35+
$sql = "CREATE TABLE helloworld_helloupgrade2 (
36+
id serial PRIMARY KEY
37+
);";
38+
$this->db->query($sql);
3639
}
3740

3841
public function postUpgrade()

tests/DatabaseSetup.php

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,19 @@ function loadDbAdapter($testConfigDir, $dbType)
6666
}
6767

6868

69-
function dropTables($db)
69+
function dropTables($db, $dbType)
7070
{
7171
$tables = $db->listTables();
7272
foreach($tables as $table)
7373
{
74-
$sql = "drop table `".$table."`";
74+
if($dbType === 'mysql')
75+
{
76+
$sql = "drop table `".$table."`";
77+
}
78+
else if($dbType === 'pgsql')
79+
{
80+
$sql = 'drop table "'.$table.'"';
81+
}
7582
$db->query($sql);
7683
}
7784
}
@@ -164,31 +171,16 @@ function installModules($utilityComponent)
164171
}
165172
}
166173

167-
// cleanup the lock files
168-
function releaseLocks()
174+
// cleanup the lock file
175+
function releaseLock($dbType)
169176
{
170-
if(file_exists(BASE_PATH.'/tests/configs/lock.pgsql.ini'))
177+
if(file_exists(BASE_PATH.'/tests/configs/lock.'.$dbType.'.ini'))
171178
{
172-
rename( BASE_PATH.'/tests/configs/lock.pgsql.ini',BASE_PATH.'/tests/configs/pgsql.ini');
173-
}
174-
if(file_exists(BASE_PATH.'/tests/configs/lock.mysql.ini'))
175-
{
176-
rename( BASE_PATH.'/tests/configs/lock.mysql.ini',BASE_PATH.'/tests/configs/mysql.ini');
179+
rename( BASE_PATH.'/tests/configs/lock.'.$dbType.'.ini',BASE_PATH.'/tests/configs/'.$dbType.'.ini');
177180
}
178181
}
179182

180183

181-
182-
183-
184-
185-
186-
187-
188-
189-
190-
191-
192184
// general setup
193185

194186
error_reporting(E_ALL | E_STRICT);
@@ -271,16 +263,15 @@ function releaseLocks()
271263
try
272264
{
273265
$dbAdapter = loadDbAdapter($testConfigDir, $dbType);
274-
dropTables($dbAdapter);
275-
266+
dropTables($dbAdapter, $dbType);
276267
require_once BASE_PATH.'/core/controllers/components/UtilityComponent.php';
277268
$utilityComponent = new UtilityComponent();
278269

279270
installCore($dbAdapter, $dbType, $utilityComponent);
280271
createDefaultAssetstore();
281272
installModules($utilityComponent);
282273

283-
releaseLocks();
274+
releaseLock($dbType);
284275
}
285276
catch(Zend_Exception $ze)
286277
{

0 commit comments

Comments
 (0)