Skip to content

Commit 4a946e6

Browse files
authored
Release / Create SQL migration script for new version (geonetwork#7395)
* Release / Create SQL migration script for new version If the target version SQL migration do not exist, create it. * Update update-version.sh * Update database_migration.xml * Doc / Indicate utilities required for making a release
1 parent a7c0dee commit 4a946e6

File tree

2 files changed

+40
-42
lines changed

2 files changed

+40
-42
lines changed

docs/manual/docs/contributing/doing-a-release.md

+4-38
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ This section documents the steps followed by the development team to do a new re
44

55
Once the release branch has been thoroughly tested and is stable a release can be made.
66

7+
The following script can be used on Linux and Mac. For this a running build environment is needed
8+
with the following utilities: sed, xmlstarlet and sftp.
9+
10+
711
1. Prepare the release
812

913
``` shell
@@ -90,25 +94,6 @@ Once the release branch has been thoroughly tested and is stable a release can b
9094
# Set version number to SNAPSHOT
9195
./update-version.sh $newversion $nextversion
9296
93-
# Add SQL migration step for the next version
94-
mkdir web/src/main/webapp/WEB-INF/classes/setup/sql/migrate/v424
95-
cat <<EOF > web/src/main/webapp/WEB-INF/classes/setup/sql/migrate/v424/migrate-default.sql
96-
UPDATE Settings SET value='4.2.4' WHERE name='system/platform/version';
97-
UPDATE Settings SET value='SNAPSHOT' WHERE name='system/platform/subVersion';
98-
EOF
99-
vi web/src/main/webResources/WEB-INF/config-db/database_migration.xml
100-
```
101-
102-
In `WEB-INF/config-db/database_migration.xml` add an entry for the new version in the 2 steps:
103-
104-
``` xml
105-
<entry key="3.12.2">
106-
<list>
107-
<value>WEB-INF/classes/setup/sql/migrate/v3122/migrate-</value>
108-
</list>
109-
</entry>
110-
```
111-
11297
``` shell
11398
git add .
11499
git commit -m "Update version to $nextversion"
@@ -180,25 +165,6 @@ Once the release branch has been thoroughly tested and is stable a release can b
180165
./update-version.sh $currentversion $nextMajorVersion
181166
```
182167
183-
In the following folder `web/src/main/webapp/WEB-INF/classes/setup/sql/migrate` create `v370` folder.
184-
185-
In this folder create a `migrate-default.sql` with the following content:
186-
187-
``` sql
188-
UPDATE Settings SET value='3.7.0' WHERE name='system/platform/version';
189-
UPDATE Settings SET value='SNAPSHOT' WHERE name='system/platform/subVersion';
190-
```
191-
192-
In `web/src/main/webResources/WEB-INF/config-db/database_migration.xml` add the following for the migration to call the migration script:
193-
194-
``` xml
195-
<entry key="3.7.0">
196-
<list>
197-
<value>WEB-INF/classes/setup/sql/migrate/v370/migrate-</value>
198-
</list>
199-
</entry>
200-
```
201-
202168
Commit the new version
203169
204170
``` shell

update-version.sh

+36-4
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,43 @@ echo
103103

104104
# Update SQL - needs improvements
105105
echo 'SQL script'
106-
sed $sedopt "s/'system\/platform\/version', '.*', 0/'system\/platform\/version', '${new_version_main}', 0/g" web/src/main/webapp/WEB-INF/classes/setup/sql/data/data-db-default.sql
107-
sed $sedopt "s/'system\/platform\/subVersion', '.*', 0/'system\/platform\/subVersion', '${sub_version}', 0/g" web/src/main/webapp/WEB-INF/classes/setup/sql/data/data-db-default.sql
106+
echo ' * Set version in initial data'
107+
sqlscriptfolder=web/src/main/webapp/WEB-INF/classes/setup/sql
108+
sed $sedopt "s/'system\/platform\/version', '.*', 0/'system\/platform\/version', '${new_version_main}', 0/g" $sqlscriptfolder/data/data-db-default.sql
109+
sed $sedopt "s/'system\/platform\/subVersion', '.*', 0/'system\/platform\/subVersion', '${sub_version}', 0/g" $sqlscriptfolder/data/data-db-default.sql
108110

109-
find . -wholename *v${new_version_main_nopoint//[.]/}/migrate-default.sql -exec sed $sedopt "s/value='${version}' WHERE name='system\/platform\/version'/value='${new_version_main}' WHERE name='system\/platform\/version'/g" {} \;
110-
find . -wholename *v${new_version_main_nopoint//[.]/}/migrate-default.sql -exec sed $sedopt "s/value='.*' WHERE name='system\/platform\/subVersion'/value='${sub_version}' WHERE name='system\/platform\/subVersion'/g" {} \;
111+
112+
113+
echo " * Set version in migration script v${new_version_main_nopoint}/migrate-default.sql"
114+
115+
sqlmigrationfile=$sqlscriptfolder/migrate/v${new_version_main_nopoint}/migrate-default.sql
116+
117+
if [ -f "$sqlmigrationfile" ]; then
118+
echo " * Updating version in existing migration script $sqlmigrationfile."
119+
sed $sedopt "s/value='${version}' WHERE name='system\/platform\/version'/value='${new_version_main}' WHERE name='system\/platform\/version'/g" $sqlmigrationfile
120+
sed $sedopt "s/value='.*' WHERE name='system\/platform\/subVersion'/value='${sub_version}' WHERE name='system\/platform\/subVersion'/g" $sqlmigrationfile
121+
else
122+
echo " * Creating migration script $sqlmigrationfile."
123+
mkdir $sqlscriptfolder/migrate/v${new_version_main_nopoint}
124+
cat <<EOF > $sqlmigrationfile
125+
UPDATE Settings SET value='${new_version_main}' WHERE name='system/platform/version';
126+
UPDATE Settings SET value='${sub_version}' WHERE name='system/platform/subVersion';
127+
EOF
128+
fi
129+
130+
131+
sqlmigrationconfig=web/src/main/webResources/WEB-INF/config-db/database_migration.xml
132+
if hash xmlstarlet 2>/dev/null; then
133+
xmlstarlet ed -L \
134+
-s "//*[@id='dataMigrationMap' and not(*[local-name() = 'entry' and @key ='${new_version_main}'])]" -t elem -n "newentry" \
135+
-i //newentry -t attr -n "key" -v "${new_version_main}" \
136+
-s //newentry -t elem -n "list" \
137+
-s //newentry/list -t elem -n "value" -v "WEB-INF/classes/setup/sql/migrate/v${new_version_main_nopoint}/migrate-" \
138+
-r //newentry -v entry \
139+
$sqlmigrationconfig
140+
else
141+
echo " * WARNING: Can't update automatically $sqlmigrationconfig. Install xmlstarlet utility or update file manually."
142+
fi
111143

112144
# Update version pom files
113145
mvn versions:set-property -Dproperty=gn.project.version -DnewVersion=${new_version}

0 commit comments

Comments
 (0)