diff --git a/internal/repository/migration.go b/internal/repository/migration.go index c0693da..fb78170 100644 --- a/internal/repository/migration.go +++ b/internal/repository/migration.go @@ -16,7 +16,7 @@ import ( "github.com/golang-migrate/migrate/v4/source/iofs" ) -const Version uint = 9 +const Version uint = 10 //go:embed migrations/* var migrationFiles embed.FS diff --git a/internal/repository/migrations/sqlite3/10_node-table.down.sql b/internal/repository/migrations/sqlite3/10_node-table.down.sql new file mode 100644 index 0000000..9119a5a --- /dev/null +++ b/internal/repository/migrations/sqlite3/10_node-table.down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS node; diff --git a/internal/repository/migrations/sqlite3/10_node-table.up.sql b/internal/repository/migrations/sqlite3/10_node-table.up.sql new file mode 100644 index 0000000..e4cb6c0 --- /dev/null +++ b/internal/repository/migrations/sqlite3/10_node-table.up.sql @@ -0,0 +1,17 @@ +CREATE TABLE "node" ( + id INTEGER PRIMARY KEY, + hostname VARCHAR(255) NOT NULL, + cluster VARCHAR(255) NOT NULL, + subcluster VARCHAR(255) NOT NULL, + node_state VARCHAR(255) NOT NULL + CHECK (job_state IN ( + 'allocated', 'reserved', 'idle', 'mixed', + 'down', 'unknown' + )), + health_state VARCHAR(255) NOT NULL + CHECK (job_state IN ( + 'full', 'partial', 'failed' + )), + meta_data TEXT, -- JSON + UNIQUE (hostname, cluster) +); diff --git a/pkg/schema/node.go b/pkg/schema/node.go new file mode 100644 index 0000000..3e2bbfb --- /dev/null +++ b/pkg/schema/node.go @@ -0,0 +1,35 @@ +// Copyright (C) NHR@FAU, University Erlangen-Nuremberg. +// All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. +package schema + +type NodeState string + +const ( + NodeStateAllocated NodeState = "allocated" + NodeStateReserved NodeState = "reserved" + NodeStateIdle NodeState = "idle" + NodeStateMixed NodeState = "mixed" + NodeStateDown NodeState = "down" + NodeStateUnknown NodeState = "unknown" +) + +type MonitoringState string + +const ( + MonitoringStateFull MonitoringState = "full" + MonitoringStatePartial MonitoringState = "partial" + MonitoringStateFailed MonitoringState = "failed" +) + +type Node struct { + ID int64 `json:"id" db:"id"` + Hostname string `json:"hostname" db:"hostname" example:"fritz"` + Cluster string `json:"cluster" db:"cluster" example:"fritz"` + SubCluster string `json:"subCluster" db:"subcluster" example:"main"` + NodeState NodeState `json:"nodeState" db:"node_state" example:"completed" enums:"completed,failed,cancelled,stopped,timeout,out_of_memory"` + HealthState MonitoringState `json:"healthState" db:"health_state" example:"completed" enums:"completed,failed,cancelled,stopped,timeout,out_of_memory"` + RawMetaData []byte `json:"-" db:"meta_data"` + MetaData map[string]string `json:"metaData"` +}