From 3dae54ad85f52bd9246b6cf2a9eabf4b9562bb0e Mon Sep 17 00:00:00 2001 From: haskal Date: Fri, 13 Nov 2020 23:44:42 -0500 Subject: [PATCH] add more migration code, rename codegen template --- crossfire/codegen.rkt | 2 +- crossfire/{codegen.template => codegen.rktc} | 0 ...dd-tasks-table.sql => 20201113-add-initial-tables.sql} | 8 ++++++++ crossfire/protocol.rkt | 5 +++++ 4 files changed, 14 insertions(+), 1 deletion(-) rename crossfire/{codegen.template => codegen.rktc} (100%) rename crossfire/migrations/{20201113-add-tasks-table.sql => 20201113-add-initial-tables.sql} (50%) diff --git a/crossfire/codegen.rkt b/crossfire/codegen.rkt index 5792b3b..bfb35df 100644 --- a/crossfire/codegen.rkt +++ b/crossfire/codegen.rkt @@ -39,7 +39,7 @@ ;; and faster) ;; 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) (eval-template `(file ,(path->string codegen-template)) diff --git a/crossfire/codegen.template b/crossfire/codegen.rktc similarity index 100% rename from crossfire/codegen.template rename to crossfire/codegen.rktc diff --git a/crossfire/migrations/20201113-add-tasks-table.sql b/crossfire/migrations/20201113-add-initial-tables.sql similarity index 50% rename from crossfire/migrations/20201113-add-tasks-table.sql rename to crossfire/migrations/20201113-add-initial-tables.sql index 8e5c295..c8abeee 100644 --- a/crossfire/migrations/20201113-add-tasks-table.sql +++ b/crossfire/migrations/20201113-add-initial-tables.sql @@ -5,7 +5,15 @@ -- @up { 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 { drop table tasks; -- } diff --git a/crossfire/protocol.rkt b/crossfire/protocol.rkt index 68f7951..4d4cf78 100644 --- a/crossfire/protocol.rkt +++ b/crossfire/protocol.rkt @@ -39,6 +39,9 @@ ;; this allows the server to be capable of migrating itself (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 adapter (sqlite-adapter db)) (adapter-init adapter) @@ -50,6 +53,8 @@ (adapter-apply! adapter (migration-revision migration) (migration-up migration))) (void)) +(migrate-server-db (open-server-db 'create)) + (define (with-server-db proc) (parameterize ([current-db (open-server-db)]) (proc)