From 0a1e6a8a449ce21a5bc856052ff4ca8b5672efa5 Mon Sep 17 00:00:00 2001 From: Ian Roth Date: Fri, 26 Nov 2010 22:55:13 -0500 Subject: [PATCH] Add initial Jonah migration scripts Signed-off-by: Michael J. Rubinsky Bug: 9393 Does not include the migration for the tagger changes, since the tagger code still needs work. --- jonah/migration/1_jonah_base_tables.php | 98 +++++++++++++++++++++++ jonah/migration/2_jonah_upgrade_autoincrement.php | 37 +++++++++ 2 files changed, 135 insertions(+) create mode 100644 jonah/migration/1_jonah_base_tables.php create mode 100644 jonah/migration/2_jonah_upgrade_autoincrement.php diff --git a/jonah/migration/1_jonah_base_tables.php b/jonah/migration/1_jonah_base_tables.php new file mode 100644 index 000000000..61c700f8a --- /dev/null +++ b/jonah/migration/1_jonah_base_tables.php @@ -0,0 +1,98 @@ +tables(); + + if (!in_array('jonah_channels', $tableList)) { + $t = $this->createTable('jonah_channels', array('primaryKey' => false)); + $t->column('channel_id', 'integer', array('null' => false)); + $t->column('channel_slug', 'string', array('limit' => 64, 'null' => false)); + $t->column('channel_name', 'string', array('limit' => 255, 'null' => false)); + $t->column('channel_type', 'integer'); + $t->column('channel_full_feed', 'integer', array('null' => false, 'default' => 0)); + $t->column('channel_desc', 'string', array('limit' => 255)); + $t->column('channel_interval', 'integer'); + $t->column('channel_url', 'string', array('limit' => 255)); + $t->column('channel_link', 'string', array('limit' => 255)); + $t->column('channel_page_link', 'string', array('limit' => 255)); + $t->column('channel_story_url', 'string', array('limit' => 255)); + $t->column('channel_img', 'string', array('limit' => 255)); + $t->column('channel_updated', 'integer'); + $t->primaryKey(array('channel_id')); + $t->end(); + + $this->addIndex('jonah_channels', array('channel_type')); + } + + if (!in_array('jonah_stories', $tableList)) { + $t = $this->createTable('jonah_stories', array('primaryKey' => false)); + $t->column('story_id', 'integer', array('null' => false)); + $t->column('channel_id', 'integer', array('null' => false)); + $t->column('story_author', 'string', array('limit' => 255, 'null' => false)); + $t->column('story_title', 'string', array('limit' => 255, 'null' => false)); + $t->column('story_desc', 'text'); + $t->column('story_body_type', 'string', array('limit' => 255, 'null' => false)); + $t->column('story_body', 'text'); + $t->column('story_url', 'string', array('limit' => 255)); + $t->column('story_permalink', 'string', array('limit' => 255)); + $t->column('story_published', 'integer'); + $t->column('story_updated', 'integer', array('null' => false)); + $t->column('story_read', 'integer', array('null' => false)); + $t->primaryKey(array('story_id')); + $t->end(); + + $this->addIndex('jonah_stories', array('channel_id')); + $this->addIndex('jonah_stories', array('story_published')); + $this->addIndex('jonah_stories', array('story_url')); + } + + if (!in_array('jonah_stories_tags', $tableList)) { + $t = $this->createTable('jonah_stories_tags', array('primaryKey' => false)); + $t->column('story_id', 'integer', array('null' => false)); + $t->column('channel_id', 'integer', array('null' => false)); + $t->column('tag_id', 'integer', array('null' => false)); + $t->primaryKey(array('story_id', 'channel_id', 'tag_id')); + $t->end(); + } + + if (!in_array('jonah_tags', $tableList)) { + $t = $this->createTable('jonah_tags', array('primaryKey' => false)); + $t->column('tag_id', 'integer', array('null' => false)); + $t->column('tag_name', 'string', array('limit' => 255, 'null' => false)); + $t->primaryKey(array('tag_id')); + $t->end(); + } + + } + + /** + * Downgrade to 0 + */ + public function down() + { + $this->dropTable('jonah_channels'); + $this->dropTable('jonah_stories'); + $this->dropTable('jonah_stories_tags'); + $this->dropTable('jonah_tags'); + } + +} + diff --git a/jonah/migration/2_jonah_upgrade_autoincrement.php b/jonah/migration/2_jonah_upgrade_autoincrement.php new file mode 100644 index 000000000..f9b5ec6a0 --- /dev/null +++ b/jonah/migration/2_jonah_upgrade_autoincrement.php @@ -0,0 +1,37 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/gpl.html GPL + * @package Jonah + */ +class JonahUpgradeAutoIncrement extends Horde_Db_Migration_Base +{ + /** + * Upgrade. + */ + public function up() + { + $this->changeColumn('jonah_channels', 'channel_id', 'integer', array('default' => null, 'null' => false, 'autoincrement' => true)); + $this->changeColumn('jonah_stories', 'story_id', 'integer', array('default' => null, 'null' => false, 'autoincrement' => true)); + $this->changeColumn('jonah_tags', 'tag_id', 'integer', array('default' => null, 'null' => false, 'autoincrement' => true)); + } + + /** + * Downgrade + */ + public function down() + { + $this->changeColumn('jonah_channels', 'channel_id', 'integer', array('null' => false)); + $this->changeColumn('jonah_stories', 'story_id', 'integer', array('null' => false)); + $this->changeColumn('jonah_tags', 'tag_id', 'integer', array('null' => false)); + } + +} -- 2.11.0