/** * Resets the database and install the migration table. * * @return void */ protected function migrate() { $tableNames = Schema::getConnection()->getDoctrineSchemaManager()->listTableNames(); foreach ($tableNames as $table) { Schema::drop($table); } $this->app['Illuminate\\Contracts\\Console\\Kernel']->call('migrate:install', ['--env' => 'testing']); }
/** * Run the migrations. * * @return void */ public function up() { $platform = Schema::getConnection()->getDoctrineSchemaManager()->getDatabasePlatform(); $platform->registerDoctrineTypeMapping('enum', 'string'); Schema::table('assets', function ($table) { $table->decimal('purchase_cost', 8, 2)->nullable()->default(null)->change(); }); }
/** * Reverse the migrations. * * @return void */ public function down() { Schema::table('goods', function (Blueprint $table) { $table->dropColumn('capsule_unit'); }); $table = Schema::getConnection()->getTablePrefix() . 'good_log'; DB::statement("ALTER TABLE `" . $table . "` MODIFY COLUMN `status` ENUM('purchase', 'new', 'picking' , 'price', 'edit', 'damage', 'replacement', 'allocation', 'empty');"); }
/** * Reverse the migrations. * * @return void */ public function down() { $grammar = Schema::getConnection()->getSchemaGrammar(); if ($grammar instanceof \Illuminate\Database\Schema\Grammars\MySqlGrammar) { Schema::table('GDN_Discussion', function ($table) { $table->dropIndex('search'); }); } Schema::drop('GDN_Discussion'); }
/** * Clean out the database for a new seed generation. */ private function cleanDatabase() { DB::statement('SET FOREIGN_KEY_CHECKS=0'); $tableNames = Schema::getConnection()->getDoctrineSchemaManager()->listTableNames(); foreach ($tableNames as $name) { //if you don't want to truncate migrations if ($name == 'migrations') { continue; } DB::table($name)->truncate(); } DB::statement('SET FOREIGN_KEY_CHECKS=1'); }
/** * Run the migrations. * * @return void */ public function up() { \Schema::create($this->table, function (Blueprint $table) { $table->increments('meta_id'); $table->string('meta_key'); $table->longText('meta_value'); $table->string('meta_type')->default('string'); $table->morphs('metable'); $table->index('meta_key'); // Laravel doesn't handle index length, so we need raw statement for this one \Schema::getConnection()->statement('create index meta_attributes_index_value on meta_attributes (meta_key, meta_value(20))'); }); }
/** * Run the migrations. * * @return void */ public function up() { Schema::table('people', function (Blueprint $table) { // Credit: https://github.com/laravel/framework/issues/3253#issuecomment-51961561 $conn = Schema::getConnection(); $dbSchemaManager = $conn->getDoctrineSchemaManager(); $doctrineTable = $dbSchemaManager->listTableDetails('people'); if ($doctrineTable->hasIndex('people_email_unique')) { $table->dropUnique('people_email_unique'); } $table->dropUnique('deleted_at'); $table->unique(['email', 'deleted_at']); }); }
/** * Add the seeded data. */ public function up() { // we will have some crazy ID values, cajole MySQL into accepting them $grammar = Schema::getConnection()->getSchemaGrammar(); if ($grammar instanceof \Illuminate\Database\Schema\Grammars\MySqlGrammar) { DB::statement('SET SESSION SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";'); } // do the seeding DB::beginTransaction(); foreach ($this->getSeedData() as $table => $rows) { // Note: each row may have different columns: can't use bulk insert foreach ($rows as $row) { $this->insertRow($table, $row); } } DB::commit(); }
private function emptyTables() { if (substr_count(get_class(DB::connection()), 'MySql') > 0) { DB::statement('SET FOREIGN_KEY_CHECKS=0'); } $tableNames = Schema::getConnection()->getDoctrineSchemaManager()->listTableNames(); foreach ($tableNames as $name) { //if you don't want to truncate migrations if ($name == 'migrations') { continue; } DB::table($name)->truncate(); } if (substr_count(get_class(DB::connection()), 'MySql') > 0) { DB::statement('SET FOREIGN_KEY_CHECKS=1'); } }
/** * Tests to make sure our testing environment is set up correctly */ public function testSetUp() { // make sure tests are working $this->assertTrue(true); // make sure Sentry is loaded and facade works $this->assertInstanceOf('Cartalyst\\Sentry\\Sentry', $this->app['sentry']); // verify that we have a database connection $this->assertInstanceOf('Illuminate\\Database\\Connection', Schema::getConnection()); // test that our database exists and has tables created in migrations $this->assertTrue(Schema::hasTable('migrations')); $this->assertTrue(Schema::hasTable('users')); $this->assertTrue(Schema::hasTable('foos')); $this->assertTrue(Schema::hasTable('bars')); $this->assertTrue(Schema::hasTable('bazes')); // test that the data we entered is loaded // check to see that our testing models were loaded $this->assertTrue(class_exists('Morphatic\\Snapi\\Tests\\Foo')); $this->assertTrue(class_exists('Morphatic\\Snapi\\Tests\\Bar')); $this->assertTrue(class_exists('Morphatic\\Snapi\\Tests\\Baz')); }
/** * Drop all the tables in the database */ public function dropTables() { $all_tables = \Schema::getConnection()->getDoctrineSchemaManager()->listTableNames(); \DB::statement("SET foreign_key_checks = 0"); foreach ($all_tables as $table) { \DB::statement('DROP TABLE IF EXISTS ' . $table); } }
<?php use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; $platform = Schema::getConnection()->getDoctrineSchemaManager()->getDatabasePlatform(); $platform->registerDoctrineTypeMapping('enum', 'string'); class ChangeProductsTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::table('products', function ($table) { $table->integer('subindustry_id')->unsigned()->nullable()->change(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::table('products', function ($table) { $table->integer('subindustry_id')->unsigned()->change(); }); } }
/** * Reverse the migrations. * * @return void */ public function down() { $table = Schema::getConnection()->getTablePrefix() . 'good_log'; DB::statement("ALTER TABLE `" . $table . "` MODIFY COLUMN `status` ENUM('purchase', 'new', 'picking' , 'price', 'edit', 'damage', 'replacement');"); }