diff --git a/src/Doctrine/AbstractMigration.php b/src/Doctrine/AbstractMigration.php index 811fef6a..5f5e58ae 100644 --- a/src/Doctrine/AbstractMigration.php +++ b/src/Doctrine/AbstractMigration.php @@ -45,7 +45,7 @@ abstract class AbstractMigration extends BaseAbstractMigration implements Contai /** * @param string $name * @return string - * @deprecated since 0.9 + * @deprecated since 0.9 - will be removed with 2.0 */ protected function getTableName($name) { diff --git a/src/Migrations/Version20180701120000.php b/src/Migrations/Version20180701120000.php index 69ecdf0f..a02749fc 100644 --- a/src/Migrations/Version20180701120000.php +++ b/src/Migrations/Version20180701120000.php @@ -22,21 +22,15 @@ final class Version20180701120000 extends AbstractMigration { public function up(Schema $schema): void { - $platform = $this->getPlatform(); + $users = 'kimai2_users'; + $userPreferences = 'kimai2_user_preferences'; + $customers = 'kimai2_customers'; + $projects = 'kimai2_projects'; + $activities = 'kimai2_activities'; + $timesheets = 'kimai2_timesheet'; + $invoiceTemplates = 'kimai2_invoice_templates'; - if (!in_array($platform, ['sqlite', 'mysql'])) { - $this->abortIf(true, 'Unsupported database platform: ' . $platform); - } - - $users = $this->getTableName('users'); - $userPreferences = $this->getTableName('user_preferences'); - $customers = $this->getTableName('customers'); - $projects = $this->getTableName('projects'); - $activities = $this->getTableName('activities'); - $timesheets = $this->getTableName('timesheet'); - $invoiceTemplates = $this->getTableName('invoice_templates'); - - if ($platform === 'sqlite') { + if ($this->isPlatformSqlite()) { $this->addSql('CREATE TABLE ' . $users . ' (id INTEGER NOT NULL, name VARCHAR(60) NOT NULL, mail VARCHAR(160) NOT NULL, password VARCHAR(254) DEFAULT NULL, alias VARCHAR(60) DEFAULT NULL, active BOOLEAN NOT NULL, registration_date DATETIME DEFAULT NULL, title VARCHAR(50) DEFAULT NULL, avatar VARCHAR(255) DEFAULT NULL, roles CLOB NOT NULL --(DC2Type:array) , PRIMARY KEY(id))'); $this->addSql('CREATE UNIQUE INDEX UNIQ_B9AC5BCE5E237E06 ON ' . $users . ' (name)'); @@ -72,26 +66,12 @@ final class Version20180701120000 extends AbstractMigration public function down(Schema $schema): void { - $platform = $this->getPlatform(); - - if (!in_array($platform, ['sqlite', 'mysql'])) { - $this->abortIf(true, 'Unsupported database platform: ' . $platform); - } - - $users = $this->getTableName('users'); - $userPreferences = $this->getTableName('user_preferences'); - $customers = $this->getTableName('customers'); - $projects = $this->getTableName('projects'); - $activities = $this->getTableName('activities'); - $timesheets = $this->getTableName('timesheet'); - $invoiceTemplates = $this->getTableName('invoice_templates'); - - $this->addSql('DROP TABLE ' . $invoiceTemplates); - $this->addSql('DROP TABLE ' . $timesheets); - $this->addSql('DROP TABLE ' . $userPreferences); - $this->addSql('DROP TABLE ' . $users); - $this->addSql('DROP TABLE ' . $activities); - $this->addSql('DROP TABLE ' . $projects); - $this->addSql('DROP TABLE ' . $customers); + $schema->dropTable('kimai2_invoice_templates'); + $schema->dropTable('kimai2_timesheet'); + $schema->dropTable('kimai2_user_preferences'); + $schema->dropTable('kimai2_users'); + $schema->dropTable('kimai2_activities'); + $schema->dropTable('kimai2_projects'); + $schema->dropTable('kimai2_customers'); } } diff --git a/src/Migrations/Version20180715160326.php b/src/Migrations/Version20180715160326.php index e09f91ab..0507e930 100644 --- a/src/Migrations/Version20180715160326.php +++ b/src/Migrations/Version20180715160326.php @@ -37,13 +37,7 @@ final class Version20180715160326 extends AbstractMigration */ public function up(Schema $schema): void { - $platform = $this->getPlatform(); - - if (!in_array($platform, ['sqlite', 'mysql'])) { - $this->abortIf(true, 'Unsupported database platform: ' . $platform); - } - - $users = $this->getTableName('users'); + $users = 'kimai2_users'; // delete all existing indexes $indexesOld = $schema->getTable($users)->getIndexes(); @@ -54,7 +48,7 @@ final class Version20180715160326 extends AbstractMigration } } - if ($platform === 'sqlite') { + if ($this->isPlatformSqlite()) { $this->addSql('CREATE TEMPORARY TABLE __temp__' . $users . ' AS SELECT id, name, mail, password, alias, active, registration_date, title, avatar, roles FROM ' . $users); $this->addSql('DROP TABLE ' . $users); $this->addSql('CREATE TABLE ' . $users . ' (id INTEGER NOT NULL, alias VARCHAR(60) DEFAULT NULL COLLATE BINARY, registration_date DATETIME DEFAULT NULL, title VARCHAR(50) DEFAULT NULL COLLATE BINARY, avatar VARCHAR(255) DEFAULT NULL COLLATE BINARY, enabled BOOLEAN NOT NULL, password VARCHAR(255) NOT NULL, roles CLOB NOT NULL --(DC2Type:array) @@ -87,20 +81,14 @@ final class Version20180715160326 extends AbstractMigration */ public function down(Schema $schema): void { - $platform = $this->getPlatform(); - - if (!in_array($platform, ['sqlite', 'mysql'])) { - $this->abortIf(true, 'Unsupported database platform: ' . $platform); - } - - $users = $this->getTableName('users'); + $users = 'kimai2_users'; $indexToDelete = ['UNIQ_B9AC5BCE92FC23A8', 'UNIQ_B9AC5BCEA0D96FBF', 'UNIQ_B9AC5BCEC05FB297', 'UNIQ_B9AC5BCEF85E0677', 'UNIQ_B9AC5BCEE7927C74']; foreach ($indexToDelete as $index) { $this->addSqlDropIndex($index, $users); } - if ($platform === 'sqlite') { + if ($this->isPlatformSqlite()) { $this->addSql('CREATE TEMPORARY TABLE __temp__' . $users . ' AS SELECT id, username, email, enabled, password, roles, alias, registration_date, title, avatar FROM ' . $users); $this->addSql('DROP TABLE ' . $users); $this->addSql('CREATE TABLE ' . $users . ' (id INTEGER NOT NULL, alias VARCHAR(60) DEFAULT NULL, registration_date DATETIME DEFAULT NULL, title VARCHAR(50) DEFAULT NULL, avatar VARCHAR(255) DEFAULT NULL, active BOOLEAN NOT NULL, password VARCHAR(254) DEFAULT NULL COLLATE BINARY, roles CLOB NOT NULL COLLATE BINARY --(DC2Type:array) diff --git a/src/Migrations/Version20180730044139.php b/src/Migrations/Version20180730044139.php index 4d5fbdba..6059a8ef 100644 --- a/src/Migrations/Version20180730044139.php +++ b/src/Migrations/Version20180730044139.php @@ -33,17 +33,11 @@ final class Version20180730044139 extends AbstractMigration */ public function up(Schema $schema): void { - $platform = $this->getPlatform(); + $timesheet = 'kimai2_timesheet'; + $user = 'kimai2_users'; + $activity = 'kimai2_activities'; - if (!in_array($platform, ['sqlite', 'mysql'])) { - $this->abortIf(true, 'Unsupported database platform: ' . $platform); - } - - $timesheet = $this->getTableName('timesheet'); - $user = $this->getTableName('users'); - $activity = $this->getTableName('activities'); - - if ($platform === 'sqlite') { + if ($this->isPlatformSqlite()) { $this->addSql('DROP INDEX IDX_4F60C6B181C06096'); $this->addSql('DROP INDEX IDX_4F60C6B18D93D649'); $this->addSql('CREATE TEMPORARY TABLE __temp__' . $timesheet . ' AS SELECT id, user, activity_id, start_time, end_time, duration, description, rate FROM ' . $timesheet); @@ -65,16 +59,10 @@ final class Version20180730044139 extends AbstractMigration */ public function down(Schema $schema): void { - $platform = $this->getPlatform(); + $timesheet = 'kimai2_timesheet'; + $user = 'kimai2_users'; - if (!in_array($platform, ['sqlite', 'mysql'])) { - $this->abortIf(true, 'Unsupported database platform: ' . $platform); - } - - $timesheet = $this->getTableName('timesheet'); - $user = $this->getTableName('users'); - - if ($platform === 'sqlite') { + if ($this->isPlatformSqlite()) { $this->addSql('DROP INDEX IDX_4F60C6B18D93D649'); $this->addSql('DROP INDEX IDX_4F60C6B181C06096'); $this->addSql('CREATE TEMPORARY TABLE __temp__' . $timesheet . ' AS SELECT id, user, activity_id, start_time, end_time, duration, description, rate FROM ' . $timesheet); diff --git a/src/Migrations/Version20180805183527.php b/src/Migrations/Version20180805183527.php index 7ac05502..733d8560 100644 --- a/src/Migrations/Version20180805183527.php +++ b/src/Migrations/Version20180805183527.php @@ -25,19 +25,7 @@ final class Version20180805183527 extends AbstractMigration */ public function up(Schema $schema): void { - $platform = $this->getPlatform(); - - if (!in_array($platform, ['sqlite', 'mysql'])) { - $this->abortIf(true, 'Unsupported database platform: ' . $platform); - } - - $user = $this->getTableName('users'); - - if ($platform === 'sqlite') { - $this->addSql('ALTER TABLE ' . $user . ' ADD COLUMN api_token VARCHAR(255) DEFAULT NULL'); - } else { - $this->addSql('ALTER TABLE ' . $user . ' ADD api_token VARCHAR(255) DEFAULT NULL'); - } + $schema->getTable('kimai2_users')->addColumn('api_token', 'string', ['length' => 255, 'notnull' => false, 'default' => null]); } /** @@ -46,32 +34,6 @@ final class Version20180805183527 extends AbstractMigration */ public function down(Schema $schema): void { - $platform = $this->getPlatform(); - - if (!in_array($platform, ['sqlite', 'mysql'])) { - $this->abortIf(true, 'Unsupported database platform: ' . $platform); - } - - $user = $this->getTableName('users'); - - if ($platform === 'sqlite') { - $this->addSql('DROP INDEX UNIQ_B9AC5BCE92FC23A8'); - $this->addSql('DROP INDEX UNIQ_B9AC5BCEA0D96FBF'); - $this->addSql('DROP INDEX UNIQ_B9AC5BCEC05FB297'); - $this->addSql('DROP INDEX UNIQ_B9AC5BCEF85E0677'); - $this->addSql('DROP INDEX UNIQ_B9AC5BCEE7927C74'); - $this->addSql('CREATE TEMPORARY TABLE __temp__' . $user . ' AS SELECT id, username, username_canonical, email, email_canonical, enabled, salt, password, last_login, confirmation_token, password_requested_at, roles, alias, registration_date, title, avatar FROM ' . $user); - $this->addSql('DROP TABLE ' . $user); - $this->addSql('CREATE TABLE ' . $user . ' (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, username VARCHAR(180) NOT NULL, username_canonical VARCHAR(180) NOT NULL, email VARCHAR(180) NOT NULL, email_canonical VARCHAR(180) NOT NULL, enabled BOOLEAN NOT NULL, salt VARCHAR(255) DEFAULT NULL, password VARCHAR(255) NOT NULL, last_login DATETIME DEFAULT NULL, confirmation_token VARCHAR(180) DEFAULT NULL, password_requested_at DATETIME DEFAULT NULL, roles CLOB NOT NULL, alias VARCHAR(60) DEFAULT NULL, registration_date DATETIME DEFAULT NULL, title VARCHAR(50) DEFAULT NULL, avatar VARCHAR(255) DEFAULT NULL)'); - $this->addSql('INSERT INTO ' . $user . ' (id, username, username_canonical, email, email_canonical, enabled, salt, password, last_login, confirmation_token, password_requested_at, roles, alias, registration_date, title, avatar) SELECT id, username, username_canonical, email, email_canonical, enabled, salt, password, last_login, confirmation_token, password_requested_at, roles, alias, registration_date, title, avatar FROM __temp__' . $user); - $this->addSql('DROP TABLE __temp__' . $user); - $this->addSql('CREATE UNIQUE INDEX UNIQ_B9AC5BCE92FC23A8 ON ' . $user . ' (username_canonical)'); - $this->addSql('CREATE UNIQUE INDEX UNIQ_B9AC5BCEA0D96FBF ON ' . $user . ' (email_canonical)'); - $this->addSql('CREATE UNIQUE INDEX UNIQ_B9AC5BCEC05FB297 ON ' . $user . ' (confirmation_token)'); - $this->addSql('CREATE UNIQUE INDEX UNIQ_B9AC5BCEF85E0677 ON ' . $user . ' (username)'); - $this->addSql('CREATE UNIQUE INDEX UNIQ_B9AC5BCEE7927C74 ON ' . $user . ' (email)'); - } else { - $this->addSql('ALTER TABLE ' . $user . ' DROP api_token'); - } + $schema->getTable('kimai2_users')->dropColumn('api_token'); } } diff --git a/src/Migrations/Version20180903202256.php b/src/Migrations/Version20180903202256.php index f851ac19..172ccbef 100644 --- a/src/Migrations/Version20180903202256.php +++ b/src/Migrations/Version20180903202256.php @@ -21,41 +21,15 @@ final class Version20180903202256 extends AbstractMigration { public function up(Schema $schema): void { - $platform = $this->getPlatform(); - - if (!in_array($platform, ['sqlite', 'mysql'])) { - $this->abortIf(true, 'Unsupported database platform: ' . $platform); - } - - $timesheet = $this->getTableName('timesheet'); - - $this->addSql('ALTER TABLE ' . $timesheet . ' ADD COLUMN fixed_rate NUMERIC(10, 2) DEFAULT NULL'); - $this->addSql('ALTER TABLE ' . $timesheet . ' ADD COLUMN hourly_rate NUMERIC(10, 2) DEFAULT NULL'); + $this->addSql('ALTER TABLE kimai2_timesheet ADD COLUMN fixed_rate NUMERIC(10, 2) DEFAULT NULL'); + $this->addSql('ALTER TABLE kimai2_timesheet ADD COLUMN hourly_rate NUMERIC(10, 2) DEFAULT NULL'); } public function down(Schema $schema): void { - $platform = $this->getPlatform(); + $timesheet = $schema->getTable('kimai2_timesheet'); - if (!in_array($platform, ['sqlite', 'mysql'])) { - $this->abortIf(true, 'Unsupported database platform: ' . $platform); - } - - $timesheet = $this->getTableName('timesheet'); - - if ($platform === 'sqlite') { - $this->addSql('DROP INDEX IDX_4F60C6B18D93D649'); - $this->addSql('DROP INDEX IDX_4F60C6B181C06096'); - $this->addSql('CREATE TEMPORARY TABLE __temp__' . $timesheet . ' AS SELECT id, user, activity_id, start_time, end_time, duration, description, rate FROM ' . $timesheet); - $this->addSql('DROP TABLE ' . $timesheet); - $this->addSql('CREATE TABLE ' . $timesheet . ' (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, user INTEGER DEFAULT NULL, activity_id INTEGER DEFAULT NULL, start_time DATETIME NOT NULL, end_time DATETIME DEFAULT NULL, duration INTEGER DEFAULT NULL, description CLOB DEFAULT NULL, rate NUMERIC(10, 2) NOT NULL)'); - $this->addSql('INSERT INTO ' . $timesheet . ' (id, user, activity_id, start_time, end_time, duration, description, rate) SELECT id, user, activity_id, start_time, end_time, duration, description, rate FROM __temp__' . $timesheet); - $this->addSql('DROP TABLE __temp__' . $timesheet); - $this->addSql('CREATE INDEX IDX_4F60C6B18D93D649 ON ' . $timesheet . ' (user)'); - $this->addSql('CREATE INDEX IDX_4F60C6B181C06096 ON ' . $timesheet . ' (activity_id)'); - } else { - $this->addSql('ALTER TABLE ' . $timesheet . ' DROP hourly_rate'); - $this->addSql('ALTER TABLE ' . $timesheet . ' DROP fixed_rate'); - } + $timesheet->dropColumn('hourly_rate'); + $timesheet->dropColumn('fixed_rate'); } } diff --git a/src/Migrations/Version20180905190737.php b/src/Migrations/Version20180905190737.php index f4680293..2b4efd52 100644 --- a/src/Migrations/Version20180905190737.php +++ b/src/Migrations/Version20180905190737.php @@ -24,67 +24,28 @@ final class Version20180905190737 extends AbstractMigration { public function up(Schema $schema): void { - $platform = $this->getPlatform(); + $this->addSql('ALTER TABLE kimai2_activities ADD COLUMN fixed_rate NUMERIC(10, 2) DEFAULT NULL'); + $this->addSql('ALTER TABLE kimai2_activities ADD COLUMN hourly_rate NUMERIC(10, 2) DEFAULT NULL'); - if (!in_array($platform, ['sqlite', 'mysql'])) { - $this->abortIf(true, 'Unsupported database platform: ' . $platform); - } + $this->addSql('ALTER TABLE kimai2_projects ADD COLUMN fixed_rate NUMERIC(10, 2) DEFAULT NULL'); + $this->addSql('ALTER TABLE kimai2_projects ADD COLUMN hourly_rate NUMERIC(10, 2) DEFAULT NULL'); - $activity = $this->getTableName('activities'); - $project = $this->getTableName('projects'); - $customer = $this->getTableName('customers'); - - $this->addSql('ALTER TABLE ' . $activity . ' ADD COLUMN fixed_rate NUMERIC(10, 2) DEFAULT NULL'); - $this->addSql('ALTER TABLE ' . $activity . ' ADD COLUMN hourly_rate NUMERIC(10, 2) DEFAULT NULL'); - - $this->addSql('ALTER TABLE ' . $project . ' ADD COLUMN fixed_rate NUMERIC(10, 2) DEFAULT NULL'); - $this->addSql('ALTER TABLE ' . $project . ' ADD COLUMN hourly_rate NUMERIC(10, 2) DEFAULT NULL'); - - $this->addSql('ALTER TABLE ' . $customer . ' ADD COLUMN fixed_rate NUMERIC(10, 2) DEFAULT NULL'); - $this->addSql('ALTER TABLE ' . $customer . ' ADD COLUMN hourly_rate NUMERIC(10, 2) DEFAULT NULL'); + $this->addSql('ALTER TABLE kimai2_customers ADD COLUMN fixed_rate NUMERIC(10, 2) DEFAULT NULL'); + $this->addSql('ALTER TABLE kimai2_customers ADD COLUMN hourly_rate NUMERIC(10, 2) DEFAULT NULL'); } public function down(Schema $schema): void { - $platform = $this->getPlatform(); + $customer = $schema->getTable('kimai2_customers'); + $customer->dropColumn('hourly_rate'); + $customer->dropColumn('fixed_rate'); - if (!in_array($platform, ['sqlite', 'mysql'])) { - $this->abortIf(true, 'Unsupported database platform: ' . $platform); - } + $project = $schema->getTable('kimai2_projects'); + $project->dropColumn('hourly_rate'); + $project->dropColumn('fixed_rate'); - $activity = $this->getTableName('activities'); - $project = $this->getTableName('projects'); - $customer = $this->getTableName('customers'); - - if ($platform === 'sqlite') { - $this->addSql('CREATE TEMPORARY TABLE __temp__' . $customer . ' AS SELECT id, name, number, comment, visible, company, contact, address, country, currency, phone, fax, mobile, mail, homepage, timezone FROM ' . $customer); - $this->addSql('DROP TABLE ' . $customer); - $this->addSql('CREATE TABLE ' . $customer . ' (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name VARCHAR(255) NOT NULL, number VARCHAR(50) DEFAULT NULL, comment CLOB DEFAULT NULL, visible BOOLEAN NOT NULL, company VARCHAR(255) DEFAULT NULL, contact VARCHAR(255) DEFAULT NULL, address CLOB DEFAULT NULL, country VARCHAR(2) NOT NULL, currency VARCHAR(3) NOT NULL, phone VARCHAR(255) DEFAULT NULL, fax VARCHAR(255) DEFAULT NULL, mobile VARCHAR(255) DEFAULT NULL, mail VARCHAR(255) DEFAULT NULL, homepage VARCHAR(255) DEFAULT NULL, timezone VARCHAR(255) NOT NULL)'); - $this->addSql('INSERT INTO ' . $customer . ' (id, name, number, comment, visible, company, contact, address, country, currency, phone, fax, mobile, mail, homepage, timezone) SELECT id, name, number, comment, visible, company, contact, address, country, currency, phone, fax, mobile, mail, homepage, timezone FROM __temp__' . $customer); - $this->addSql('DROP TABLE __temp__' . $customer); - - $this->addSql('DROP INDEX IDX_407F12069395C3F3'); - $this->addSql('CREATE TEMPORARY TABLE __temp__' . $project . ' AS SELECT id, customer_id, name, order_number, comment, visible, budget FROM ' . $project); - $this->addSql('DROP TABLE ' . $project); - $this->addSql('CREATE TABLE ' . $project . ' (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, customer_id INTEGER DEFAULT NULL, name VARCHAR(255) NOT NULL, order_number CLOB DEFAULT NULL, comment CLOB DEFAULT NULL, visible BOOLEAN NOT NULL, budget NUMERIC(10, 2) NOT NULL)'); - $this->addSql('INSERT INTO ' . $project . ' (id, customer_id, name, order_number, comment, visible, budget) SELECT id, customer_id, name, order_number, comment, visible, budget FROM __temp__' . $project); - $this->addSql('DROP TABLE __temp__' . $project); - $this->addSql('CREATE INDEX IDX_407F12069395C3F3 ON ' . $project . ' (customer_id)'); - - $this->addSql('DROP INDEX IDX_8811FE1C166D1F9C'); - $this->addSql('CREATE TEMPORARY TABLE __temp__' . $activity . ' AS SELECT id, project_id, name, comment, visible FROM ' . $activity); - $this->addSql('DROP TABLE ' . $activity); - $this->addSql('CREATE TABLE ' . $activity . ' (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, project_id INTEGER DEFAULT NULL, name VARCHAR(255) NOT NULL, comment CLOB DEFAULT NULL, visible BOOLEAN NOT NULL)'); - $this->addSql('INSERT INTO ' . $activity . ' (id, project_id, name, comment, visible) SELECT id, project_id, name, comment, visible FROM __temp__' . $activity); - $this->addSql('DROP TABLE __temp__' . $activity); - $this->addSql('CREATE INDEX IDX_8811FE1C166D1F9C ON ' . $activity . ' (project_id)'); - } else { - $this->addSql('ALTER TABLE ' . $customer . ' DROP hourly_rate'); - $this->addSql('ALTER TABLE ' . $customer . ' DROP fixed_rate'); - $this->addSql('ALTER TABLE ' . $project . ' DROP hourly_rate'); - $this->addSql('ALTER TABLE ' . $project . ' DROP fixed_rate'); - $this->addSql('ALTER TABLE ' . $activity . ' DROP hourly_rate'); - $this->addSql('ALTER TABLE ' . $activity . ' DROP fixed_rate'); - } + $activity = $schema->getTable('kimai2_activities'); + $activity->dropColumn('hourly_rate'); + $activity->dropColumn('fixed_rate'); } } diff --git a/src/Migrations/Version20180924111853.php b/src/Migrations/Version20180924111853.php index 7e782681..2efc268a 100644 --- a/src/Migrations/Version20180924111853.php +++ b/src/Migrations/Version20180924111853.php @@ -23,15 +23,9 @@ final class Version20180924111853 extends AbstractMigration { public function up(Schema $schema): void { - $platform = $this->getPlatform(); + $invoiceTemplates = 'kimai2_invoice_templates'; - if (!in_array($platform, ['sqlite', 'mysql'])) { - $this->abortIf(true, 'Unsupported database platform: ' . $platform); - } - - $invoiceTemplates = $this->getTableName('invoice_templates'); - - if ($platform === 'sqlite') { + if ($this->isPlatformSqlite()) { $this->addSql('UPDATE ' . $invoiceTemplates . ' SET name=substr(name, 1, 60)'); $this->addSql('DROP INDEX UNIQ_1626CFE95E237E06'); $this->addSql('CREATE TEMPORARY TABLE __temp__' . $invoiceTemplates . ' AS SELECT id, name, title, company, address, due_days, vat, calculator, number_generator, renderer, payment_terms FROM ' . $invoiceTemplates); @@ -48,15 +42,9 @@ final class Version20180924111853 extends AbstractMigration public function down(Schema $schema): void { - $platform = $this->getPlatform(); + $invoiceTemplates = 'kimai2_invoice_templates'; - if (!in_array($platform, ['sqlite', 'mysql'])) { - $this->abortIf(true, 'Unsupported database platform: ' . $platform); - } - - $invoiceTemplates = $this->getTableName('invoice_templates'); - - if ($platform === 'sqlite') { + if ($this->isPlatformSqlite()) { $this->addSql('DROP INDEX UNIQ_1626CFE95E237E06'); $this->addSql('CREATE TEMPORARY TABLE __temp__' . $invoiceTemplates . ' AS SELECT id, name, title, company, address, due_days, vat, calculator, number_generator, renderer, payment_terms FROM ' . $invoiceTemplates); $this->addSql('DROP TABLE ' . $invoiceTemplates); diff --git a/src/Migrations/Version20181031220003.php b/src/Migrations/Version20181031220003.php index fbf69515..18cfabc1 100644 --- a/src/Migrations/Version20181031220003.php +++ b/src/Migrations/Version20181031220003.php @@ -22,19 +22,13 @@ final class Version20181031220003 extends AbstractMigration { public function up(Schema $schema): void { - $platform = $this->getPlatform(); + $timesheet = 'kimai2_timesheet'; + $projects = 'kimai2_projects'; + $activities = 'kimai2_activities'; + $users = 'kimai2_users'; + $customers = 'kimai2_customers'; - if (!in_array($platform, ['sqlite', 'mysql'])) { - $this->abortIf(true, 'Unsupported database platform: ' . $platform); - } - - $timesheet = $this->getTableName('timesheet'); - $projects = $this->getTableName('projects'); - $activities = $this->getTableName('activities'); - $users = $this->getTableName('users'); - $customers = $this->getTableName('customers'); - - if ($platform === 'sqlite') { + if ($this->isPlatformSqlite()) { // project table $this->addSql('DROP INDEX IDX_407F12069395C3F3'); $this->addSql('CREATE TEMPORARY TABLE __temp__' . $projects . ' AS SELECT id, customer_id, name, order_number, comment, visible, budget, fixed_rate, hourly_rate FROM ' . $projects); @@ -68,7 +62,7 @@ final class Version20181031220003 extends AbstractMigration $this->addSql('UPDATE ' . $timesheet . ' SET project_id = (SELECT project_id FROM ' . $activities . ' WHERE id = activity_id)'); // now update the timesheet table and disallow null values for all required columns (that was a bug before) - if ($platform === 'sqlite') { + if ($this->isPlatformSqlite()) { $this->addSql('DROP INDEX IDX_4F60C6B181C06096'); $this->addSql('DROP INDEX IDX_4F60C6B18D93D649'); $this->addSql('DROP INDEX IDX_4F60C6B1166D1F9C'); @@ -92,17 +86,11 @@ final class Version20181031220003 extends AbstractMigration public function down(Schema $schema): void { - $platform = $this->getPlatform(); + $timesheet = 'kimai2_timesheet'; + $projects = 'kimai2_projects'; + $customers = 'kimai2_customers'; - if (!in_array($platform, ['sqlite', 'mysql'])) { - $this->abortIf(true, 'Unsupported database platform: ' . $platform); - } - - $timesheet = $this->getTableName('timesheet'); - $projects = $this->getTableName('projects'); - $customers = $this->getTableName('customers'); - - if ($platform === 'sqlite') { + if ($this->isPlatformSqlite()) { // project table $this->addSql('DROP INDEX IDX_407F12069395C3F3'); $this->addSql('CREATE TEMPORARY TABLE __temp__' . $projects . ' AS SELECT id, customer_id, name, order_number, comment, visible, budget, fixed_rate, hourly_rate FROM ' . $projects); diff --git a/src/Migrations/Version20190124004014.php b/src/Migrations/Version20190124004014.php index 0cbae3b9..2074aaac 100644 --- a/src/Migrations/Version20190124004014.php +++ b/src/Migrations/Version20190124004014.php @@ -23,45 +23,11 @@ final class Version20190124004014 extends AbstractMigration { public function up(Schema $schema): void { - $platform = $this->getPlatform(); - - if (!in_array($platform, ['sqlite', 'mysql'])) { - $this->abortIf(true, 'Unsupported database platform: ' . $platform); - } - - $timesheet = $this->getTableName('timesheet'); - - if ($platform === 'sqlite') { - $this->addSql('ALTER TABLE ' . $timesheet . ' ADD COLUMN exported BOOLEAN NOT NULL DEFAULT false'); - } else { - $this->addSql('ALTER TABLE ' . $timesheet . ' ADD exported TINYINT(1) NOT NULL DEFAULT false'); - } + $schema->getTable('kimai2_timesheet')->addColumn('exported', 'boolean', ['notnull' => true, 'default' => false]); } public function down(Schema $schema): void { - $platform = $this->getPlatform(); - - if (!in_array($platform, ['sqlite', 'mysql'])) { - $this->abortIf(true, 'Unsupported database platform: ' . $platform); - } - - $timesheet = $this->getTableName('timesheet'); - - if ($platform === 'sqlite') { - $this->addSql('DROP INDEX IDX_4F60C6B1166D1F9C'); - $this->addSql('DROP INDEX IDX_4F60C6B18D93D649'); - $this->addSql('DROP INDEX IDX_4F60C6B181C06096'); - $this->addSql('CREATE TEMPORARY TABLE __temp__' . $timesheet . ' AS SELECT id, user, activity_id, project_id, start_time, end_time, duration, description, rate, fixed_rate, hourly_rate FROM ' . $timesheet); - $this->addSql('DROP TABLE ' . $timesheet); - $this->addSql('CREATE TABLE ' . $timesheet . ' (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, user INTEGER NOT NULL, activity_id INTEGER NOT NULL, project_id INTEGER NOT NULL, start_time DATETIME NOT NULL, end_time DATETIME DEFAULT NULL, duration INTEGER DEFAULT NULL, description CLOB DEFAULT NULL, rate NUMERIC(10, 2) NOT NULL, fixed_rate NUMERIC(10, 2) DEFAULT NULL, hourly_rate NUMERIC(10, 2) DEFAULT NULL)'); - $this->addSql('INSERT INTO ' . $timesheet . ' (id, user, activity_id, project_id, start_time, end_time, duration, description, rate, fixed_rate, hourly_rate) SELECT id, user, activity_id, project_id, start_time, end_time, duration, description, rate, fixed_rate, hourly_rate FROM __temp__' . $timesheet); - $this->addSql('DROP TABLE __temp__' . $timesheet); - $this->addSql('CREATE INDEX IDX_4F60C6B1166D1F9C ON ' . $timesheet . ' (project_id)'); - $this->addSql('CREATE INDEX IDX_4F60C6B18D93D649 ON ' . $timesheet . ' (user)'); - $this->addSql('CREATE INDEX IDX_4F60C6B181C06096 ON ' . $timesheet . ' (activity_id)'); - } else { - $this->addSql('ALTER TABLE ' . $timesheet . ' DROP exported'); - } + $schema->getTable('kimai2_timesheet')->dropColumn('exported'); } } diff --git a/src/Migrations/Version20190201150324.php b/src/Migrations/Version20190201150324.php index 5ab586bb..876bdb0a 100644 --- a/src/Migrations/Version20190201150324.php +++ b/src/Migrations/Version20190201150324.php @@ -24,50 +24,19 @@ final class Version20190201150324 extends AbstractMigration { public function up(Schema $schema): void { - $platform = $this->getPlatform(); - - if (!in_array($platform, ['sqlite', 'mysql'])) { - $this->abortIf(true, 'Unsupported database platform: ' . $platform); - } - - $timesheet = $this->getTableName('timesheet'); $timezone = date_default_timezone_get(); - if ($platform === 'sqlite') { - $this->addSql('ALTER TABLE ' . $timesheet . ' ADD COLUMN timezone VARCHAR(64) DEFAULT NULL'); + if ($this->isPlatformSqlite()) { + $this->addSql('ALTER TABLE kimai2_timesheet ADD COLUMN timezone VARCHAR(64) DEFAULT NULL'); } else { - $this->addSql('ALTER TABLE ' . $timesheet . ' ADD timezone VARCHAR(64) NOT NULL'); + $this->addSql('ALTER TABLE kimai2_timesheet ADD timezone VARCHAR(64) NOT NULL'); } - $this->addSql('UPDATE ' . $timesheet . ' SET timezone = "' . $timezone . '"'); + $this->addSql('UPDATE kimai2_timesheet SET timezone = "' . $timezone . '"'); } public function down(Schema $schema): void { - $platform = $this->getPlatform(); - - if (!in_array($platform, ['sqlite', 'mysql'])) { - $this->abortIf(true, 'Unsupported database platform: ' . $platform); - } - - $timesheet = $this->getTableName('timesheet'); - - if ($platform === 'sqlite') { - $this->addSql('DROP INDEX IDX_4F60C6B1166D1F9C'); - $this->addSql('DROP INDEX IDX_4F60C6B18D93D649'); - $this->addSql('DROP INDEX IDX_4F60C6B181C06096'); - $this->addSql('CREATE TEMPORARY TABLE __temp__' . $timesheet . ' AS SELECT id, user, activity_id, project_id, start_time, end_time, duration, description, rate, fixed_rate, hourly_rate, exported FROM ' . $timesheet); - $this->addSql('DROP TABLE ' . $timesheet); - $this->addSql('CREATE TABLE ' . $timesheet . ' (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, user INTEGER NOT NULL, activity_id INTEGER NOT NULL, project_id INTEGER NOT NULL, start_time DATETIME NOT NULL --(DC2Type:datetime) - , end_time DATETIME DEFAULT NULL --(DC2Type:datetime) - , duration INTEGER DEFAULT NULL, description CLOB DEFAULT NULL, rate NUMERIC(10, 2) NOT NULL, fixed_rate NUMERIC(10, 2) DEFAULT NULL, hourly_rate NUMERIC(10, 2) DEFAULT NULL, exported BOOLEAN NOT NULL DEFAULT false)'); - $this->addSql('INSERT INTO ' . $timesheet . ' (id, user, activity_id, project_id, start_time, end_time, duration, description, rate, fixed_rate, hourly_rate, exported) SELECT id, user, activity_id, project_id, start_time, end_time, duration, description, rate, fixed_rate, hourly_rate, exported FROM __temp__' . $timesheet); - $this->addSql('DROP TABLE __temp__' . $timesheet); - $this->addSql('CREATE INDEX IDX_4F60C6B1166D1F9C ON ' . $timesheet . ' (project_id)'); - $this->addSql('CREATE INDEX IDX_4F60C6B18D93D649 ON ' . $timesheet . ' (user)'); - $this->addSql('CREATE INDEX IDX_4F60C6B181C06096 ON ' . $timesheet . ' (activity_id)'); - } else { - $this->addSql('ALTER TABLE ' . $timesheet . ' DROP timezone'); - } + $schema->getTable('kimai2_timesheet')->dropColumn('timezone'); } } diff --git a/src/Migrations/Version20190219200020.php b/src/Migrations/Version20190219200020.php index 5a1d0e55..1ae375a5 100644 --- a/src/Migrations/Version20190219200020.php +++ b/src/Migrations/Version20190219200020.php @@ -23,17 +23,9 @@ final class Version20190219200020 extends AbstractMigration { public function up(Schema $schema): void { - $platform = $this->getPlatform(); - - if (!in_array($platform, ['sqlite', 'mysql'])) { - $this->abortIf(true, 'Unsupported database platform: ' . $platform); - } - - $userPrefs = $this->getTableName('user_preferences'); - - $this->addSql('DELETE FROM ' . $userPrefs . ' WHERE name = "theme.fixed_layout"'); - $this->addSql('DELETE FROM ' . $userPrefs . ' WHERE name = "theme.boxed_layout"'); - $this->addSql('DELETE FROM ' . $userPrefs . ' WHERE name = "theme.mini_sidebar"'); + $this->addSql('DELETE FROM kimai2_user_preferences WHERE name = "theme.fixed_layout"'); + $this->addSql('DELETE FROM kimai2_user_preferences WHERE name = "theme.boxed_layout"'); + $this->addSql('DELETE FROM kimai2_user_preferences WHERE name = "theme.mini_sidebar"'); } public function down(Schema $schema): void diff --git a/src/Migrations/Version20190305152308.php b/src/Migrations/Version20190305152308.php index 3086ae3d..02f7e267 100644 --- a/src/Migrations/Version20190305152308.php +++ b/src/Migrations/Version20190305152308.php @@ -26,11 +26,11 @@ final class Version20190305152308 extends AbstractMigration { public function up(Schema $schema): void { - $customers = $this->getTableName('customers'); - $projects = $this->getTableName('projects'); - $activities = $this->getTableName('activities'); - $timesheet = $this->getTableName('timesheet'); - $users = $this->getTableName('users'); + $customers = 'kimai2_customers'; + $projects = 'kimai2_projects'; + $activities = 'kimai2_activities'; + $timesheet = 'kimai2_timesheet'; + $users = 'kimai2_users'; if ($this->isPlatformSqlite()) { // first backup of ALL tables @@ -84,10 +84,10 @@ final class Version20190305152308 extends AbstractMigration public function down(Schema $schema): void { - $customers = $this->getTableName('customers'); - $projects = $this->getTableName('projects'); - $activities = $this->getTableName('activities'); - $timesheet = $this->getTableName('timesheet'); + $customers = 'kimai2_customers'; + $projects = 'kimai2_projects'; + $activities = 'kimai2_activities'; + $timesheet = 'kimai2_timesheet'; if ($this->isPlatformSqlite()) { // first backup of ALL tables diff --git a/src/Migrations/Version20190321181243.php b/src/Migrations/Version20190321181243.php index dc8e9e28..9add572e 100644 --- a/src/Migrations/Version20190321181243.php +++ b/src/Migrations/Version20190321181243.php @@ -38,6 +38,6 @@ final class Version20190321181243 extends AbstractMigration public function down(Schema $schema): void { - $this->addSql('DROP TABLE kimai2_configuration'); + $schema->dropTable('kimai2_configuration'); } }