mirror of https://notabug.org/mthl/cuirass.git
database: Use an external SQL schema.
parent
730832c2fb
commit
46c9d432ea
|
@ -14,6 +14,8 @@ nodist_pkgmodule_DATA = \
|
||||||
src/cuirass/config.scm \
|
src/cuirass/config.scm \
|
||||||
src/cuirass/config.go
|
src/cuirass/config.go
|
||||||
|
|
||||||
|
dist_pkgdata_DATA = src/schema.sql
|
||||||
|
|
||||||
TEST_EXTENSIONS = .scm .sh
|
TEST_EXTENSIONS = .scm .sh
|
||||||
AM_TESTS_ENVIRONMENT = \
|
AM_TESTS_ENVIRONMENT = \
|
||||||
env GUILE_AUTO_COMPILE='0' \
|
env GUILE_AUTO_COMPILE='0' \
|
||||||
|
|
|
@ -24,6 +24,9 @@ GUILE_LOAD_COMPILED_PATH="$abs_top_builddir/src${GUILE_LOAD_COMPILED_PATH:+:}$GU
|
||||||
GUILE_LOAD_PATH="$abs_top_builddir/src:$abs_top_srcdir/src${GUILE_LOAD_PATH:+:}$GUILE_LOAD_PATH"
|
GUILE_LOAD_PATH="$abs_top_builddir/src:$abs_top_srcdir/src${GUILE_LOAD_PATH:+:}$GUILE_LOAD_PATH"
|
||||||
export GUILE_LOAD_COMPILED_PATH GUILE_LOAD_PATH
|
export GUILE_LOAD_COMPILED_PATH GUILE_LOAD_PATH
|
||||||
|
|
||||||
|
CUIRASS_DATADIR="$abs_top_srcdir/src"
|
||||||
|
export CUIRASS_DATADIR
|
||||||
|
|
||||||
PATH="$abs_top_builddir/bin:$PATH"
|
PATH="$abs_top_builddir/bin:$PATH"
|
||||||
export PATH
|
export PATH
|
||||||
|
|
||||||
|
|
10
configure.ac
10
configure.ac
|
@ -8,11 +8,13 @@ AM_SILENT_RULES([yes]) # enables silent rules by default
|
||||||
|
|
||||||
AC_CANONICAL_HOST
|
AC_CANONICAL_HOST
|
||||||
|
|
||||||
# Prepare a version of $localstatedir that does not contain references to
|
# Prepare a version of installation directories that does not contain
|
||||||
# shell variables.
|
# references to shell variables.
|
||||||
expanded_prefix="`eval echo $prefix | sed -e "s|NONE|/usr/local|g"`"
|
expanded_prefix="`eval echo $prefix | sed -e "s|NONE|/usr/local|g"`"
|
||||||
expanded_localstatedir="`eval echo $localstatedir | sed -e "s|NONE|$expanded_prefix|g"`"
|
AC_SUBST([expanded_datadir],
|
||||||
AC_SUBST([expanded_localstatedir])
|
[`eval echo $datadir | sed -e "s|NONE|$expanded_prefix|g"`])
|
||||||
|
AC_SUBST([expanded_localstatedir],
|
||||||
|
[`eval echo $localstatedir | sed -e "s|NONE|$expanded_prefix|g"`])
|
||||||
|
|
||||||
PKG_CHECK_MODULES([GUILE], [guile-2.0 >= 2.0.7])
|
PKG_CHECK_MODULES([GUILE], [guile-2.0 >= 2.0.7])
|
||||||
AC_PATH_PROG([GUILE], [guile])
|
AC_PATH_PROG([GUILE], [guile])
|
||||||
|
|
|
@ -47,6 +47,10 @@
|
||||||
;; Define to the version of this package.
|
;; Define to the version of this package.
|
||||||
"@PACKAGE_VERSION@")
|
"@PACKAGE_VERSION@")
|
||||||
|
|
||||||
|
(define-public %datadir
|
||||||
|
;; Define to DATADIR without reference to '${prefix}'.
|
||||||
|
"@expanded_datadir@")
|
||||||
|
|
||||||
(define-public %localstatedir
|
(define-public %localstatedir
|
||||||
;; Define to LOCALSTATEDIR without reference to '${prefix}'.
|
;; Define to LOCALSTATEDIR without reference to '${prefix}'.
|
||||||
"@expanded_localstatedir@")
|
"@expanded_localstatedir@")
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
;;;; database.scm - store evaluation and build results
|
;;; database.scm -- store evaluation and build results
|
||||||
;;;
|
|
||||||
;;; Copyright © 2016 Mathieu Lirzin <mthl@gnu.org>
|
;;; Copyright © 2016 Mathieu Lirzin <mthl@gnu.org>
|
||||||
;;;
|
;;;
|
||||||
;;; This file is part of Cuirass.
|
;;; This file is part of Cuirass.
|
||||||
|
@ -18,8 +17,8 @@
|
||||||
;;; along with Cuirass. If not, see <http://www.gnu.org/licenses/>.
|
;;; along with Cuirass. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
(define-module (cuirass database)
|
(define-module (cuirass database)
|
||||||
#:use-module (cuirass base)
|
|
||||||
#:use-module (cuirass config)
|
#:use-module (cuirass config)
|
||||||
|
#:use-module (ice-9 rdelim)
|
||||||
#:use-module (sqlite3)
|
#:use-module (sqlite3)
|
||||||
#:export (;; Procedures.
|
#:export (;; Procedures.
|
||||||
db-init
|
db-init
|
||||||
|
@ -29,6 +28,7 @@
|
||||||
db-get-evaluation
|
db-get-evaluation
|
||||||
db-delete-evaluation
|
db-delete-evaluation
|
||||||
db-add-build-log
|
db-add-build-log
|
||||||
|
read-sql-file
|
||||||
;; Parameters.
|
;; Parameters.
|
||||||
%package-database
|
%package-database
|
||||||
;; Macros.
|
;; Macros.
|
||||||
|
@ -44,6 +44,24 @@
|
||||||
;; Define to the database file name of this package.
|
;; Define to the database file name of this package.
|
||||||
(make-parameter (string-append %localstatedir "/" %package ".db")))
|
(make-parameter (string-append %localstatedir "/" %package ".db")))
|
||||||
|
|
||||||
|
(define %package-schema-file
|
||||||
|
;; Define to the database schema file of this package.
|
||||||
|
(make-parameter (string-append (or (getenv "CUIRASS_DATADIR")
|
||||||
|
(string-append %datadir "/" %package))
|
||||||
|
"/schema.sql")))
|
||||||
|
|
||||||
|
(define (read-sql-file file-name)
|
||||||
|
"Return a list of string containing SQL instructions from FILE-NAME."
|
||||||
|
(call-with-input-file file-name
|
||||||
|
(λ (port)
|
||||||
|
(let loop ((insts '()))
|
||||||
|
(let ((inst (read-delimited ";" port 'concat)))
|
||||||
|
(if (or (eof-object? inst)
|
||||||
|
;; Don't cons the spaces after the last instructions.
|
||||||
|
(string-every char-whitespace? inst))
|
||||||
|
(reverse! insts)
|
||||||
|
(loop (cons inst insts))))))))
|
||||||
|
|
||||||
(define (db-init)
|
(define (db-init)
|
||||||
"Open the database to store and read jobs and builds informations. Return a
|
"Open the database to store and read jobs and builds informations. Return a
|
||||||
database object."
|
database object."
|
||||||
|
@ -53,29 +71,8 @@ database object."
|
||||||
(delete-file db-name))
|
(delete-file db-name))
|
||||||
(let ((db (sqlite-open db-name (logior SQLITE_OPEN_CREATE
|
(let ((db (sqlite-open db-name (logior SQLITE_OPEN_CREATE
|
||||||
SQLITE_OPEN_READWRITE))))
|
SQLITE_OPEN_READWRITE))))
|
||||||
(for-each (λ (sql) (sqlite-exec db sql))
|
(for-each (λ (sql) (false-if-exception (sqlite-exec db sql)))
|
||||||
'("PRAGMA foreign_keys=OFF;"
|
(read-sql-file (%package-schema-file)))
|
||||||
"BEGIN TRANSACTION;"
|
|
||||||
"COMMIT;"
|
|
||||||
"
|
|
||||||
CREATE TABLE job_spec (
|
|
||||||
name text not null,
|
|
||||||
url text not null,
|
|
||||||
branch text not null,
|
|
||||||
file text not null,
|
|
||||||
proc text not null,
|
|
||||||
arguments text not null,
|
|
||||||
primary key (name)
|
|
||||||
);"
|
|
||||||
"
|
|
||||||
CREATE TABLE build (
|
|
||||||
id integer primary key autoincrement not null,
|
|
||||||
job_spec text not null,
|
|
||||||
drv text not null,
|
|
||||||
log text,
|
|
||||||
output text
|
|
||||||
-- foreign key (job_spec) references job_spec(name)
|
|
||||||
);"))
|
|
||||||
db)))
|
db)))
|
||||||
|
|
||||||
(define (db-open)
|
(define (db-open)
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
create table job_spec (
|
||||||
|
name text not null,
|
||||||
|
url text not null,
|
||||||
|
branch text not null,
|
||||||
|
file text not null,
|
||||||
|
proc text not null,
|
||||||
|
arguments text not null,
|
||||||
|
primary key (name)
|
||||||
|
);
|
||||||
|
|
||||||
|
create table build (
|
||||||
|
id integer primary key autoincrement not null,
|
||||||
|
job_spec text not null,
|
||||||
|
drv text not null,
|
||||||
|
log text,
|
||||||
|
output text
|
||||||
|
-- foreign key (job_spec) references job_spec(name)
|
||||||
|
);
|
Loading…
Reference in New Issue