Fix database migration rollback

This commit is contained in:
gdarko
2021-11-06 14:22:59 -05:00
parent e43ddeea54
commit fdb46275c0
23 changed files with 71 additions and 14 deletions

View File

@@ -43,6 +43,11 @@ class CreateCustomFieldsTable extends Migration
*/
public function down()
{
Schema::table('custom_fields', function (Blueprint $table) {
if (config('database.default') !== 'sqlite') {
$table->dropForeign( [ 'company_id' ] );
}
});
Schema::dropIfExists('custom_fields');
}
}

View File

@@ -39,6 +39,12 @@ class CreateCustomFieldValuesTable extends Migration
*/
public function down()
{
Schema::dropIfExists('answers');
Schema::table('custom_field_values', function (Blueprint $table){
if (config('database.default') !== 'sqlite') {
$table->dropForeign(['custom_field_id']);
$table->dropForeign(['company_id']);
}
});
Schema::dropIfExists('custom_field_values');
}
}

View File

@@ -26,8 +26,6 @@ class AddUserIdToExpensesTable extends Migration
*/
public function down()
{
Schema::table('expenses', function (Blueprint $table) {
$table->dropColumn('paid');
});
}
}

View File

@@ -28,7 +28,9 @@ class AddCompanyToAddressesTable extends Migration
public function down()
{
Schema::table('addresses', function (Blueprint $table) {
$table->dropForeign(['company_id']);
if (config('database.default') !== 'sqlite') {
$table->dropForeign( [ 'company_id' ] );
}
});
}
}

View File

@@ -27,7 +27,9 @@ class AddCreatorInInvoicesTable extends Migration
public function down()
{
Schema::table('invoices', function (Blueprint $table) {
$table->dropForeign(['creator_id']);
if (config('database.default') !== 'sqlite') {
$table->dropForeign( [ 'creator_id' ] );
}
});
}
}

View File

@@ -27,7 +27,9 @@ class AddCreatorInEstimatesTable extends Migration
public function down()
{
Schema::table('estimates', function (Blueprint $table) {
$table->dropForeign(['creator_id']);
if (config('database.default') !== 'sqlite') {
$table->dropForeign( [ 'creator_id' ] );
}
});
}
}

View File

@@ -27,7 +27,9 @@ class AddCreatorInPaymentsTable extends Migration
public function down()
{
Schema::table('payments', function (Blueprint $table) {
$table->dropForeign(['creator_id']);
if (config('database.default') !== 'sqlite') {
$table->dropForeign( [ 'creator_id' ] );
}
});
}
}

View File

@@ -27,7 +27,9 @@ class AddCreatorInExpensesTable extends Migration
public function down()
{
Schema::table('expenses', function (Blueprint $table) {
$table->dropForeign(['creator_id']);
if (config('database.default') !== 'sqlite') {
$table->dropForeign( [ 'creator_id' ] );
}
});
}
}

View File

@@ -27,7 +27,9 @@ class AddCreatorInItemsTable extends Migration
public function down()
{
Schema::table('items', function (Blueprint $table) {
$table->dropForeign(['creator_id']);
if (config('database.default') !== 'sqlite') {
$table->dropForeign( [ 'creator_id' ] );
}
});
}
}

View File

@@ -27,7 +27,9 @@ class AddCreatorInUsersTable extends Migration
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropForeign(['creator_id']);
if (config('database.default') !== 'sqlite') {
$table->dropForeign( [ 'creator_id' ] );
}
});
}
}

View File

@@ -52,7 +52,9 @@ class AddOwnerIdToCompaniesTable extends Migration
{
Schema::table('companies', function (Blueprint $table) {
$table->dropColumn('slug');
$table->dropForeign(['owner_id']);
if (config('database.default') !== 'sqlite') {
$table->dropForeign( [ 'owner_id' ] );
}
});
}
}

View File

