Skip to content

Commit

Permalink
[db] Add migration of bb_bt_users_dl_status (hurtom#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
yukoff committed Aug 20, 2017
1 parent b7fb179 commit c170cd0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
5 changes: 5 additions & 0 deletions database/entities/Database/Entities/BbBtDlstatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class BbBtDlstatus
*/
private $userStatus = '0';

/**
* @var integer
*/
private $complCount = '0';

/**
* @var \DateTime
*/
Expand Down
7 changes: 7 additions & 0 deletions database/mappings/Database.Entities.BbBtDlstatus.dcm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ Database\Entities\BbBtDlstatus:
options:
default: '0'
column: user_status
complCount:
type: smallint
nullable: false
options:
unsigned: true
default: '0'
column: compl_count
lastModifiedDlstatus:
type: datetime
nullable: false
Expand Down
43 changes: 33 additions & 10 deletions database/migrations/Version20170601000000.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public function up(Schema $schema)
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');

/*
* add new tables
*/
/******************
* Add new tables
******************/

// bb_ads
$this->addSql('CREATE TABLE bb_ads (
Expand All @@ -57,11 +57,12 @@ public function up(Schema $schema)
PRIMARY KEY(user_id, forum_id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');

// bb_bt_dlstatus
// bb_bt_dlstatus, migration of old data later on
$this->addSql('CREATE TABLE bb_bt_dlstatus (
user_id INT NOT NULL,
topic_id INT UNSIGNED NOT NULL,
user_status SMALLINT DEFAULT 0 NOT NULL,
compl_count SMALLINT UNSIGNED NOT NULL DEFAULT 0,
last_modified_dlstatus DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,
INDEX topic_id (topic_id),
PRIMARY KEY(user_id, topic_id)
Expand Down Expand Up @@ -257,6 +258,10 @@ public function up(Schema $schema)
PRIMARY KEY(topic_id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');

/******************
* Drop old tables
******************/

/**
* bb_bt_config
* @see https://github.com/hurtom/toloka/issues/95
Expand All @@ -277,8 +282,6 @@ public function up(Schema $schema)
$this->addSql('DROP TABLE bb_bt_torrents_del');
$this->addSql('DROP TRIGGER IF EXISTS bb_topics_au');

$this->addSql('DROP TABLE bb_bt_users_dl_status');

/**
* bb_confirm
* @see https://github.com/hurtom/toloka/issues/98
Expand Down Expand Up @@ -347,9 +350,9 @@ public function up(Schema $schema)
*/
$this->addSql('DROP TABLE bb_topics_move');

/*
* modify tables
*/
/******************
* Modify tables
******************/

// bb_attachments
$this->addSql('DROP INDEX attach_id_post_id ON bb_attachments');
Expand Down Expand Up @@ -664,7 +667,27 @@ public function up(Schema $schema)
$this->addSql('CREATE INDEX topic_id ON bb_posts (topic_id)');
$this->addSql('CREATE INDEX forum_id_post_time ON bb_posts (forum_id, post_time)');

// bb_posts_edit
/**
* bb_bt_users_dl_status migration to bb_bt_dlstatus
* @see https://github.com/hurtom/toloka/issues/97
*/
$this->addSql('
INSERT INTO bb_bt_dlstatus
(user_id, topic_id, user_status, compl_count, last_modified_dlstatus)
SELECT
user_id,
topic_id,
user_status,
compl_count,
FROM_UNIXTIME(update_time)
FROM bb_bt_users_dl_status
');
$this->addSql('DROP TABLE bb_bt_users_dl_status');

/**
* bb_posts_edit
* @see https://github.com/hurtom/toloka/issues/40
*/
$this->addSql('ALTER TABLE bb_posts_edit
CHANGE post_id post_id INT UNSIGNED NOT NULL,
ADD PRIMARY KEY (post_id),
Expand Down

0 comments on commit c170cd0

Please sign in to comment.