-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
950 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
app/migrations/filevault_status_model/001_add_filevault_users.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
class Migration_add_filevault_users extends Model | ||
{ | ||
protected $columname = 'filevault_users'; | ||
|
||
function __construct() | ||
{ | ||
parent::__construct(); | ||
$this->tablename = 'filevault_status'; | ||
} | ||
|
||
public function up() | ||
{ | ||
// Get database handle | ||
$dbh = $this->getdbh(); | ||
|
||
// Wrap in transaction | ||
$dbh->beginTransaction(); | ||
|
||
// Adding a column is simple... | ||
$sql = sprintf('ALTER TABLE %s ADD COLUMN %s VARCHAR(255)', | ||
$this->enquote($this->tablename), $this->enquote($this->columname)); | ||
|
||
$this->exec($sql); | ||
|
||
// so is adding an index... | ||
$idx_name = $this->tablename . '_' . $this->columname; | ||
$sql = sprintf("CREATE INDEX %s ON %s (%s)", | ||
$idx_name, $this->enquote($this->tablename), $this->columname); | ||
|
||
$this->exec($sql); | ||
|
||
$dbh->commit(); | ||
} | ||
|
||
public function down() | ||
{ | ||
// Get database handle | ||
$dbh = $this->getdbh(); | ||
|
||
switch ($this->get_driver()) | ||
{ | ||
case 'sqlite':// ...removing a column in SQLite is hard | ||
|
||
$dbh->beginTransaction(); | ||
|
||
// Create temporary table | ||
$sql = "CREATE TABLE filevault_status_temp ( | ||
id INTEGER PRIMARY KEY, | ||
serial_number VARCHAR(255) UNIQUE, | ||
filevault_status VARCHAR(255))"; | ||
$this->exec($sql); | ||
|
||
$sql = "INSERT INTO filevault_status_temp | ||
SELECT id, serial_number, filevault_status FROM filevault_status"; | ||
$this->exec($sql); | ||
|
||
$sql = "DROP table filevault_status"; | ||
$this->exec($sql); | ||
|
||
$sql = "ALTER TABLE filevault_status_temp RENAME TO filevault_status"; | ||
$this->exec($sql); | ||
|
||
// Add index for old filevault_status column | ||
$idx_name = $this->tablename . '_filevault_status'; | ||
$sql = sprintf("CREATE INDEX %s ON %s (%s)", | ||
$idx_name, $this->enquote($this->tablename), 'filevault_status'); | ||
|
||
$this->exec($sql); | ||
|
||
$dbh->commit(); | ||
|
||
break; | ||
|
||
default: // MySQL (other engines?) | ||
|
||
// MySQL drops the index as well -> check for other engines | ||
$sql = sprintf('ALTER TABLE %s DROP COLUMN %s', | ||
$this->enquote($this->tablename), $this->enquote($this->columname)); | ||
$this->exec($sql); | ||
} | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
app/migrations/network_model/001_network_model_fix_ipv4router.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
// Fix the ipv4 router: was integer, should be varchar | ||
|
||
class Migration_network_model_fix_ipv4router extends Model | ||
{ | ||
|
||
public function up() | ||
{ | ||
// Get database handle | ||
$dbh = $this->getdbh(); | ||
|
||
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | ||
|
||
// Wrap in transaction | ||
$dbh->beginTransaction(); | ||
|
||
switch ($this->get_driver()) | ||
{ | ||
case 'sqlite': | ||
|
||
// Set IPv4 router to string affinity | ||
// Unfortunately this is not very simple | ||
$sql = "CREATE TABLE network_temp ( | ||
id INTEGER PRIMARY KEY, | ||
serial_number VARCHAR(255) UNIQUE, | ||
service VARCHAR(255), | ||
`order` INTEGER, | ||
status INTEGER, | ||
ethernet VARCHAR(255), | ||
clientid VARCHAR(255), | ||
ipv4conf VARCHAR(255), | ||
ipv4ip VARCHAR(255), | ||
ipv4mask VARCHAR(255), | ||
ipv4router VARCHAR(255), | ||
ipv6conf VARCHAR(255), | ||
ipv6ip VARCHAR(255), | ||
ipv6prefixlen INTEGER, | ||
ipv6router VARCHAR(255), | ||
timestamp INTEGER)"; | ||
$this->exec($sql); | ||
|
||
$sql = "INSERT INTO network_temp SELECT * FROM network"; | ||
$this->exec($sql); | ||
|
||
$sql = "DROP table network"; | ||
$this->exec($sql); | ||
|
||
$sql = "ALTER TABLE network_temp RENAME TO network"; | ||
$this->exec($sql); | ||
|
||
// Re-add indexes | ||
$this->tablename = 'network'; | ||
$this->idx[] = array('serial_number'); | ||
$this->idx[] = array('serial_number', 'service'); | ||
$this->set_indexes(); | ||
|
||
break; | ||
|
||
case 'mysql': | ||
|
||
// Set ipv4router column to VARCHAR | ||
$sql = "ALTER TABLE network MODIFY ipv4router VARCHAR(255)"; | ||
$this->exec($sql); | ||
|
||
break; | ||
|
||
default: | ||
|
||
# code... | ||
break; | ||
} | ||
|
||
// Commit changes | ||
$dbh->commit(); | ||
|
||
|
||
}// End function up() | ||
|
||
public function down() | ||
{ | ||
// As this is an error correction, there's no need for down(). | ||
// up() is idempotent | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.