diff options
author | Matthew Heon <matthew.heon@gmail.com> | 2017-11-29 14:37:35 -0500 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2017-11-30 18:05:56 +0000 |
commit | 7eb5ce940c8145ef57920ef90b52857e9716ffc9 (patch) | |
tree | 0a9d90a27d87820f8c08c802ad6c0a1859e614fb /libpod/sql_state.go | |
parent | ed5d686076b9b01ce5da7ed0bd37faeed216ae75 (diff) | |
download | podman-7eb5ce940c8145ef57920ef90b52857e9716ffc9.tar.gz podman-7eb5ce940c8145ef57920ef90b52857e9716ffc9.tar.bz2 podman-7eb5ce940c8145ef57920ef90b52857e9716ffc9.zip |
Add schema validation to DB
This ensures we don't open a DB with an earlier schema or a
config that differs from ours
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Closes: #86
Approved by: rhatdan
Diffstat (limited to 'libpod/sql_state.go')
-rw-r--r-- | libpod/sql_state.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/libpod/sql_state.go b/libpod/sql_state.go index 8b18a8959..7c2061fca 100644 --- a/libpod/sql_state.go +++ b/libpod/sql_state.go @@ -14,6 +14,10 @@ import ( _ "github.com/mattn/go-sqlite3" ) +// DBSchema is the current DB schema version +// Increments every time a change is made to the database's tables +const DBSchema = 1 + // SQLState is a state implementation backed by a persistent SQLite3 database type SQLState struct { db *sql.DB @@ -69,6 +73,11 @@ func NewSQLState(dbPath, lockPath, specsDir string, runtime *Runtime) (State, er return nil, err } + // Ensure that the database matches our config + if err := checkDB(db, runtime); err != nil { + return nil, err + } + state.db = db state.valid = true |