forked from ftrotter/ORMBuild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bulk_change_field_names.php
54 lines (40 loc) · 1.27 KB
/
bulk_change_field_names.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
//copyright [email protected]
//Not Only Development, LLC 2012
//Licensed under the same license as Sequelize
//https://github.com/sdepold/sequelize/blob/master/LICENSE
$yaml_file = 'config.yaml';
if(function_exists('yaml_parse_file')){ //then we are using PECL..
$config = yaml_parse_file($yaml_file);
}else{
echo "use pecl to install php yaml";
exit();
}
$user = $config['user'];
$password = $config['password'];
$database = $config['database'];
mysql_connect($config['host'],$user,$password);
mysql_select_db($database);
$tables_sql = "SHOW TABLES";
$result = mysql_query($tables_sql) or die("arrgh... my eye!!! $tables_sql");
$fields_to_change = array(
'createdAt' => array( 'to' => 'created_at',
'type' => 'DATETIME NOT NULL'),
'updatedAt' => array( 'to' => 'updated_at',
'type' => 'DATETIME NOT NULL'),
);
foreach($fields_to_change as $from => $to_array){
$to = $to_array['to'];
$type = $to_array['type'];
while($row = mysql_fetch_array($result)){
$this_table = $row[0];
$sql = "ALTER TABLE `$this_table` CHANGE `$from` `$to` $type";
echo "$sql \n";
if(!mysql_query($sql)){
echo "Error with: ".mysql_error()."\n";
}else{
echo "$this_table changed\n";
}
}//end while
}//end foreach
?>