Commit 857d967c authored by Aurélien Dunand's avatar Aurélien Dunand Committed by Seblu

Update repository version

Old repository are still usable.
Database changes:
Add is_min_version and image_format in image table.
Add repository table which contain database uuid, version and motd.
Signed-off-by: Seblu's avatarSébastien Luttringer <sebastien.luttringer@smartjog.com>
parent 56a216b0
......@@ -20,8 +20,10 @@
Database stuff
'''
import math
import os
import sqlite3
import uuid
import installsystems.tools as istools
import installsystems.template as istemplate
from installsystems.tarball import Tarball
......@@ -34,6 +36,8 @@ class Database(object):
It needs to be local cause of sqlite3 which need to open a file
'''
version = 2.0
@classmethod
def create(cls, path):
arrow("Creating repository database")
......@@ -47,6 +51,8 @@ class Database(object):
conn = sqlite3.connect(path, isolation_level=None)
conn.execute("PRAGMA foreign_keys = ON")
conn.executescript(istemplate.createdb)
conn.execute("INSERT INTO repository values (?,?,?)",
(str(uuid.uuid4()), Database.version, "",))
conn.commit()
conn.close()
except Exception as e:
......@@ -64,16 +70,15 @@ class Database(object):
self.conn.execute("PRAGMA foreign_keys = ON")
# get database version
try:
r = self.ask("SELECT value FROM misc WHERE key = 'version'").fetchone()
r = self.ask("SELECT version FROM repository").fetchone()
if r is None:
raise TypeError()
self.version = float(r[0])
except:
self.version = 1.0
# we only support database v1
if self.version >= 2.0:
debug(u"Invalid database format: %s" % self.version)
raise ISError("Invalid database format")
if math.floor(self.version) >= math.floor(Database.version) + 1.0:
raise ISWarning(u"New database format (%s), please upgrade "
"your Installsystems version" % self.version)
# we make a query to be sure format is valid
try:
self.ask("SELECT * FROM image")
......
This diff is collapsed.
......@@ -90,12 +90,18 @@ CREATE TABLE image (md5 TEXT NOT NULL PRIMARY KEY,
author TEXT,
description TEXT,
size INTEGER NOT NULL,
is_min_version INTEGER NOT NULL,
format INTEGER NOT NULL,
UNIQUE(name, version));
CREATE TABLE payload (md5 TEXT NOT NULL,
image_md5 TEXT NOT NULL REFERENCES image(md5),
name TEXT NOT NULL,
isdir INTEGER NOT NULL,
size INTEGER NOT NULL,
PRIMARY KEY(md5, image_md5));
image_md5 TEXT NOT NULL REFERENCES image(md5),
name TEXT NOT NULL,
isdir INTEGER NOT NULL,
size INTEGER NOT NULL,
PRIMARY KEY(md5, image_md5));
CREATE TABLE repository (uuid TEXT NOT NULL PRIMARY KEY,
version FLOAT NOT NULL,
motd TEXT NOT NULL);
"""
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment