mirror of
https://gitea.osmocom.org/cellular-infrastructure/osmo-hlr.git
synced 2025-10-23 08:22:12 +00:00
If a database file is missing, osmo-hlr creates it, as is the default sqlite3 API behavior -- before this patch, that db file is created, but lacks useful tables. Actually also create initial tables in it, as osmo-nitb did. In effect, the 'vty-test' target in tests/Makefile.am no longer needs to create a database manually. (The 'ctrl-test' still does, because it also wants to add subscriber data on top of the bare tables.) Note: it could be desirable to bail if the desired database file does not exist. That is however a different semantic from this patch; this is not changing the fact that a db file is created, this just creates a usable one. Note: I am about to add osmo-hlr-db-tool to do database migration from osmo-nitb. For that, it is desirable to bootstrap a usable database, which is the core reason for this patch. Don't plainly duplicate hlr.sql to .c, but create db_bootstrap.h as a BUILT_SOURCE from reading in sql/hlr.sql and mangling via sed to a list of SQL statement strings. On each db_open(), run this bootstrap sequence. In sql/hlr.sql, these tweaks are necessary: * Add 'IF NOT EXISTS' to 'CREATE TABLE', so that the bootstrap sequence can be run on an already bootstrapped db. * Drop the final comment at the bottom, which ended up being an empty SQL statement and causing sqlite3 API errors, seemed to have no purpose anyway. Note: by composing the statement strings as multiline and including the SQL comments, sqlite3 actually retains the comments contained in table definitions and prints them back during 'sqlite3 hlr.db .dump'. Change-Id: If77dbbfe1af3e66aaec91cb6295b687f37678636
71 lines
2.1 KiB
SQL
71 lines
2.1 KiB
SQL
--modelled roughly after TS 23.008 version 13.3.0
|
|
|
|
CREATE TABLE IF NOT EXISTS subscriber (
|
|
id INTEGER PRIMARY KEY,
|
|
-- Chapter 2.1.1.1
|
|
imsi VARCHAR(15) UNIQUE NOT NULL,
|
|
-- Chapter 2.1.2
|
|
msisdn VARCHAR(15) UNIQUE,
|
|
-- Chapter 2.2.3: Most recent / current IMEI
|
|
imeisv VARCHAR,
|
|
-- Chapter 2.4.5
|
|
vlr_number VARCHAR(15),
|
|
-- Chapter 2.4.6
|
|
hlr_number VARCHAR(15),
|
|
-- Chapter 2.4.8.1
|
|
sgsn_number VARCHAR(15),
|
|
-- Chapter 2.13.10
|
|
sgsn_address VARCHAR,
|
|
-- Chapter 2.4.8.2
|
|
ggsn_number VARCHAR(15),
|
|
-- Chapter 2.4.9.2
|
|
gmlc_number VARCHAR(15),
|
|
-- Chapter 2.4.23
|
|
smsc_number VARCHAR(15),
|
|
-- Chapter 2.4.24
|
|
periodic_lu_tmr INTEGER,
|
|
-- Chapter 2.13.115
|
|
periodic_rau_tau_tmr INTEGER,
|
|
-- Chapter 2.1.1.2: network access mode
|
|
nam_cs BOOLEAN NOT NULL DEFAULT 1,
|
|
nam_ps BOOLEAN NOT NULL DEFAULT 1,
|
|
-- Chapter 2.1.8
|
|
lmsi INTEGER,
|
|
|
|
-- The below purged flags might not even be stored non-volatile,
|
|
-- refer to TS 23.012 Chapter 3.6.1.4
|
|
-- Chapter 2.7.5
|
|
ms_purged_cs BOOLEAN NOT NULL DEFAULT 0,
|
|
-- Chapter 2.7.6
|
|
ms_purged_ps BOOLEAN NOT NULL DEFAULT 0
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS subscriber_apn (
|
|
subscriber_id INTEGER, -- subscriber.id
|
|
apn VARCHAR(256) NOT NULL
|
|
);
|
|
|
|
-- Chapter 2.1.3
|
|
CREATE TABLE IF NOT EXISTS subscriber_multi_msisdn (
|
|
subscriber_id INTEGER, -- subscriber.id
|
|
msisdn VARCHAR(15) NOT NULL
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS 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 (
|
|
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)
|
|
op VARCHAR(32), -- hex string: operator's secret key (128bit)
|
|
opc VARCHAR(32), -- hex string: derived from OP and K (128bit)
|
|
sqn INTEGER NOT NULL DEFAULT 0, -- sequence number of key usage
|
|
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);
|