This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateAtencaoBasicaInconsistenciaTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('atencao_basica_inconsistencia', function (Blueprint $table) {
|
||||
MigrationUtil::idWithoutIncrements($table);
|
||||
|
||||
$table->char('codigo', 3)->unique();
|
||||
$table->string('descricao', 100);
|
||||
|
||||
MigrationUtil::addCommonFields($table, ['staticData' => true]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('atencao_basica_inconsistencia');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateAtencaoBasicaExportacaoTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('atencao_basica_exportacao', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->uuid('uuid')->nullable();
|
||||
MigrationUtil::addCommonFields($table);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('atencao_basica_exportacao');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AlterDescricaoToAtencaoBasicaInconsistenciaTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('atencao_basica_inconsistencia', function (Blueprint $table) {
|
||||
$table->string('descricao', 200)->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('atencao_basica_inconsistencia', function (Blueprint $table) {
|
||||
$table->string('descricao', 100)->change();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AlterUuidToAtencaoBasicaExportacaoTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('atencao_basica_exportacao', function (Blueprint $table) {
|
||||
$table->string('uuid', 44)->nullable()->unique()->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('atencao_basica_exportacao', function (Blueprint $table) {
|
||||
$table->uuid('uuid')->nullable();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateAtencaoBasicaExportacaoTableArquivo extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
public function up()
|
||||
{
|
||||
Schema::create('atencao_basica_exportacao_arquivo', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('competencia', 6);
|
||||
$table->string('arquivo', 500);
|
||||
|
||||
MigrationUtil::addCommonFieldsWithSoftDeletes($table);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('atencao_basica_exportacao_arquivo');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateAtencaoBasicaExportacaoStatusTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('atencao_basica_exportacao_status', function (Blueprint $table) {
|
||||
MigrationUtil::idWithoutIncrements($table);
|
||||
|
||||
$table->string('nome', 100)->unique();
|
||||
|
||||
MigrationUtil::addCommonFields($table, ['staticData' => true]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('atencao_basica_exportacao_status');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddStatusIdToAtencaoBasicaExportacaoArquivoTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('atencao_basica_exportacao_arquivo', function (Blueprint $table) {
|
||||
$table->foreignId('status_id')->nullable()->after('id')->constrained('atencao_basica_exportacao_status');
|
||||
$table->string('arquivo', 500)->change()->nullable();
|
||||
$table->dateTime('data_hora_inicio')->nullable()->after('arquivo');
|
||||
$table->dateTime('data_hora_fim')->nullable()->after('data_hora_inicio');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('atencao_basica_exportacao_arquivo', function (Blueprint $table) {
|
||||
$table->dropConstrainedForeignId('status_id');
|
||||
$table->string('arquivo', 500)->change()->nullable(false);
|
||||
$table->dropColumn('data_hora_inicio');
|
||||
$table->dropColumn('data_hora_fim');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddExportacaoArquivoIdToAtencaoBasicaExportacaoTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('atencao_basica_exportacao', function (Blueprint $table) {
|
||||
$table->foreignId('exportacao_arquivo_id')->nullable()->after('id')->constrained('atencao_basica_exportacao_arquivo');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('atencao_basica_exportacao', function (Blueprint $table) {
|
||||
$table->dropConstrainedForeignId('exportacao_arquivo_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\AtencaoBasica\Exportacao\Status;
|
||||
use App\Models\AtencaoBasica\Exportacao\ExportacaoArquivo;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class UpdateStatusIdOnAtencaoBasicaExportacaoArquivoTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
ExportacaoArquivo::withTrashed()->whereNull('status_id')->update(['status_id' => Status::PROCESSADO]);
|
||||
|
||||
DB::table('atencao_basica_exportacao_arquivo')
|
||||
->select([
|
||||
'competencia',
|
||||
DB::raw('COUNT(*) AS quantidade'),
|
||||
])
|
||||
->whereNull('deleted_at')
|
||||
->where('status_id', Status::ERRO_NO_PROCESSAMENTO)
|
||||
->groupBy('competencia')
|
||||
->havingRaw('COUNT(*) > 1')
|
||||
->get()
|
||||
->each(function ($query) {
|
||||
ExportacaoArquivo::where('competencia', $query->competencia)
|
||||
->where('status_id', Status::ERRO_NO_PROCESSAMENTO)
|
||||
->orderBy('id')
|
||||
->take($query->quantidade - 1)
|
||||
->delete();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user