From 7483cebccaac46b537a69b1a07240dcd4426875c Mon Sep 17 00:00:00 2001 From: Limezy Date: Mon, 4 Dec 2023 23:07:21 +0700 Subject: [PATCH] Add table migration --- conf/migrate_7.0.5.sql | 17 +++++++++++++++++ scripts/upgrade | 11 +++++++++++ 2 files changed, 28 insertions(+) create mode 100644 conf/migrate_7.0.5.sql diff --git a/conf/migrate_7.0.5.sql b/conf/migrate_7.0.5.sql new file mode 100644 index 0000000..6e7fef4 --- /dev/null +++ b/conf/migrate_7.0.5.sql @@ -0,0 +1,17 @@ +SET NAMES utf8mb4; + +CREATE TABLE `jetton` ( + `no_jetton` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, + `no_compte` mediumint(8) unsigned DEFAULT NULL, + `nom` varchar(256) COLLATE utf8mb4_bin NOT NULL, + `expire` tinyint(1) unsigned NOT NULL DEFAULT 0, + `pays` varchar(2) COLLATE utf8mb4_bin DEFAULT NULL, + `date_creation` timestamp NOT NULL DEFAULT current_timestamp(), + `date_use` timestamp NULL DEFAULT NULL, + `jetton_str` varchar(512) COLLATE utf8mb4_bin NOT NULL, + `captcha` varchar(16) COLLATE utf8mb4_bin DEFAULT NULL, + PRIMARY KEY (`no_jetton`), + UNIQUE KEY `jetton_str` (`jetton_str`), + KEY `no_compte` (`no_compte`), + CONSTRAINT `observation_ibfk_2` FOREIGN KEY (`no_compte`) REFERENCES `compte` (`no_compte`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; \ No newline at end of file diff --git a/scripts/upgrade b/scripts/upgrade index 57542ea..f938b44 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -40,6 +40,17 @@ chown -R $app:www-data "$install_dir" pushd "$install_dir" ynh_exec_warn_less mv ./www_data/* . ynh_exec_warn_less mv /tmp/config.php . + + ynh_script_progression --message="Checking if a database migration is needed" + if ynh_compare_current_package_version --comparison le --version 7.0~ynh5 + then + ynh_script_progression --message="Database migration required, migrating" + ynh_add_config --template="../conf/migrate_7.0.5.sql" --destination="$install_dir/migrate.sql" + ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < migrate.sql + else + ynh_script_progression --message="Database migration not required" + fi + popd #=================================================