Skip to content

Commit

Permalink
refact: refatora código para criação de tabelas
Browse files Browse the repository at this point in the history
Este commit refatora o método de criação das colunas de timestamp, a lógica inicial utilizava modificadores não compativeis com a versao atual do Capsule utilizado pelo WHMCS.

ref: #156
  • Loading branch information
andrekutianski committed Apr 26, 2024
1 parent 916f390 commit 01afe42
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public static function migrateTimestampColumns(string $tableName)
$pdo = Capsule::connection()->getPdo();
$pdo->beginTransaction();
try {
$self = new static();
$self = new self();
$self->createAlterColumnTimestampStatement($pdo, 'created_at', 'CURRENT_TIMESTAMP', $tableName);
$self->createAlterColumnTimestampStatement($pdo, 'updated_at', 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', $tableName);
if ($pdo->inTransaction()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@ public function drop()
*/
public function createAliquotsTable()
{
if (!Capsule::schema()->hasTable($this->tableName)) {
Capsule::schema()->create(
$db = Capsule::connection();
$schema = Capsule::schema();

if (!$schema->hasTable($this->tableName)) {
$schema->create(
$this->tableName,
function ($table) {
$table->increments('id');
Expand All @@ -91,9 +94,13 @@ function ($table) {
// retenção de ISS
$table->float('iss_held', 5, 2)->nullable();
$table->timestamp('created_at')->useCurrent();
$table->timestamp('updated_at')->useCurrentOnUpdate();
$table->timestamp('updated_at')->useCurrent();
}
);

// Adiciona a coluna updated_at com a configuração de auto update #156
$db->statement(sprintf('ALTER TABLE %s CHANGE updated_at updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', $this->tableName));

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,25 @@ public function dropProductCodeTable()
*/
public function createProductCodeTable()
{
if (!Capsule::schema()->hasTable($this->tableName)) {
Capsule::schema()->create(
$db = Capsule::connection();
$schema = Capsule::schema();

if (!$schema->hasTable($this->tableName)) {
$schema->create(
$this->tableName,
function ($table) {
$table->increments('id');
$table->integer('product_id');
$table->string('code_service', 30);
$table->timestamp('created_at')->useCurrent();
$table->timestamp('updated_at')->useCurrentOnUpdate();
$table->timestamp('updated_at')->useCurrent();
$table->integer('ID_user');
}
);

// Adiciona a coluna updated_at com a configuração de auto update #156
$db->statement(sprintf('ALTER TABLE %s CHANGE updated_at updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', $this->tableName));

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ public function dataTable()
*/
public function createServiceInvoicesTable()
{
if (!Capsule::schema()->hasTable($this->tableName)) {
Capsule::schema()->create(
$db = Capsule::connection();
$schema = Capsule::schema();

if (!$schema->hasTable($this->tableName)) {
$schema->create(
$this->tableName,
function ($table) {
// incremented id
Expand All @@ -116,12 +119,16 @@ function ($table) {
$table->string('rpsSerialNumber');
$table->string('rpsNumber');
$table->timestamp('created_at')->useCurrent();
$table->timestamp('updated_at')->useCurrentOnUpdate();
$table->timestamp('updated_at')->useCurrent();
$table->string('service_code', 30)->nullable(true);
$table->string('tics')->nullable(true);
}
);
}

// Adiciona a coluna updated_at com a configuração de auto update #156
$db->statement(sprintf('ALTER TABLE %s CHANGE updated_at updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', $this->tableName));

}

/**
Expand Down

0 comments on commit 01afe42

Please sign in to comment.