Update migrations so you can always roll back.

This commit is contained in:
James Cole 2019-03-02 15:54:24 +01:00
parent 3a57e09447
commit b7f0a6fff4
24 changed files with 184 additions and 64 deletions

View File

@ -31,7 +31,7 @@ class CreateSupportTables extends Migration
/** /**
* Reverse the migrations. * Reverse the migrations.
*/ */
public function down() public function down(): void
{ {
Schema::drop('account_types'); Schema::drop('account_types');
Schema::drop('transaction_currencies'); Schema::drop('transaction_currencies');
@ -50,7 +50,7 @@ class CreateSupportTables extends Migration
* *
* @SuppressWarnings(PHPMD.ShortMethodName) * @SuppressWarnings(PHPMD.ShortMethodName)
*/ */
public function up() public function up(): void
{ {
$this->createAccountTypeTable(); $this->createAccountTypeTable();
$this->createCurrencyTable(); $this->createCurrencyTable();
@ -67,7 +67,7 @@ class CreateSupportTables extends Migration
/** /**
* *
*/ */
private function createAccountTypeTable() private function createAccountTypeTable(): void
{ {
if (!Schema::hasTable('account_types')) { if (!Schema::hasTable('account_types')) {
Schema::create( Schema::create(
@ -84,7 +84,7 @@ class CreateSupportTables extends Migration
} }
} }
private function createConfigurationTable() private function createConfigurationTable(): void
{ {
if (!Schema::hasTable('configuration')) { if (!Schema::hasTable('configuration')) {
Schema::create( Schema::create(
@ -104,7 +104,7 @@ class CreateSupportTables extends Migration
/** /**
* *
*/ */
private function createCurrencyTable() private function createCurrencyTable(): void
{ {
if (!Schema::hasTable('transaction_currencies')) { if (!Schema::hasTable('transaction_currencies')) {
Schema::create( Schema::create(
@ -127,7 +127,7 @@ class CreateSupportTables extends Migration
/** /**
* *
*/ */
private function createJobsTable() private function createJobsTable(): void
{ {
if (!Schema::hasTable('jobs')) { if (!Schema::hasTable('jobs')) {
Schema::create( Schema::create(
@ -151,7 +151,7 @@ class CreateSupportTables extends Migration
/** /**
* *
*/ */
private function createPasswordTable() private function createPasswordTable(): void
{ {
if (!Schema::hasTable('password_resets')) { if (!Schema::hasTable('password_resets')) {
Schema::create( Schema::create(
@ -169,7 +169,7 @@ class CreateSupportTables extends Migration
/** /**
* *
*/ */
private function createPermissionRoleTable() private function createPermissionRoleTable(): void
{ {
if (!Schema::hasTable('permission_role')) { if (!Schema::hasTable('permission_role')) {
Schema::create( Schema::create(
@ -190,7 +190,7 @@ class CreateSupportTables extends Migration
/** /**
* *
*/ */
private function createPermissionsTable() private function createPermissionsTable(): void
{ {
if (!Schema::hasTable('permissions')) { if (!Schema::hasTable('permissions')) {
Schema::create( Schema::create(
@ -209,7 +209,7 @@ class CreateSupportTables extends Migration
/** /**
* *
*/ */
private function createRolesTable() private function createRolesTable(): void
{ {
if (!Schema::hasTable('roles')) { if (!Schema::hasTable('roles')) {
Schema::create( Schema::create(
@ -228,7 +228,7 @@ class CreateSupportTables extends Migration
/** /**
* *
*/ */
private function createSessionsTable() private function createSessionsTable(): void
{ {
if (!Schema::hasTable('sessions')) { if (!Schema::hasTable('sessions')) {
Schema::create( Schema::create(
@ -248,7 +248,7 @@ class CreateSupportTables extends Migration
/** /**
* *
*/ */
private function createTransactionTypeTable() private function createTransactionTypeTable(): void
{ {
if (!Schema::hasTable('transaction_types')) { if (!Schema::hasTable('transaction_types')) {
Schema::create( Schema::create(

View File

@ -31,7 +31,7 @@ class CreateUsersTable extends Migration
/** /**
* Reverse the migrations. * Reverse the migrations.
*/ */
public function down() public function down(): void
{ {
Schema::drop('users'); Schema::drop('users');
} }
@ -41,7 +41,7 @@ class CreateUsersTable extends Migration
* *
* @SuppressWarnings(PHPMD.ShortMethodName) * @SuppressWarnings(PHPMD.ShortMethodName)
*/ */
public function up() public function up(): void
{ {
if (!Schema::hasTable('users')) { if (!Schema::hasTable('users')) {
Schema::create( Schema::create(

View File

@ -31,7 +31,7 @@ class CreateMainTables extends Migration
/** /**
* Reverse the migrations. * Reverse the migrations.
*/ */
public function down() public function down(): void
{ {
Schema::drop('account_meta'); Schema::drop('account_meta');
Schema::drop('piggy_bank_repetitions'); Schema::drop('piggy_bank_repetitions');
@ -68,7 +68,7 @@ class CreateMainTables extends Migration
* *
* @SuppressWarnings(PHPMD.ShortMethodName) * @SuppressWarnings(PHPMD.ShortMethodName)
*/ */
public function up() public function up(): void
{ {
$this->createAccountTables(); $this->createAccountTables();
$this->createPiggyBanksTable(); $this->createPiggyBanksTable();
@ -87,7 +87,7 @@ class CreateMainTables extends Migration
/** /**
* *
*/ */
private function createAccountTables() private function createAccountTables(): void
{ {
if (!Schema::hasTable('accounts')) { if (!Schema::hasTable('accounts')) {
Schema::create( Schema::create(
@ -127,7 +127,7 @@ class CreateMainTables extends Migration
/** /**
* *
*/ */
private function createAttachmentsTable() private function createAttachmentsTable(): void
{ {
if (!Schema::hasTable('attachments')) { if (!Schema::hasTable('attachments')) {
Schema::create( Schema::create(
@ -158,7 +158,7 @@ class CreateMainTables extends Migration
/** /**
* *
*/ */
private function createBillsTable() private function createBillsTable(): void
{ {
if (!Schema::hasTable('bills')) { if (!Schema::hasTable('bills')) {
Schema::create( Schema::create(
@ -190,7 +190,7 @@ class CreateMainTables extends Migration
/** /**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) // cannot be helped. * @SuppressWarnings(PHPMD.ExcessiveMethodLength) // cannot be helped.
*/ */
private function createBudgetTables() private function createBudgetTables(): void
{ {
if (!Schema::hasTable('budgets')) { if (!Schema::hasTable('budgets')) {
Schema::create( Schema::create(
@ -241,7 +241,7 @@ class CreateMainTables extends Migration
/** /**
* *
*/ */
private function createCategoriesTable() private function createCategoriesTable(): void
{ {
if (!Schema::hasTable('categories')) { if (!Schema::hasTable('categories')) {
Schema::create( Schema::create(
@ -264,7 +264,7 @@ class CreateMainTables extends Migration
/** /**
* *
*/ */
private function createExportJobsTable() private function createExportJobsTable(): void
{ {
if (!Schema::hasTable('export_jobs')) { if (!Schema::hasTable('export_jobs')) {
Schema::create( Schema::create(
@ -300,7 +300,7 @@ class CreateMainTables extends Migration
/** /**
* *
*/ */
private function createPiggyBanksTable() private function createPiggyBanksTable(): void
{ {
if (!Schema::hasTable('piggy_banks')) { if (!Schema::hasTable('piggy_banks')) {
Schema::create( Schema::create(
@ -341,7 +341,7 @@ class CreateMainTables extends Migration
/** /**
* *
*/ */
private function createPreferencesTable() private function createPreferencesTable(): void
{ {
if (!Schema::hasTable('preferences')) { if (!Schema::hasTable('preferences')) {
Schema::create( Schema::create(
@ -362,7 +362,7 @@ class CreateMainTables extends Migration
/** /**
* *
*/ */
private function createRoleTable() private function createRoleTable(): void
{ {
if (!Schema::hasTable('role_user')) { if (!Schema::hasTable('role_user')) {
Schema::create( Schema::create(
@ -384,7 +384,7 @@ class CreateMainTables extends Migration
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) // cannot be helped. * @SuppressWarnings(PHPMD.ExcessiveMethodLength) // cannot be helped.
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // its exactly five * @SuppressWarnings(PHPMD.CyclomaticComplexity) // its exactly five
*/ */
private function createRuleTables() private function createRuleTables(): void
{ {
if (!Schema::hasTable('rule_groups')) { if (!Schema::hasTable('rule_groups')) {
Schema::create( Schema::create(
@ -472,7 +472,7 @@ class CreateMainTables extends Migration
/** /**
* *
*/ */
private function createTagsTable() private function createTagsTable(): void
{ {
if (!Schema::hasTable('tags')) { if (!Schema::hasTable('tags')) {
Schema::create( Schema::create(
@ -503,7 +503,7 @@ class CreateMainTables extends Migration
* @SuppressWarnings(PHPMD.NPathComplexity) // cannot be helped * @SuppressWarnings(PHPMD.NPathComplexity) // cannot be helped
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // its exactly five * @SuppressWarnings(PHPMD.CyclomaticComplexity) // its exactly five
*/ */
private function createTransactionTables() private function createTransactionTables(): void
{ {
if (!Schema::hasTable('transaction_journals')) { if (!Schema::hasTable('transaction_journals')) {
Schema::create( Schema::create(

View File

@ -31,8 +31,14 @@ class ChangesFor3101 extends Migration
/** /**
* Reverse the migrations. * Reverse the migrations.
*/ */
public function down() public function down(): void
{ {
Schema::table(
'import_jobs',
function (Blueprint $table) {
$table->dropColumn('extended_status');
}
);
} }
/** /**
@ -40,7 +46,7 @@ class ChangesFor3101 extends Migration
* *
* @SuppressWarnings(PHPMD.ShortMethodName) * @SuppressWarnings(PHPMD.ShortMethodName)
*/ */
public function up() public function up(): void
{ {
Schema::table( Schema::table(
'import_jobs', 'import_jobs',

View File

@ -31,7 +31,7 @@ class FixNullables extends Migration
/** /**
* Reverse the migrations. * Reverse the migrations.
*/ */
public function down() public function down(): void
{ {
} }
@ -40,7 +40,7 @@ class FixNullables extends Migration
* *
* @SuppressWarnings(PHPMD.ShortMethodName) * @SuppressWarnings(PHPMD.ShortMethodName)
*/ */
public function up() public function up(): void
{ {
Schema::table( Schema::table(
'rule_groups', 'rule_groups',

View File

@ -31,8 +31,14 @@ class ExpandTransactionsTable extends Migration
/** /**
* Reverse the migrations. * Reverse the migrations.
*/ */
public function down() public function down(): void
{ {
Schema::table(
'transactions',
function (Blueprint $table) {
$table->dropColumn('identifier');
}
);
} }
/** /**
@ -40,7 +46,7 @@ class ExpandTransactionsTable extends Migration
* *
* @SuppressWarnings(PHPMD.ShortMethodName) * @SuppressWarnings(PHPMD.ShortMethodName)
*/ */
public function up() public function up(): void
{ {
Schema::table( Schema::table(
'transactions', 'transactions',

View File

@ -31,7 +31,7 @@ class ChangesForV410 extends Migration
/** /**
* Reverse the migrations. * Reverse the migrations.
*/ */
public function down() public function down(): void
{ {
Schema::dropIfExists('notes'); Schema::dropIfExists('notes');
} }
@ -41,7 +41,7 @@ class ChangesForV410 extends Migration
* *
* @SuppressWarnings(PHPMD.ShortMethodName) * @SuppressWarnings(PHPMD.ShortMethodName)
*/ */
public function up() public function up(): void
{ {
Schema::create( Schema::create(
'notes', 'notes',

View File

@ -31,8 +31,14 @@ class ChangesForV420 extends Migration
/** /**
* Reverse the migrations. * Reverse the migrations.
*/ */
public function down() public function down(): void
{ {
Schema::table(
'journal_meta',
function (Blueprint $table) {
$table->dropSoftDeletes();
}
);
} }
/** /**
@ -40,7 +46,7 @@ class ChangesForV420 extends Migration
* *
* @SuppressWarnings(PHPMD.ShortMethodName) * @SuppressWarnings(PHPMD.ShortMethodName)
*/ */
public function up() public function up(): void
{ {
Schema::table( Schema::table(
'journal_meta', 'journal_meta',

View File

@ -31,7 +31,7 @@ class ChangesForV430 extends Migration
/** /**
* Reverse the migrations. * Reverse the migrations.
*/ */
public function down() public function down(): void
{ {
Schema::dropIfExists('available_budgets'); Schema::dropIfExists('available_budgets');
} }
@ -41,7 +41,7 @@ class ChangesForV430 extends Migration
* *
* @SuppressWarnings(PHPMD.ShortMethodName) * @SuppressWarnings(PHPMD.ShortMethodName)
*/ */
public function up() public function up(): void
{ {
Schema::create( Schema::create(
'available_budgets', 'available_budgets',

View File

@ -31,7 +31,7 @@ class ChangesForV431 extends Migration
/** /**
* Reverse the migrations. * Reverse the migrations.
*/ */
public function down() public function down(): void
{ {
// reinstate "repeats" and "repeat_freq". // reinstate "repeats" and "repeat_freq".
Schema::table( Schema::table(
@ -47,6 +47,14 @@ class ChangesForV431 extends Migration
} }
); );
// change field "start_date" to "startdate"
Schema::table(
'budget_limits',
function (Blueprint $table) {
$table->renameColumn('start_date', 'startdate');
}
);
// remove date field "end_date" // remove date field "end_date"
Schema::table( Schema::table(
'budget_limits', 'budget_limits',
@ -54,6 +62,13 @@ class ChangesForV431 extends Migration
$table->dropColumn('end_date'); $table->dropColumn('end_date');
} }
); );
// remove decimal places
Schema::table(
'transaction_currencies',
function (Blueprint $table) {
$table->dropColumn('decimal_places');
}
);
} }
/** /**
@ -61,7 +76,7 @@ class ChangesForV431 extends Migration
* *
* @SuppressWarnings(PHPMD.ShortMethodName) * @SuppressWarnings(PHPMD.ShortMethodName)
*/ */
public function up() public function up(): void
{ {
// add decimal places to "transaction currencies". // add decimal places to "transaction currencies".
Schema::table( Schema::table(

View File

@ -31,11 +31,23 @@ class ChangesForV440 extends Migration
/** /**
* Reverse the migrations. * Reverse the migrations.
*/ */
public function down() public function down(): void
{ {
if (Schema::hasTable('currency_exchange_rates')) { if (Schema::hasTable('currency_exchange_rates')) {
Schema::drop('currency_exchange_rates'); Schema::drop('currency_exchange_rates');
} }
Schema::table(
'transactions',
function (Blueprint $table) {
// cannot drop foreign keys in SQLite:
if ('sqlite' !== config('database.default')) {
$table->dropForeign('transactions_transaction_currency_id_foreign');
}
$table->dropColumn('transaction_currency_id');
}
);
} }
/** /**
@ -43,7 +55,7 @@ class ChangesForV440 extends Migration
* *
* @SuppressWarnings(PHPMD.ShortMethodName) * @SuppressWarnings(PHPMD.ShortMethodName)
*/ */
public function up() public function up(): void
{ {
if (!Schema::hasTable('currency_exchange_rates')) { if (!Schema::hasTable('currency_exchange_rates')) {
Schema::create( Schema::create(

View File

@ -31,8 +31,20 @@ class ChangesForV450 extends Migration
/** /**
* Reverse the migrations. * Reverse the migrations.
*/ */
public function down() public function down(): void
{ {
Schema::table(
'transactions',
function (Blueprint $table) {
$table->dropColumn('foreign_amount');
// cannot drop foreign keys in SQLite:
if ('sqlite' !== config('database.default')) {
$table->dropForeign('transactions_foreign_currency_id_foreign');
}
$table->dropColumn('foreign_currency_id');
}
);
} }
/** /**
@ -40,7 +52,7 @@ class ChangesForV450 extends Migration
* *
* @SuppressWarnings(PHPMD.ShortMethodName) * @SuppressWarnings(PHPMD.ShortMethodName)
*/ */
public function up() public function up(): void
{ {
// add "foreign_amount" to transactions // add "foreign_amount" to transactions
Schema::table( Schema::table(

View File

@ -32,7 +32,7 @@ class ChangesForV470 extends Migration
/** /**
* Reverse the migrations. * Reverse the migrations.
*/ */
public function down() public function down(): void
{ {
Schema::dropIfExists('journal_links'); Schema::dropIfExists('journal_links');
Schema::dropIfExists('link_types'); Schema::dropIfExists('link_types');
@ -43,7 +43,7 @@ class ChangesForV470 extends Migration
* *
* @SuppressWarnings(PHPMD.ShortMethodName) * @SuppressWarnings(PHPMD.ShortMethodName)
*/ */
public function up() public function up(): void
{ {
if (!Schema::hasTable('link_types')) { if (!Schema::hasTable('link_types')) {
Schema::create( Schema::create(

View File

@ -32,8 +32,14 @@ class ChangesForV470a extends Migration
/** /**
* Reverse the migrations. * Reverse the migrations.
*/ */
public function down() public function down(): void
{ {
Schema::table(
'transactions',
function (Blueprint $table) {
$table->dropColumn('reconciled');
}
);
} }
/** /**
@ -41,7 +47,7 @@ class ChangesForV470a extends Migration
* *
* @SuppressWarnings(PHPMD.ShortMethodName) * @SuppressWarnings(PHPMD.ShortMethodName)
*/ */
public function up() public function up(): void
{ {
Schema::table( Schema::table(
'transactions', 'transactions',

View File

@ -34,7 +34,7 @@ class CreateOauthAuthCodesTable extends Migration
/** /**
* Reverse the migrations. * Reverse the migrations.
*/ */
public function down() public function down(): void
{ {
Schema::drop('oauth_auth_codes'); Schema::drop('oauth_auth_codes');
} }
@ -42,7 +42,7 @@ class CreateOauthAuthCodesTable extends Migration
/** /**
* Run the migrations. * Run the migrations.
*/ */
public function up() public function up(): void
{ {
Schema::create( Schema::create(
'oauth_auth_codes', function (Blueprint $table) { 'oauth_auth_codes', function (Blueprint $table) {

View File

@ -34,7 +34,7 @@ class CreateOauthAccessTokensTable extends Migration
/** /**
* Reverse the migrations. * Reverse the migrations.
*/ */
public function down() public function down(): void
{ {
Schema::drop('oauth_access_tokens'); Schema::drop('oauth_access_tokens');
} }
@ -42,7 +42,7 @@ class CreateOauthAccessTokensTable extends Migration
/** /**
* Run the migrations. * Run the migrations.
*/ */
public function up() public function up(): void
{ {
Schema::create( Schema::create(
'oauth_access_tokens', function (Blueprint $table) { 'oauth_access_tokens', function (Blueprint $table) {

View File

@ -34,7 +34,7 @@ class CreateOauthRefreshTokensTable extends Migration
/** /**
* Reverse the migrations. * Reverse the migrations.
*/ */
public function down() public function down(): void
{ {
Schema::drop('oauth_refresh_tokens'); Schema::drop('oauth_refresh_tokens');
} }
@ -42,7 +42,7 @@ class CreateOauthRefreshTokensTable extends Migration
/** /**
* Run the migrations. * Run the migrations.
*/ */
public function up() public function up(): void
{ {
Schema::create( Schema::create(
'oauth_refresh_tokens', function (Blueprint $table) { 'oauth_refresh_tokens', function (Blueprint $table) {

View File

@ -34,7 +34,7 @@ class CreateOauthClientsTable extends Migration
/** /**
* Reverse the migrations. * Reverse the migrations.
*/ */
public function down() public function down(): void
{ {
Schema::drop('oauth_clients'); Schema::drop('oauth_clients');
} }
@ -42,7 +42,7 @@ class CreateOauthClientsTable extends Migration
/** /**
* Run the migrations. * Run the migrations.
*/ */
public function up() public function up(): void
{ {
Schema::create( Schema::create(
'oauth_clients', function (Blueprint $table) { 'oauth_clients', function (Blueprint $table) {

View File

@ -37,6 +37,7 @@ class CreateOauthPersonalAccessClientsTable extends Migration
public function down(): void public function down(): void
{ {
Schema::drop('oauth_personal_access_clients'); Schema::drop('oauth_personal_access_clients');
} }
/** /**

View File

@ -37,7 +37,18 @@ class ChangesForV472 extends Migration
*/ */
public function down(): void public function down(): void
{ {
// Schema::table(
'attachments',
function (Blueprint $table) {
$table->text('notes')->nullable();
}
);
Schema::table(
'budgets',
function (Blueprint $table) {
$table->dropColumn('order');
}
);
} }
/** /**

View File

@ -38,7 +38,25 @@ class ChangesForV473 extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::table(
'bills',
function (Blueprint $table) {
// cannot drop foreign keys in SQLite:
if ('sqlite' !== config('database.default')) {
$table->dropForeign('bills_transaction_currency_id_foreign');
}
$table->dropColumn('transaction_currency_id');
}
);
Schema::table(
'rules',
function (Blueprint $table) {
$table->dropColumn('strict');
}
);
} }
/** /**

View File

@ -37,6 +37,23 @@ class ChangesForV474 extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::table(
'import_jobs',
function (Blueprint $table) {
// cannot drop foreign keys in SQLite:
if ('sqlite' !== config('database.default')) {
$table->dropForeign('import_jobs_tag_id_foreign');
}
$table->dropColumn('provider');
$table->dropColumn('stage');
$table->dropColumn('transactions');
$table->dropColumn('errors');
$table->dropColumn('tag_id');
}
);
} }
/** /**

View File

@ -38,11 +38,17 @@ class ChangesForV477 extends Migration
*/ */
public function down(): void public function down(): void
{ {
// Schema::table(
Schema::table('budget_limits', function (Blueprint $table) { 'budget_limits', function (Blueprint $table) {
$table->dropForeign('budget_limits_transaction_currency_id_foreign');
// cannot drop foreign keys in SQLite:
if ('sqlite' !== config('database.default')) {
$table->dropForeign('budget_limits_transaction_currency_id_foreign');
}
$table->dropColumn(['transaction_currency_id']); $table->dropColumn(['transaction_currency_id']);
}); }
);
} }
/** /**

View File

@ -36,7 +36,11 @@ class ChangesForV479 extends Migration
*/ */
public function down() public function down()
{ {
// Schema::table(
'transaction_currencies', function (Blueprint $table) {
$table->dropColumn(['enabled']);
}
);
} }
/** /**