@@ -39,7 +39,9 @@ class AddCompanyToNotesTable extends Migration
public function down()
{
Schema::table('notes', function (Blueprint $table) {
$table->dropForeign(['company_id']);
if (config('database.default') !== 'sqlite') {
$table->dropForeign( [ 'company_id' ] );
}
});
}
}

View File

@@ -27,6 +27,9 @@ class AddRecurringInvoiceIdToInvoicesTable extends Migration
public function down()
{
Schema::table('invoices', function (Blueprint $table) {
if (config('database.default') !== 'sqlite') {
$table->dropForeign( [ 'recurring_invoice_id' ] );
}
$table->dropColumn('recurring_invoice_id');
});
}

View File

@@ -28,6 +28,9 @@ class AddRecurringInvoiceIdToInvoiceItemsTable extends Migration
public function down()
{
Schema::table('invoice_items', function (Blueprint $table) {
if (config('database.default') !== 'sqlite') {
$table->dropForeign( [ 'recurring_invoice_id' ] );
}
$table->dropColumn('recurring_invoice_id');
});
}

View File

@@ -27,6 +27,9 @@ class AddCurrencyIdIntoInvoicesTable extends Migration
public function down()
{
Schema::table('invoices', function (Blueprint $table) {
if (config('database.default') !== 'sqlite') {
$table->dropForeign( [ 'currency_id' ] );
}
$table->dropColumn('currency_id');
});
}

View File

@@ -27,6 +27,9 @@ class AddCurrencyIdIntoPaymentsTable extends Migration
public function down()
{
Schema::table('payments', function (Blueprint $table) {
if (config('database.default') !== 'sqlite') {
$table->dropForeign( [ 'currency_id' ] );
}
$table->dropColumn('currency_id');
});
}

View File

@@ -27,6 +27,9 @@ class AddCurrencyIdIntoItemsTable extends Migration
public function down()
{
Schema::table('items', function (Blueprint $table) {
if (config('database.default') !== 'sqlite') {
$table->dropForeign( [ 'currency_id' ] );
}
$table->dropColumn('currency_id');
});
}

View File

@@ -27,6 +27,9 @@ class AddCurrencyIdIntoTaxesTable extends Migration
public function down()
{
Schema::table('taxes', function (Blueprint $table) {
if (config('database.default') !== 'sqlite') {
$table->dropForeign( [ 'currency_id' ] );
}
$table->dropColumn('currency_id');
});
}

View File

@@ -27,6 +27,9 @@ class AddCurrencyIdIntoEstimatesTable extends Migration
public function down()
{
Schema::table('estimates', function (Blueprint $table) {
if (config('database.default') !== 'sqlite') {
$table->dropForeign( [ 'currency_id' ] );
}
$table->dropColumn('currency_id');
});
}

View File

@@ -33,6 +33,6 @@ class CreateExchangeRateLogsTable extends Migration
*/
public function down()
{
Schema::dropIfExists('exchange_rates');
Schema::dropIfExists('exchange_rate_logs');
}
}

View File

@@ -27,6 +27,9 @@ class AddRecurringInvoiceIdToTaxesTable extends Migration
public function down()
{
Schema::table('taxes', function (Blueprint $table) {
if (config('database.default') !== 'sqlite') {
$table->dropForeign( [ 'recurring_invoice_id' ] );
}
$table->dropColumn('recurring_invoice_id');
});
}

View File

@@ -27,6 +27,9 @@ class AddPaymentMethodToExpenseTable extends Migration
public function down()
{
Schema::table('expenses', function (Blueprint $table) {
if (config('database.default') !== 'sqlite') {
$table->dropForeign( [ 'payment_method_id' ] );
}
$table->dropColumn('payment_method_id');
});
}

View File

@@ -27,6 +27,9 @@ class AddTransactionIdToPaymentsTable extends Migration
public function down()
{
Schema::table('payments', function (Blueprint $table) {
if (config('database.default') !== 'sqlite') {
$table->dropForeign( [ 'transaction_id' ] );
}
$table->dropColumn('transaction_id');
});
}