Skip to content

Commit

Permalink
Never drop tables
Browse files Browse the repository at this point in the history
  • Loading branch information
tntsoft committed Apr 29, 2021
1 parent 4a46739 commit 7dd2fa9
Show file tree
Hide file tree
Showing 4 changed files with 11,710 additions and 242 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor/
/node_modules
.phpunit.result.cache
.idea
37 changes: 19 additions & 18 deletions database/migrations/2018_08_29_200844_create_languages_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ class CreateLanguagesTable extends Migration
*/
public function up()
{
Schema::connection(config('translation.database.connection'))
->create(config('translation.database.languages_table'), function (Blueprint $table) {
$table->increments('id');
$table->string('name')->nullable();
$table->string('language');
$table->timestamps();
});
// create the table only if it doesn't exist
if(!Schema::connection(config('translation.database.connection'))->hasTable(config('translation.database.translations_table')))
{
Schema::connection(config('translation.database.connection'))->create(config('translation.database.languages_table'), function(Blueprint $table)
{
$table->increments('id');
$table->string('name')->nullable();
$table->string('language');
$table->timestamps();
});

$initialLanguages = array_unique([
config('app.fallback_locale'),
config('app.locale'),
]);
$initialLanguages = array_unique([config('app.fallback_locale'), config('app.locale'),]);

foreach ($initialLanguages as $language) {
Language::firstOrCreate([
'language' => $language,
]);
}
foreach($initialLanguages as $language)
{
Language::firstOrCreate(['language' => $language,]);
}
}
}

/**
Expand All @@ -41,7 +41,8 @@ public function up()
*/
public function down()
{
Schema::connection(config('translation.database.connection'))
->dropIfExists(config('translation.database.languages_table'));
// never drop the schema
// Schema::connection(config('translation.database.connection'))
// ->dropIfExists(config('translation.database.languages_table'));
}
}
31 changes: 18 additions & 13 deletions database/migrations/2018_08_29_205156_create_translations_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@ class CreateTranslationsTable extends Migration
*/
public function up()
{
Schema::connection(config('translation.database.connection'))
->create(config('translation.database.translations_table'), function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('language_id');
$table->foreign('language_id')->references('id')
->on(config('translation.database.languages_table'));
$table->string('group')->nullable();
$table->text('key');
$table->text('value')->nullable();
$table->timestamps();
});
// create the table only if it doesn't exist
if(!Schema::connection(config('translation.database.connection'))->hasTable(config('translation.database.translations_table')))
{
Schema::connection(config('translation.database.connection'))
->create(config('translation.database.translations_table'), function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('language_id');
$table->foreign('language_id')->references('id')
->on(config('translation.database.languages_table'));
$table->string('group')->nullable();
$table->text('key');
$table->text('value')->nullable();
$table->timestamps();
});
}
}

/**
Expand All @@ -33,7 +37,8 @@ public function up()
*/
public function down()
{
Schema::connection(config('translation.database.connection'))
->dropIfExists(config('translation.database.translations_table'));
// never drop the schema
// Schema::connection(config('translation.database.connection'))
// ->dropIfExists(config('translation.database.translations_table'));
}
}
Loading

0 comments on commit 7dd2fa9

Please sign in to comment.