Skip to content

Instantly share code, notes, and snippets.

@rsmarshall
Created May 17, 2012 11:15
Show Gist options
  • Save rsmarshall/2718224 to your computer and use it in GitHub Desktop.
Save rsmarshall/2718224 to your computer and use it in GitHub Desktop.
sql migration
<?php
class Migration_Foreign_keys extends Migration {
public $migration_type = 'sql';
public function up()
{
$prefix = $this->db->dbprefix;
$sql = "
ALTER TABLE {$prefix}supplier_pricing
ADD CONSTRAINT supplier_id FOREIGN KEY (supplier_id) REFERENCES {$prefix}supplier_details(id)
ON UPDATE CASCADE
ON DELETE CASCADE;";
return $sql;
}
public function down()
{
$prefix = $this->db->dbprefix;
$sql = "
ALTER TABLE {$prefix}supplier_pricing DROP FOREIGN KEY supplier_id;
ALTER TABLE {$prefix}supplier_pricing DROP INDEX supplier_id;";
return $sql;
}
}
/* End of file: 004_Foreign_keys.php */
/* Location: /bonfire/modules/suppliers/migrations/004_Foreign_keys.php */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment