diff --git a/db/migrations/20210423172422_add_created_at_and_updated_at.php b/db/migrations/20210423172422_add_created_at_and_updated_at.php new file mode 100644 index 0000000..31a19a5 --- /dev/null +++ b/db/migrations/20210423172422_add_created_at_and_updated_at.php @@ -0,0 +1,53 @@ +getAdapter()->getOption('name'); + $query = 'SELECT table_name FROM information_schema.tables WHERE table_schema = \'' . $database_name . '\''; + $tables = $this->query($query)->fetchAll(); + foreach ($tables as $table) + { + //Do not modify phinxlog + if ($table['table_name'] == 'phinxlog') + { + continue; + } + + //Foreach table add timestamps, created_at and updated_at whith default values + $table = $this->table($table['table_name']); + $table->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP']); + $table->addColumn('updated_at', 'timestamp', ['null' => true, 'update' => 'CURRENT_TIMESTAMP']); + $table->update(); + } + + } +}