Skip to content

Commit

Permalink
Split update and downgrade version
Browse files Browse the repository at this point in the history
During an update, it is not possible to run the downgrade scripts until
the release has been tagged, but the update scripts can be run. This
means that we need to split the previous version into two different
fields: one for running the update tests and one for running the
downgrade tests.
  • Loading branch information
mkindahl committed Jul 1, 2021
1 parent cb7fffe commit a58ebdb
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/update-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ jobs:
id: read_version
shell: perl -n {0} version.config
run: |
print "::set-output name=from_version::$1\n" if /update_from_version\s*=\s*(\S+)/
print "::set-output name=to_version::$1\n" if /downgrade_to_version\s*=\s*(\S+)/
- name: Downgrade tests ${{ matrix.pg }}
env:
UPDATE_FROM_TAG: ${{ steps.read_version.outputs.from_version }}-pg${{ matrix.pg_major }}
UPDATE_FROM_TAG: ${{ steps.read_version.outputs.to_version }}-pg${{ matrix.pg_major }}
TEST_VERSION: v7
run: bash scripts/test_downgrade_from_tag.sh

Expand Down
46 changes: 28 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,40 @@ endfunction()

configure_file("version.config" "version.config" COPYONLY)
file(READ version.config VERSION_CONFIG)
set(VERSION_REGEX
"version[\t ]*=[\t ]*([0-9]+\\.[0-9]+\\.*[0-9]*)([-]([a-z]+[0-9]*))?([-](dev))?\r?\nupdate_from_version[\t ]*=[\t ]*([0-9]+\\.[0-9]+\\.*[0-9]*([-]([a-z]+[0-9]*))?)*(\r?\n)*$"

if(VERSION_CONFIG
MATCHES
"(^|.*[^a-z])version[\t ]*=[\t ]*([0-9]+\\.[0-9]+\\.*[0-9]*)-([a-z]+[0-9]*|dev)?.*"
)
set(VERSION ${CMAKE_MATCH_2})
if(CMAKE_MATCH_3)
set(PROJECT_VERSION_MOD ${CMAKE_MATCH_2}-${CMAKE_MATCH_3})
else()
set(PROJECT_VERSION_MOD ${CMAKE_MATCH_2})
endif()
endif()

if(NOT (${VERSION_CONFIG} MATCHES ${VERSION_REGEX}))
message(FATAL_ERROR "Cannot read version from version.config")
if(VERSION_CONFIG
MATCHES
".*update_from_version[\t ]*=[\t ]*([0-9]+\\.[0-9]+\\.[0-9]+(-[a-z]+[0-9]*)?).*"
)
set(UPDATE_FROM_VERSION ${CMAKE_MATCH_1})
endif()

if(VERSION_CONFIG
MATCHES
".*downgrade_to_version[\t ]*=[\t ]*([0-9]+\\.[0-9]+\\.[0-9]+(-[a-z]+[0-9]*)?).*"
)
set(DOWNGRADE_TO_VERSION ${CMAKE_MATCH_1})
endif()

message(STATUS "VERSION: ${VERSION}")
message(STATUS "PROJECT_VERSION_MOD: ${PROJECT_VERSION_MOD}")
message(STATUS "UPDATE_FROM_VERSION: ${UPDATE_FROM_VERSION}")
message(STATUS "DOWNGRADE_TO_VERSION: ${DOWNGRADE_TO_VERSION}")

# a hack to avoid change of SQL extschema variable
set(extschema "@extschema@")
set(VERSION ${CMAKE_MATCH_1})
set(VERSION_MOD ${CMAKE_MATCH_3})
set(VERSION_DEV ${CMAKE_MATCH_5})
set(UPDATE_FROM_VERSION ${CMAKE_MATCH_6})

if(VERSION_MOD AND VERSION_DEV)
set(PROJECT_VERSION_MOD ${VERSION}-${VERSION_MOD}-${VERSION_DEV})
elseif(VERSION_MOD)
set(PROJECT_VERSION_MOD ${VERSION}-${VERSION_MOD})
elseif(VERSION_DEV)
set(PROJECT_VERSION_MOD ${VERSION}-${VERSION_DEV})
else()
set(PROJECT_VERSION_MOD ${VERSION})
endif()

# Set project name, version, and language. Language needs to be set for compiler
# checks
Expand Down
8 changes: 4 additions & 4 deletions scripts/test_downgrade_from_tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ SCRIPT_DIR=$(dirname $0)
BASE_DIR=${PWD}/${SCRIPT_DIR}/..
WITH_SUPERUSER=true # Update tests have superuser privileges when running tests.
TEST_VERSION=${TEST_VERSION:-v2}
TEST_TMPDIR=${TEST_TMPDIR:-$(mktemp -d 2>/dev/null || mktemp -d -t 'timescaledb_update_test' || mkdir -p /tmp/${RANDOM})}
TEST_TMPDIR=${TEST_TMPDIR:-$(mktemp -d 2>/dev/null || mktemp -d -t 'timescaledb_downgrade_test' || mkdir -p /tmp/${RANDOM})}
UPDATE_PG_PORT=${UPDATE_PG_PORT:-6432}
CLEAN_PG_PORT=${CLEAN_PG_PORT:-6433}
PG_VERSION=${PG_VERSION:-12.0}
GIT_ID=$(git -C ${BASE_DIR} describe --dirty --always | sed -e "s|/|_|g")
UPDATE_FROM_IMAGE=${UPDATE_FROM_IMAGE:-timescale/timescaledb}
UPDATE_FROM_TAG=${UPDATE_FROM_TAG:-0.1.0}
UPDATE_TO_IMAGE=${UPDATE_TO_IMAGE:-update_test}
UPDATE_TO_IMAGE=${UPDATE_TO_IMAGE:-downgrade_test}
UPDATE_TO_TAG=${UPDATE_TO_TAG:-${GIT_ID}}
DO_CLEANUP=${DO_CLEANUP:-true}
PGOPTS="-v TEST_VERSION=${TEST_VERSION} -v TEST_REPAIR=${TEST_REPAIR} -v WITH_SUPERUSER=${WITH_SUPERUSER} -v WITH_ROLES=true -v WITH_CHUNK=true"
Expand Down Expand Up @@ -109,8 +109,8 @@ docker_pgtest() {

docker_pgdiff_all() {
local database=${2:-single}
diff_file1=update_test.restored.diff.${UPDATE_FROM_TAG}
diff_file2=update_test.clean.diff.${UPDATE_FROM_TAG}
diff_file1=downgrade_test.restored.diff.${UPDATE_FROM_TAG}
diff_file2=downgrade_test.clean.diff.${UPDATE_FROM_TAG}
docker_pgtest ${CONTAINER_UPDATED} $1 $database
docker_pgtest ${CONTAINER_CLEAN_RESTORE} $1 $database
docker_pgtest ${CONTAINER_CLEAN_RERUN} $1 $database
Expand Down
2 changes: 1 addition & 1 deletion sql/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ else()
SOURCE_VERSION
${PROJECT_VERSION_MOD}
TARGET_VERSION
${UPDATE_FROM_VERSION}
${DOWNGRADE_TO_VERSION}
INPUT_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/updates
FILES
Expand Down
5 changes: 3 additions & 2 deletions sql/updates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ not to any other preceeding versions.

The source and target versions are found in be found in the file
`version.config` file in the root of the source tree, where `version`
is the source version and `update_from_version` is the target version.
is the source version and `downgrade_to_version` is the target
version. Note that we have a separate field for the downgrade.

A downgrade file consists of:
- A prolog that is retrieved from the target version.
Expand Down Expand Up @@ -116,7 +117,7 @@ script to the immediately preceeding version.
### When releasing a new version

When releasing a new version, please rename the file `reverse-dev.sql`
to `<version>--<update_from_version>.sql` and add that name to
to `<version>--<downgrade_to_version>.sql` and add that name to
`REV_FILES` variable in the `sql/CMakeLists.txt`. This will allow
generation of downgrade scripts for any version in that list, but it
is currently not added.
2 changes: 2 additions & 0 deletions version.config
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
version = 2.4.0-dev
update_from_version = 2.3.0
downgrade_to_version = 2.3.0

0 comments on commit a58ebdb

Please sign in to comment.