diff options
author | Stefan Sperling <ssperling@sysmocom.de> | 2018-11-27 12:10:45 +0100 |
---|---|---|
committer | Neels Hofmeyr <neels@hofmeyr.de> | 2018-12-04 14:13:28 +0100 |
commit | 8f3a7cce80955082daeb4372472a6dd94035200a (patch) | |
tree | 1ed68714d106cc75fd414a5f8508d6ec5ea9959b /sql | |
parent | a820ea1f67bab68136fbaae0108bb90c94b77b22 (diff) |
add database schema versioning to the HLR database
Make use of pragma user_version to store our database schema version.
The present schema is now identitifed as 'version 0', which is also
the default value for databases on which we never ran the statement
'pragma user_version' before.
Only bootstrap the database if it hasn't been bootstrapped yet.
Previously, bootstrap SQL statements ran every time osmo-hlr
opened the database, and any errors were being ignored in SQL.
Instead, we now first run a query which checks whether tables
already exist, and only create them if necessary.
This change will allow future schema updates to work properly.
Prepare for future schema upgrades by adding a new command-line
option which enables upgrades. This option defaults to 'false'
in order to avoid accidental upgrades.
Change-Id: I8aeaa9a404b622657cbc7138106f38aa6ad8d01b
Related: OS#2838
Diffstat (limited to 'sql')
-rw-r--r-- | sql/hlr.sql | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/sql/hlr.sql b/sql/hlr.sql index 80eb3e5..3499109 100644 --- a/sql/hlr.sql +++ b/sql/hlr.sql @@ -1,4 +1,4 @@ -CREATE TABLE IF NOT EXISTS subscriber ( +CREATE TABLE subscriber ( -- OsmoHLR's DB scheme is modelled roughly after TS 23.008 version 13.3.0 id INTEGER PRIMARY KEY, -- Chapter 2.1.1.1 @@ -39,24 +39,24 @@ CREATE TABLE IF NOT EXISTS subscriber ( ms_purged_ps BOOLEAN NOT NULL DEFAULT 0 ); -CREATE TABLE IF NOT EXISTS subscriber_apn ( +CREATE TABLE subscriber_apn ( subscriber_id INTEGER, -- subscriber.id apn VARCHAR(256) NOT NULL ); -CREATE TABLE IF NOT EXISTS subscriber_multi_msisdn ( +CREATE TABLE subscriber_multi_msisdn ( -- Chapter 2.1.3 subscriber_id INTEGER, -- subscriber.id msisdn VARCHAR(15) NOT NULL ); -CREATE TABLE IF NOT EXISTS auc_2g ( +CREATE TABLE auc_2g ( subscriber_id INTEGER PRIMARY KEY, -- subscriber.id algo_id_2g INTEGER NOT NULL, -- enum osmo_auth_algo value ki VARCHAR(32) NOT NULL -- hex string: subscriber's secret key (128bit) ); -CREATE TABLE IF NOT EXISTS auc_3g ( +CREATE TABLE auc_3g ( subscriber_id INTEGER PRIMARY KEY, -- subscriber.id algo_id_3g INTEGER NOT NULL, -- enum osmo_auth_algo value k VARCHAR(32) NOT NULL, -- hex string: subscriber's secret key (128bit) @@ -66,4 +66,7 @@ CREATE TABLE IF NOT EXISTS auc_3g ( ind_bitlen INTEGER NOT NULL DEFAULT 5 -- nr of index bits at lower SQN end ); -CREATE UNIQUE INDEX IF NOT EXISTS idx_subscr_imsi ON subscriber (imsi); +CREATE UNIQUE INDEX idx_subscr_imsi ON subscriber (imsi); + +-- Set HLR database schema version number +PRAGMA user_version = 0; |