add more migration code, rename codegen template

This commit is contained in:
xenia 2020-11-13 23:44:42 -05:00
parent ed503363a4
commit 3dae54ad85
4 changed files with 14 additions and 1 deletions

View File

@ -39,7 +39,7 @@
;; and faster) ;; and faster)
;; ok gamer move time ;; ok gamer move time
(define-runtime-path codegen-template "codegen.template") (define-runtime-path codegen-template "codegen.rktc")
(define (pattern-codegen pattern mode pp-start pp-end) (define (pattern-codegen pattern mode pp-start pp-end)
(eval-template (eval-template
`(file ,(path->string codegen-template)) `(file ,(path->string codegen-template))

View File

@ -5,7 +5,15 @@
-- @up { -- @up {
create table tasks (id integer primary key, name text not null, manifest blob not null); create table tasks (id integer primary key, name text not null, manifest blob not null);
-- } -- }
-- @up {
create table nodes (id integer primary key, name text not null,
type text check(type in ("client", "agent")) not null,
secret blob(32) not null)
-- }
-- @down {
drop table nodes;
-- }
-- @down { -- @down {
drop table tasks; drop table tasks;
-- } -- }

View File

@ -39,6 +39,9 @@
;; this allows the server to be capable of migrating itself ;; this allows the server to be capable of migrating itself
(define (migrate-server-db [db (current-db)]) (define (migrate-server-db [db (current-db)])
;; these are the steps taken by the north cli tool (it's a bit verbose but at least it's all
;; programmatically accessible...)
;; i also use a runtime path to be a bit more robust
(define base (path->migration migrations-dir)) (define base (path->migration migrations-dir))
(define adapter (sqlite-adapter db)) (define adapter (sqlite-adapter db))
(adapter-init adapter) (adapter-init adapter)
@ -50,6 +53,8 @@
(adapter-apply! adapter (migration-revision migration) (migration-up migration))) (adapter-apply! adapter (migration-revision migration) (migration-up migration)))
(void)) (void))
(migrate-server-db (open-server-db 'create))
(define (with-server-db proc) (define (with-server-db proc)
(parameterize ([current-db (open-server-db)]) (parameterize ([current-db (open-server-db)])
(proc) (proc)