From a6833ac3a4dc6b7007978f4108a3aafe6edcd182 Mon Sep 17 00:00:00 2001 From: Marcus Hill Date: Sun, 17 Apr 2022 23:16:36 +0100 Subject: [PATCH] created/updated timestamp update Convert all created_at and modified_at fields to default to current timestamp/update timestamp. We can cleanup the SQL code in post.php (and other places) to no longer manually set these values at a later date, but it will work fine for now --- database_updates.php | 104 ++++++++++++++++++++++++++- database_version.php | 2 +- db.sql | 166 +++++++++++++++++++++---------------------- 3 files changed, 185 insertions(+), 87 deletions(-) diff --git a/database_updates.php b/database_updates.php index 2631bb5e..d840195c 100644 --- a/database_updates.php +++ b/database_updates.php @@ -23,9 +23,9 @@ if(LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION){ mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_module_enable_itdoc` TINYINT(1) DEFAULT 1 AFTER `config_backup_path`"); mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_module_enable_ticketing` TINYINT(1) DEFAULT 1 AFTER `config_module_enable_itdoc`"); mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_module_enable_accounting` TINYINT(1) DEFAULT 1 AFTER `config_module_enable_ticketing`"); - + // Update the database to the next sequential version - mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.0.2'"); + mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.0.2'"); } if(CURRENT_DATABASE_VERSION == '0.0.2'){ @@ -56,12 +56,110 @@ if(LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION){ // Insert queries here required to update to DB version 0.0.4 // mysqli_query($mysqli, "ALTER TABLE ....."); + // Update all tables updated/modified fields to be automatic + + mysqli_query($mysqli, "ALTER TABLE `accounts` CHANGE `account_created_at` `account_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `account_updated_at` `account_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL;"); + + mysqli_query($mysqli, "ALTER TABLE `api_keys` CHANGE `api_key_created_at` `api_key_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP; "); + + mysqli_query($mysqli, "ALTER TABLE `assets` CHANGE `asset_created_at` `asset_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `asset_updated_at` `asset_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL;"); + + mysqli_query($mysqli, "ALTER TABLE `calendars` CHANGE `calendar_created_at` `calendar_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `calendar_updated_at` `calendar_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `campaigns` CHANGE `campaign_created_at` `campaign_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `campaign_updated_at` `campaign_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `campaign_messages` CHANGE `message_created_at` `message_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `message_updated_at` `message_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `categories` CHANGE `category_created_at` `category_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `category_updated_at` `category_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `certificates` CHANGE `certificate_created_at` `certificate_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `certificate_updated_at` `certificate_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `clients` CHANGE `client_created_at` `client_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `client_updated_at` `client_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `companies` CHANGE `company_created_at` `company_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `company_updated_at` `company_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `contacts` CHANGE `contact_created_at` `contact_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `contact_updated_at` `contact_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `contracts` CHANGE `contract_created_at` `contract_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `contract_updated_at` `contract_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `custom_links` CHANGE `custom_link_created_at` `custom_link_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP; "); + + mysqli_query($mysqli, "ALTER TABLE `departments` CHANGE `department_created_at` `department_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `department_updated_at` `department_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `documents` CHANGE `document_created_at` `document_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `document_updated_at` `document_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `domains` CHANGE `domain_created_at` `domain_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `domain_updated_at` `domain_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `events` CHANGE `event_created_at` `event_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `event_updated_at` `event_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `expenses` CHANGE `expense_created_at` `expense_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `expense_updated_at` `expense_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `files` CHANGE `file_created_at` `file_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `file_updated_at` `file_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL;"); + + mysqli_query($mysqli, "ALTER TABLE `history` CHANGE `history_created_at` `history_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP; "); + + mysqli_query($mysqli, "ALTER TABLE `invoices` CHANGE `invoice_created_at` `invoice_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `invoice_updated_at` `invoice_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `invoice_items` CHANGE `item_created_at` `item_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `item_updated_at` `item_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `locations` CHANGE `location_created_at` `location_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `location_updated_at` `location_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `logins` CHANGE `login_created_at` `login_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `login_updated_at` `login_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `logs` CHANGE `log_created_at` `log_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP; "); + + mysqli_query($mysqli, "ALTER TABLE `networks` CHANGE `network_created_at` `network_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `network_updated_at` `network_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `notifications` CHANGE `notification_timestamp` `notification_timestamp` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP; "); + + mysqli_query($mysqli, "ALTER TABLE `payments` CHANGE `payment_created_at` `payment_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `payment_updated_at` `payment_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `products` CHANGE `product_created_at` `product_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `product_updated_at` `product_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `quotes` CHANGE `quote_created_at` `quote_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `quote_updated_at` `quote_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `records` CHANGE `record_created_at` `record_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `record_updated_at` `record_updated_at` DATETIME on update CURRENT_TIMESTAMP NOT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `recurring` CHANGE `recurring_created_at` `recurring_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `recurring_updated_at` `recurring_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `scheduled_tickets` CHANGE `scheduled_ticket_created_at` `scheduled_ticket_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `scheduled_ticket_updated_at` `scheduled_ticket_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `services` CHANGE `service_created_at` `service_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `service_updated_at` `service_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `shared_items` CHANGE `item_created_at` `item_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP; "); + + mysqli_query($mysqli, "ALTER TABLE `software` CHANGE `software_created_at` `software_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `software_updated_at` `software_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `tags` CHANGE `tag_created_at` `tag_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `tag_updated_at` `tag_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `taxes` CHANGE `tax_created_at` `tax_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `tax_updated_at` `tax_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `tickets` CHANGE `ticket_created_at` `ticket_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `ticket_updated_at` `ticket_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `ticket_replies` CHANGE `ticket_reply_created_at` `ticket_reply_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `ticket_reply_updated_at` `ticket_reply_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `transfers` CHANGE `transfer_created_at` `transfer_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `transfer_updated_at` `transfer_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `trips` CHANGE `trip_created_at` `trip_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `trip_updated_at` `trip_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `users` CHANGE `user_created_at` `user_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `user_updated_at` `user_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); + + mysqli_query($mysqli, "ALTER TABLE `vendors` CHANGE `vendor_created_at` `vendor_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `vendor_updated_at` `vendor_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; "); // Then, update the database to the next sequential version - //mysqli_query($mysqli, "UPDATE settings SET config_current_database_version = '0.0.3'"); + mysqli_query($mysqli, "UPDATE settings SET config_current_database_version = '0.0.4'"); } + if(CURRENT_DATABASE_VERSION == '0.0.4'){ + // Insert queries here required to update to DB version 0.0.5 + + // ALTER queries..... + + // Then, update the database to the next sequential version + // mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.0.5'"); + } + // etc } diff --git a/database_version.php b/database_version.php index e0581015..4bf10e33 100644 --- a/database_version.php +++ b/database_version.php @@ -5,4 +5,4 @@ * It is used in conjunction with database_updates.php */ -DEFINE("LATEST_DATABASE_VERSION", "0.0.3"); \ No newline at end of file +DEFINE("LATEST_DATABASE_VERSION", "0.0.4"); \ No newline at end of file diff --git a/db.sql b/db.sql index 88a7b977..e1a14297 100644 --- a/db.sql +++ b/db.sql @@ -28,8 +28,8 @@ CREATE TABLE `accounts` ( `opening_balance` decimal(15,2) NOT NULL DEFAULT 0.00, `account_currency_code` varchar(200) NOT NULL, `account_notes` text DEFAULT NULL, - `account_created_at` datetime NOT NULL, - `account_updated_at` datetime DEFAULT NULL, + `account_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `account_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `account_archived_at` datetime DEFAULT NULL, `company_id` int(11) NOT NULL, PRIMARY KEY (`account_id`) @@ -47,8 +47,8 @@ CREATE TABLE `api_keys` ( `api_key_id` int(11) NOT NULL AUTO_INCREMENT, `api_key_name` varchar(255) NOT NULL, `api_key_secret` varchar(255) NOT NULL, - `api_key_created_at` datetime NOT NULL, - `api_key_updated_at` datetime DEFAULT NULL, + `api_key_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `api_key_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `api_key_expire` date NOT NULL, `api_key_client_id` int(11) NOT NULL DEFAULT '0', `company_id` int(11) NOT NULL, @@ -79,8 +79,8 @@ CREATE TABLE `assets` ( `asset_reciept` varchar(200) DEFAULT NULL, `asset_notes` text DEFAULT NULL, `asset_meshcentral_id` varchar(200) DEFAULT NULL, - `asset_created_at` datetime NOT NULL, - `asset_updated_at` datetime DEFAULT NULL, + `asset_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `asset_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `asset_archived_at` datetime DEFAULT NULL, `asset_login_id` int(11) DEFAULT NULL, `asset_vendor_id` int(11) DEFAULT NULL, @@ -104,8 +104,8 @@ CREATE TABLE `calendars` ( `calendar_id` int(11) NOT NULL AUTO_INCREMENT, `calendar_name` varchar(200) NOT NULL, `calendar_color` varchar(200) NOT NULL, - `calendar_created_at` datetime NOT NULL, - `calendar_updated_at` datetime DEFAULT NULL, + `calendar_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `calendar_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `calendar_archived_at` datetime DEFAULT NULL, `company_id` int(11) NOT NULL, PRIMARY KEY (`calendar_id`) @@ -131,8 +131,8 @@ CREATE TABLE `campaign_messages` ( `message_bounced_at` datetime DEFAULT NULL, `message_opened_at` datetime DEFAULT NULL, `message_clicked_at` datetime DEFAULT NULL, - `message_created_at` datetime NOT NULL, - `message_updated_at` datetime DEFAULT NULL, + `message_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `message_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `message_client_tag_id` int(11) NOT NULL, `message_contact_id` int(11) NOT NULL, `message_campaign_id` int(11) NOT NULL, @@ -157,8 +157,8 @@ CREATE TABLE `campaigns` ( `campaign_content` longtext NOT NULL, `campaign_status` varchar(20) NOT NULL, `campaign_scheduled_at` datetime DEFAULT NULL, - `campaign_created_at` datetime NOT NULL, - `campaign_updated_at` datetime DEFAULT NULL, + `campaign_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `campaign_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `campaign_archived_at` datetime DEFAULT NULL, `company_id` int(11) NOT NULL, PRIMARY KEY (`campaign_id`) @@ -177,8 +177,8 @@ CREATE TABLE `categories` ( `category_name` varchar(200) NOT NULL, `category_type` varchar(200) NOT NULL, `category_color` varchar(200) DEFAULT NULL, - `category_created_at` datetime NOT NULL, - `category_updated_at` datetime DEFAULT NULL, + `category_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `category_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `category_archived_at` datetime DEFAULT NULL, `company_id` int(11) NOT NULL, PRIMARY KEY (`category_id`) @@ -200,8 +200,8 @@ CREATE TABLE `certificates` ( `certificate_expire` date DEFAULT NULL, `certificate_public_key` text DEFAULT NULL, `certificate_notes` text DEFAULT NULL, - `certificate_created_at` datetime NOT NULL, - `certificate_updated_at` datetime DEFAULT NULL, + `certificate_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `certificate_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `certificate_archived_at` datetime DEFAULT NULL, `certificate_domain_id` int(11) DEFAULT NULL, `certificate_client_id` int(11) NOT NULL, @@ -241,8 +241,8 @@ CREATE TABLE `clients` ( `client_net_terms` int(10) NOT NULL, `client_notes` text DEFAULT NULL, `client_meshcentral_group` varchar(200) DEFAULT NULL, - `client_created_at` datetime NOT NULL, - `client_updated_at` datetime DEFAULT NULL, + `client_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `client_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `client_archived_at` datetime DEFAULT NULL, `client_accessed_at` datetime DEFAULT NULL, `primary_location` int(11) DEFAULT NULL, @@ -273,8 +273,8 @@ CREATE TABLE `companies` ( `company_logo` varchar(250) DEFAULT NULL, `company_locale` varchar(200) DEFAULT NULL, `company_currency` varchar(200) NOT NULL, - `company_created_at` datetime NOT NULL, - `company_updated_at` datetime DEFAULT NULL, + `company_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `company_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `company_archived_at` datetime DEFAULT NULL, PRIMARY KEY (`company_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; @@ -300,8 +300,8 @@ CREATE TABLE `contacts` ( `contact_auth_method` varchar(200) DEFAULT NULL, `contact_password_hash` varchar(200) DEFAULT NULL, `contact_important` tinyint(1) NOT NULL DEFAULT 0, - `contact_created_at` datetime NOT NULL, - `contact_updated_at` datetime DEFAULT NULL, + `contact_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `contact_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `contact_archived_at` datetime DEFAULT NULL, `contact_location_id` int(11) DEFAULT NULL, `contact_department_id` int(11) DEFAULT NULL, @@ -324,8 +324,8 @@ CREATE TABLE `contracts` ( `contract_description` longtext DEFAULT NULL, `contract_start_date` date DEFAULT NULL, `contract_end_date` date NOT NULL, - `contract_created_at` datetime NOT NULL, - `contract_updated_at` datetime DEFAULT NULL, + `contract_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `contract_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `contract_archived_at` datetime DEFAULT NULL, `contract_vendor_id` int(11) NOT NULL, `contract_client_id` int(11) NOT NULL, @@ -347,7 +347,7 @@ CREATE TABLE `custom_links` ( `custom_link_icon` varchar(100) DEFAULT NULL, `custom_link_url` varchar(250) NOT NULL, `custom_link_order` int(11) DEFAULT NULL, - `custom_link_created_at` datetime NOT NULL, + `custom_link_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `company_id` int(11) NOT NULL, PRIMARY KEY (`custom_link_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -363,8 +363,8 @@ DROP TABLE IF EXISTS `departments`; CREATE TABLE `departments` ( `department_id` int(11) NOT NULL AUTO_INCREMENT, `department_name` varchar(200) NOT NULL, - `department_created_at` datetime NOT NULL, - `department_updated_at` datetime DEFAULT NULL, + `department_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `department_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `department_archived_at` datetime DEFAULT NULL, `department_client_id` int(11) NOT NULL, `company_id` int(11) NOT NULL, @@ -399,8 +399,8 @@ CREATE TABLE `documents` ( `document_name` varchar(200) NOT NULL, `document_content` longtext NOT NULL, `document_content_raw` longtext NOT NULL, - `document_created_at` datetime NOT NULL, - `document_updated_at` datetime DEFAULT NULL, + `document_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `document_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `document_archived_at` datetime DEFAULT NULL, `document_template` tinyint(1) NOT NULL, `document_folder_id` int(11) DEFAULT NULL, @@ -445,8 +445,8 @@ CREATE TABLE `domains` ( `domain_name_servers` varchar(255) DEFAULT NULL, `domain_mail_servers` varchar(255) DEFAULT NULL, `domain_raw_whois` text DEFAULT NULL, - `domain_created_at` datetime NOT NULL, - `domain_updated_at` datetime DEFAULT NULL, + `domain_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `domain_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `domain_archived_at` datetime DEFAULT NULL, `domain_registrar` int(11) DEFAULT NULL, `domain_webhost` int(11) DEFAULT NULL, @@ -470,8 +470,8 @@ CREATE TABLE `events` ( `event_start` datetime NOT NULL, `event_end` datetime DEFAULT NULL, `event_repeat` varchar(200) DEFAULT NULL, - `event_created_at` datetime NOT NULL, - `event_updated_at` datetime DEFAULT NULL, + `event_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `event_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `event_archived_at` datetime DEFAULT NULL, `event_client_id` int(11) DEFAULT NULL, `event_location_id` int(11) DEFAULT NULL, @@ -497,8 +497,8 @@ CREATE TABLE `expenses` ( `expense_reference` varchar(200) DEFAULT NULL, `expense_payment_method` varchar(200) DEFAULT NULL, `expense_receipt` varchar(200) DEFAULT NULL, - `expense_created_at` datetime NOT NULL, - `expense_updated_at` datetime DEFAULT NULL, + `expense_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `expense_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `expense_archived_at` datetime DEFAULT NULL, `expense_vendor_id` int(11) DEFAULT NULL, `expense_client_id` int(11) DEFAULT NULL, @@ -522,8 +522,8 @@ CREATE TABLE `files` ( `file_reference_name` varchar(200) DEFAULT NULL, `file_name` varchar(200) NOT NULL, `file_ext` varchar(200) DEFAULT NULL, - `file_created_at` datetime NOT NULL, - `file_updated_at` datetime DEFAULT NULL, + `file_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `file_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `file_archived_at` datetime DEFAULT NULL, `file_contact_id` int(11) NOT NULL DEFAULT 0, `file_client_id` int(11) NOT NULL, @@ -560,7 +560,7 @@ CREATE TABLE `history` ( `history_id` int(11) NOT NULL AUTO_INCREMENT, `history_status` varchar(200) NOT NULL, `history_description` varchar(200) NOT NULL, - `history_created_at` datetime NOT NULL, + `history_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `history_archived_at` datetime DEFAULT NULL, `history_invoice_id` int(11) DEFAULT NULL, `history_recurring_id` int(11) DEFAULT NULL, @@ -586,8 +586,8 @@ CREATE TABLE `invoice_items` ( `item_subtotal` decimal(15,2) NOT NULL, `item_tax` decimal(15,2) DEFAULT NULL, `item_total` decimal(15,2) NOT NULL, - `item_created_at` datetime NOT NULL, - `item_updated_at` datetime DEFAULT NULL, + `item_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `item_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `item_archived_at` datetime DEFAULT NULL, `item_tax_id` int(11) DEFAULT NULL, `item_quote_id` int(11) DEFAULT NULL, @@ -617,8 +617,8 @@ CREATE TABLE `invoices` ( `invoice_currency_code` varchar(200) NOT NULL, `invoice_note` text DEFAULT NULL, `invoice_url_key` varchar(200) DEFAULT NULL, - `invoice_created_at` datetime NOT NULL, - `invoice_updated_at` datetime DEFAULT NULL, + `invoice_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `invoice_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `invoice_archived_at` datetime DEFAULT NULL, `invoice_category_id` int(11) NOT NULL, `invoice_client_id` int(11) NOT NULL, @@ -646,8 +646,8 @@ CREATE TABLE `locations` ( `location_hours` varchar(200) DEFAULT NULL, `location_photo` varchar(200) DEFAULT NULL, `location_notes` text DEFAULT NULL, - `location_created_at` datetime NOT NULL, - `location_updated_at` datetime DEFAULT NULL, + `location_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `location_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `location_archived_at` datetime DEFAULT NULL, `location_contact_id` int(11) DEFAULT NULL, `location_client_id` int(11) DEFAULT NULL, @@ -672,8 +672,8 @@ CREATE TABLE `logins` ( `login_password` varbinary(200) DEFAULT NULL, `login_otp_secret` varchar(200) DEFAULT NULL, `login_note` text DEFAULT NULL, - `login_created_at` datetime NOT NULL, - `login_updated_at` datetime DEFAULT NULL, + `login_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `login_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `login_archived_at` datetime DEFAULT NULL, `login_contact_id` int(11) NOT NULL DEFAULT 0, `login_vendor_id` int(11) DEFAULT NULL, @@ -699,7 +699,7 @@ CREATE TABLE `logs` ( `log_description` varchar(255) NOT NULL, `log_ip` varchar(200) DEFAULT NULL, `log_user_agent` varchar(250) DEFAULT NULL, - `log_created_at` datetime NOT NULL, + `log_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `log_archived_at` datetime DEFAULT NULL, `log_client_id` int(11) DEFAULT NULL, `log_invoice_id` int(11) DEFAULT NULL, @@ -746,8 +746,8 @@ CREATE TABLE `networks` ( `network_gateway` varchar(200) NOT NULL, `network_dhcp_range` varchar(200) DEFAULT NULL, `network_notes` text DEFAULT NULL, - `network_created_at` datetime NOT NULL, - `network_updated_at` datetime DEFAULT NULL, + `network_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `network_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `network_archived_at` datetime DEFAULT NULL, `network_location_id` int(11) DEFAULT NULL, `network_client_id` int(11) NOT NULL, @@ -790,8 +790,8 @@ CREATE TABLE `payments` ( `payment_currency_code` varchar(10) NOT NULL, `payment_method` varchar(200) DEFAULT NULL, `payment_reference` varchar(200) DEFAULT NULL, - `payment_created_at` datetime NOT NULL, - `payment_updated_at` datetime DEFAULT NULL, + `payment_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `payment_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `payment_archived_at` datetime DEFAULT NULL, `payment_account_id` int(11) NOT NULL, `payment_invoice_id` int(11) DEFAULT NULL, @@ -813,8 +813,8 @@ CREATE TABLE `products` ( `product_description` text DEFAULT NULL, `product_price` decimal(15,2) NOT NULL, `product_currency_code` varchar(200) NOT NULL, - `product_created_at` datetime NOT NULL, - `product_updated_at` datetime DEFAULT NULL, + `product_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `product_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `product_archived_at` datetime DEFAULT NULL, `product_tax_id` int(11) DEFAULT NULL, `product_category_id` int(11) NOT NULL, @@ -841,8 +841,8 @@ CREATE TABLE `quotes` ( `quote_currency_code` varchar(200) NOT NULL, `quote_note` text DEFAULT NULL, `quote_url_key` varchar(200) DEFAULT NULL, - `quote_created_at` datetime NOT NULL, - `quote_updated_at` datetime DEFAULT NULL, + `quote_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `quote_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `quote_archived_at` datetime DEFAULT NULL, `quote_category_id` int(11) NOT NULL, `quote_client_id` int(11) NOT NULL, @@ -864,7 +864,7 @@ CREATE TABLE `records` ( `record` varchar(200) NOT NULL, `record_value` varchar(200) NOT NULL, `record_priority` int(11) DEFAULT NULL, - `record_created_at` datetime NOT NULL, + `record_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `record_updated_at` datetime NOT NULL, `record_archived_at` datetime DEFAULT NULL, `record_domain_id` int(11) NOT NULL, @@ -892,8 +892,8 @@ CREATE TABLE `recurring` ( `recurring_amount` decimal(15,2) DEFAULT NULL, `recurring_currency_code` varchar(200) NOT NULL, `recurring_note` text DEFAULT NULL, - `recurring_created_at` datetime NOT NULL, - `recurring_updated_at` datetime DEFAULT NULL, + `recurring_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `recurring_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `recurring_archived_at` datetime DEFAULT NULL, `recurring_category_id` int(11) NOT NULL, `recurring_client_id` int(11) NOT NULL, @@ -917,8 +917,8 @@ CREATE TABLE `revenues` ( `revenue_payment_method` varchar(200) DEFAULT NULL, `revenue_reference` varchar(200) DEFAULT NULL, `revenue_description` varchar(200) DEFAULT NULL, - `revenue_created_at` datetime NOT NULL, - `revenue_updated_at` datetime DEFAULT NULL, + `revenue_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `revenue_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `revenue_archived_at` datetime DEFAULT NULL, `revenue_category_id` int(11) NOT NULL, `revenue_account_id` int(11) NOT NULL, @@ -958,8 +958,8 @@ CREATE TABLE `scheduled_tickets` ( `scheduled_ticket_frequency` varchar(10) NOT NULL, `scheduled_ticket_start_date` date NOT NULL, `scheduled_ticket_next_run` date NOT NULL, - `scheduled_ticket_created_at` datetime NOT NULL, - `scheduled_ticket_updated_at` datetime DEFAULT NULL, + `scheduled_ticket_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `scheduled_ticket_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `scheduled_ticket_created_by` int(11) NOT NULL, `scheduled_ticket_client_id` int(11) DEFAULT NULL, `scheduled_ticket_contact_id` int(11) DEFAULT NULL, @@ -1075,8 +1075,8 @@ CREATE TABLE `services` ( `service_importance` varchar(10) CHARACTER SET latin1 NOT NULL, `service_backup` varchar(200) DEFAULT NULL, `service_notes` text CHARACTER SET latin1 NOT NULL, - `service_created_at` datetime NOT NULL, - `service_updated_at` datetime DEFAULT NULL, + `service_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `service_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `service_review_due` date DEFAULT NULL, `service_client_id` int(11) NOT NULL, `company_id` int(11) NOT NULL, @@ -1165,7 +1165,7 @@ CREATE TABLE `shared_items` ( `item_note` varchar(255) DEFAULT NULL, `item_views` int(11) NOT NULL, `item_view_limit` int(11) DEFAULT NULL, - `item_created_at` datetime NOT NULL, + `item_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `item_expire_at` datetime DEFAULT NULL, `item_client_id` int(11) NOT NULL, PRIMARY KEY (`item_id`) @@ -1190,8 +1190,8 @@ CREATE TABLE `software` ( `software_purchase` date DEFAULT NULL, `software_expire` date DEFAULT NULL, `software_notes` text DEFAULT NULL, - `software_created_at` datetime NOT NULL, - `software_updated_at` datetime DEFAULT NULL, + `software_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `software_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `software_archived_at` datetime DEFAULT NULL, `software_login_id` int(11) DEFAULT NULL, `software_client_id` int(11) NOT NULL, @@ -1241,8 +1241,8 @@ CREATE TABLE `tags` ( `tag_type` int(11) NOT NULL, `tag_color` varchar(200) DEFAULT NULL, `tag_icon` varchar(200) DEFAULT NULL, - `tag_created_at` datetime NOT NULL, - `tag_updated_at` datetime DEFAULT NULL, + `tag_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `tag_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `company_id` int(11) NOT NULL, PRIMARY KEY (`tag_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -1259,8 +1259,8 @@ CREATE TABLE `taxes` ( `tax_id` int(11) NOT NULL AUTO_INCREMENT, `tax_name` varchar(200) NOT NULL, `tax_percent` float NOT NULL, - `tax_created_at` datetime NOT NULL, - `tax_updated_at` datetime DEFAULT NULL, + `tax_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `tax_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `tax_archived_at` datetime DEFAULT NULL, `company_id` int(11) NOT NULL, PRIMARY KEY (`tax_id`) @@ -1279,8 +1279,8 @@ CREATE TABLE `ticket_replies` ( `ticket_reply` longtext NOT NULL, `ticket_reply_type` varchar(10) NOT NULL, `ticket_reply_time_worked` time DEFAULT NULL, - `ticket_reply_created_at` datetime NOT NULL, - `ticket_reply_updated_at` datetime DEFAULT NULL, + `ticket_reply_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `ticket_reply_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `ticket_reply_archived_at` datetime DEFAULT NULL, `ticket_reply_by` int(11) NOT NULL, `ticket_reply_ticket_id` int(11) NOT NULL, @@ -1322,8 +1322,8 @@ CREATE TABLE `tickets` ( `ticket_priority` varchar(200) DEFAULT NULL, `ticket_status` varchar(200) NOT NULL, `ticket_feedback` varchar(200) DEFAULT NULL, - `ticket_created_at` datetime NOT NULL, - `ticket_updated_at` datetime DEFAULT NULL, + `ticket_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `ticket_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `ticket_archived_at` datetime DEFAULT NULL, `ticket_closed_at` datetime DEFAULT NULL, `ticket_created_by` int(11) NOT NULL, @@ -1349,8 +1349,8 @@ DROP TABLE IF EXISTS `transfers`; CREATE TABLE `transfers` ( `transfer_id` int(11) NOT NULL AUTO_INCREMENT, `transfer_notes` text DEFAULT NULL, - `transfer_created_at` datetime NOT NULL, - `transfer_updated_at` datetime DEFAULT NULL, + `transfer_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `transfer_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `transfer_archived_at` datetime DEFAULT NULL, `transfer_expense_id` int(11) NOT NULL, `transfer_revenue_id` int(11) NOT NULL, @@ -1376,8 +1376,8 @@ CREATE TABLE `trips` ( `trip_end_odmeter` int(11) DEFAULT NULL, `trip_miles` float(15,1) NOT NULL, `round_trip` int(1) NOT NULL, - `trip_created_at` datetime NOT NULL, - `trip_updated_at` datetime DEFAULT NULL, + `trip_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `trip_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `trip_archived_at` datetime DEFAULT NULL, `trip_user_id` int(11) NOT NULL DEFAULT 0, `trip_client_id` int(11) DEFAULT NULL, @@ -1448,8 +1448,8 @@ CREATE TABLE `users` ( `user_specific_encryption_ciphertext` varchar(200) DEFAULT NULL, `user_php_session` varchar(255) DEFAULT NULL, `user_extension_key` varchar(18) DEFAULT NULL, - `user_created_at` datetime NOT NULL, - `user_updated_at` datetime DEFAULT NULL, + `user_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `user_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `user_archived_at` datetime DEFAULT NULL, PRIMARY KEY (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; @@ -1479,8 +1479,8 @@ CREATE TABLE `vendors` ( `vendor_account_number` varchar(200) DEFAULT NULL, `vendor_notes` text DEFAULT NULL, `vendor_global` tinyint(1) DEFAULT NULL, - `vendor_created_at` datetime NOT NULL, - `vendor_updated_at` datetime DEFAULT NULL, + `vendor_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `vendor_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `vendor_archived_at` datetime DEFAULT NULL, `vendor_client_id` int(11) DEFAULT NULL, `company_id` int(11) NOT NULL,