diff options
author | Erich Eckner <git@eckner.net> | 2018-07-27 14:02:02 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2018-07-27 14:02:02 +0200 |
commit | 90cd0f30b198d41db3f73998983e4e9ba31a8d3c (patch) | |
tree | a365fce8795f764fec65646443c2bfe187a8244b /lib | |
parent | 462730feca527e84867030cb44a28253fd3ca683 (diff) | |
download | builder-90cd0f30b198d41db3f73998983e4e9ba31a8d3c.tar.xz |
lib/mysql-functions: mysql_update_versions_ordering() new
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/mysql-functions | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/mysql-functions b/lib/mysql-functions index a4cca4e..2ae5832 100755 --- a/lib/mysql-functions +++ b/lib/mysql-functions @@ -1142,3 +1142,44 @@ mysql_query_create_toolchain_order() { printf ' SELECT `toolchain_order`.`number`,`toolchain_order`.`pkgbase`' printf ' FROM `toolchain_order`;\n' } + +# mysql_update_versions_ordering +# calculate the correct ordering of `versions` entries +mysql_update_versions_ordering() { + ( # new shell is intentional + tmp_file=$(mktemp "${work_dir}/tmp.mysql-functions.mysql_update_versions_ordering.XXXXXX") + trap 'rm "${tmp_file}"' EXIT + { + printf 'SELECT ' + printf 'CONCAT(' + printf '`versions`.`epoch`,":",' + printf '`versions`.`version`' + printf '),' + printf '`versions`.`id`' + printf ' FROM `versions`;\n' + } | \ + mysql_run_query | \ + expand_version 1 | \ + sort -k1V,1 | \ + cat -n | \ + sed ' + s/^\s*\([0-9]\+\)\s\+\S\+\s\+\([0-9]\+\)$/\1\t\2/ + ' > \ + "${tmp_file}" + { + printf 'CREATE TEMPORARY TABLE `v`(' + printf '`id` BIGINT,' + printf '`order` BIGINT,' + printf 'PRIMARY KEY `id`(`id`)' + printf ');\n' + printf 'LOAD DATA LOCAL INFILE "%s" INTO TABLE `v`(`order`,`id`);\n' \ + "${tmp_file}" + printf 'UPDATE `versions`' + printf ' JOIN `v`' + printf ' ON `v`.`id`=`versions`.`id`' + printf ' SET `versions`.`order`=`v`.`order`;\n' + printf 'DROP TEMPORARY TABLE `v`;\n' + } | \ + mysql_run_query + ) +} |