From 4ebaa58d954f895e1873f2dea7bcec15761d66bf Mon Sep 17 00:00:00 2001 From: int2001 Date: Wed, 17 Sep 2025 09:07:50 +0000 Subject: [PATCH] Adds creationdate and modifydate to nearly every table --- application/config/migration.php | 2 +- application/migrations/256_crea_modidates.php | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 application/migrations/256_crea_modidates.php diff --git a/application/config/migration.php b/application/config/migration.php index 74c6d6f1f..91f88513b 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE; | */ -$config['migration_version'] = 255; +$config['migration_version'] = 256; /* |-------------------------------------------------------------------------- diff --git a/application/migrations/256_crea_modidates.php b/application/migrations/256_crea_modidates.php new file mode 100644 index 000000000..1d3002a70 --- /dev/null +++ b/application/migrations/256_crea_modidates.php @@ -0,0 +1,40 @@ +tables = [$this->config->item('table_name'), 'adif_modes','api','bandedges','bands','bandxuser','cat','club_permissions','contest','contest_session','cron','cwmacros','dxpedition','eQSL_images','hams_of_note','iota','label_types','lotw_certs','lotw_users','migrations','notes','oqrs','paper_types','primary_subdivisions','qsl_images','queries','satellite','satellitemode','station_logbooks','station_logbooks_relationship','station_profile','themes','thirdparty_logins','timezones','tle','user_options','users','webadif']; + } + + public function up() { + foreach ($this->tables as $tname) { + $this->add_create_modi($tname); + } + } + + public function down(){ + foreach ($this->tables as $tname) { + $this->rm_create_modi($tname); + } + } + + function add_create_modi($table) { + $this->dbtry("ALTER TABLE ".$table." ADD COLUMN `CREATION_DATE` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, ADD COLUMN `LAST_MODIFIED` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;"); + } + + function rm_create_modi($table) { + $this->dbtry("ALTER TABLE ".$table." DROP COLUMN IF EXISTS `CREATION_DATE`, DROP COLUMN IF EXISTS `LAST_MODIFIED`;"); + } + + function dbtry($what) { + try { + $this->db->query($what); + } catch (Exception $e) { + log_message("error", "Something gone wrong while altering the OQRS table: ".$e." // Executing: ".$this->db->last_query()); + } + } +} +