Created
May 26, 2015 15:34
-
-
Save jschroed91/a623901474bda70e0b67 to your computer and use it in GitHub Desktop.
Example migration
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
public function preUp(Schema $schema) | |
{ | |
parent::preUp($schema); | |
$this->addSql("CREATE TABLE cdp_timeline_link (id INT AUTO_INCREMENT NOT NULL, timeline_id INT DEFAULT NULL, action_button_text VARCHAR(50) NOT NULL, action_button_link VARCHAR(1024) NOT NULL, INDEX IDX_4BF3B3F6EDBEDD37 (timeline_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"); | |
$this->addSql("ALTER TABLE cdp_timeline_link ADD CONSTRAINT FK_4BF3B3F6EDBEDD37 FOREIGN KEY (timeline_id) REFERENCES cdp_timeline (id) ON DELETE CASCADE"); | |
} | |
public function up(Schema $schema) | |
{ | |
parent::up($schema); | |
$sql = 'SELECT id, action_button_text, action_button_link FROM cdp_timeline'; | |
/* @var $stmt \Doctrine\DBAL\Statement */ | |
$stmt = $this->executeQuery($sql, array(), array(), false); | |
$section = ''; | |
$title = ''; | |
$results = $stmt->fetchAll(); | |
if ($stmt->rowCount() > 0) { | |
$row = $stmt->fetch(); | |
$keys = array_keys($row); | |
$section = $row[$keys[0]]; | |
$title = $row[$keys[1]]; | |
} | |
return array('section' => $section, 'title' => $title); | |
} | |
public function postUp(Schema $schema) | |
{ | |
parent::postUp($schema); | |
$this->addSql("ALTER TABLE cdp_timeline DROP action_button_text, DROP action_button_link"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment