Add SQLite support
This commit is contained in:
parent
0a108739d4
commit
badcad8d70
3
Makefile
3
Makefile
|
@ -12,5 +12,8 @@ build:
|
|||
frontend/build/...
|
||||
go build -tags=binassets -o backend/build/cmdui backend/main.go
|
||||
|
||||
create_db:
|
||||
sqlite3 backend/data/cmdui.db < backend/schema_sqlite.sql
|
||||
|
||||
cloc:
|
||||
cloc --exclude-dir=vendor,build,node_modules .
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
vendor
|
||||
build
|
||||
data
|
||||
api/assets/bindata_assetfs.go
|
||||
config.toml
|
||||
|
|
|
@ -43,6 +43,12 @@
|
|||
revision = "8c199fb6259ffc1af525cc3ad52ee60ba8359669"
|
||||
version = "v1.1"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/mattn/go-sqlite3"
|
||||
packages = ["."]
|
||||
revision = "5160b48509cf5c877bc22c11c373f8c7738cdb38"
|
||||
version = "v1.3.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/satori/go.uuid"
|
||||
packages = ["."]
|
||||
|
@ -55,6 +61,12 @@
|
|||
packages = ["ssh/terminal"]
|
||||
revision = "2509b142fb2b797aa7587dad548f113b2c0f20ce"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/net"
|
||||
packages = ["context"]
|
||||
revision = "01c190206fbdffa42f334f4b2bf2220f50e64920"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/sys"
|
||||
|
@ -64,6 +76,6 @@
|
|||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "6c201fcf68612a8ad33e6e620125ca3a88e8e4c34d7acc2b5ed0f452c3457a3f"
|
||||
inputs-digest = "4db9692ffa1d302e9cb342da138f0606a659403be6d1131f8689b874610a1eff"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
log_dir = "/var/log/commands"
|
||||
log_dir = "data/logs"
|
||||
|
||||
[commands]
|
||||
base_path = "/usr/local/bin/runner"
|
||||
config_command = "/usr/local/bin/runner_commands --export=json"
|
||||
|
||||
[database]
|
||||
driver = "mysql"
|
||||
spec = "root:@(localhost:3306)/commands?charset=utf8mb4&parseTime=true"
|
||||
driver = "sqlite3"
|
||||
spec = "data/cmdui.db"
|
||||
|
||||
# MySQL example
|
||||
# driver = "mysql"
|
||||
# spec = "root:@(localhost:3306)/commands?charset=utf8mb4&parseTime=true"
|
||||
|
||||
[server]
|
||||
host = "http://127.0.0.1"
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/jmoiron/sqlx"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
|
||||
"github.com/localhots/cmdui/backend/config"
|
||||
|
|
|
@ -127,15 +127,8 @@ func (r *Job) Create() error {
|
|||
r.State = string(JobStateCreated)
|
||||
|
||||
_, err := db.NamedExec(`
|
||||
INSERT INTO jobs
|
||||
SET
|
||||
id = :id,
|
||||
command = :command,
|
||||
args = :args,
|
||||
flags = :flags,
|
||||
user_id = :user_id,
|
||||
state = :state,
|
||||
created_at = :created_at
|
||||
INSERT INTO jobs (id, command, args, flags, user_id, state, created_at)
|
||||
VALUES (:id, :command, :args, :flags, :user_id, :state, :created_at)
|
||||
`, r)
|
||||
if err != nil {
|
||||
return errors.Annotate(err, "Failed to create a job")
|
||||
|
|
|
@ -42,12 +42,8 @@ func FindSession(id string) (*Session, error) {
|
|||
|
||||
func (s Session) Create() error {
|
||||
_, err := db.NamedExec(`
|
||||
INSERT INTO sessions
|
||||
SET
|
||||
id = :id,
|
||||
user_id = :user_id,
|
||||
created_at = :created_at,
|
||||
expires_at = :expires_at
|
||||
INSERT INTO sessions (id, user_id, created_at, expires_at)
|
||||
VALUES (:id, :user_id, :created_at, :expires_at)
|
||||
`, s)
|
||||
if err != nil {
|
||||
return errors.Annotate(err, "Failed to create a session")
|
||||
|
|
|
@ -71,13 +71,8 @@ func findUser(query string, args ...interface{}) (*User, error) {
|
|||
|
||||
func (u User) Create() error {
|
||||
_, err := db.NamedExec(`
|
||||
INSERT INTO users
|
||||
SET
|
||||
id = :id,
|
||||
github_id = :github_id,
|
||||
github_login = :github_login,
|
||||
github_name = :github_name,
|
||||
github_picture = :github_picture
|
||||
INSERT INTO users (id, github_id, github_login, github_name, github_picture)
|
||||
VALUES (:id, :github_id, :github_login, :github_name, :github_picture)
|
||||
`, u)
|
||||
if err != nil {
|
||||
return errors.Annotate(err, "Failed to create a user")
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
CREATE TABLE `jobs` (
|
||||
`id` char(36) NOT NULL DEFAULT '',
|
||||
`command` varchar(255) NOT NULL DEFAULT '',
|
||||
`id` char(36) NOT NULL,
|
||||
`command` varchar(255) NOT NULL,
|
||||
`args` text NOT NULL,
|
||||
`flags` text NOT NULL,
|
||||
`user_id` char(36) DEFAULT NULL,
|
||||
|
@ -12,15 +12,15 @@ CREATE TABLE `jobs` (
|
|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE `sessions` (
|
||||
`id` char(36) NOT NULL DEFAULT '',
|
||||
`user_id` char(36) NOT NULL DEFAULT '',
|
||||
`id` char(36) NOT NULL,
|
||||
`user_id` char(36) NOT NULL,
|
||||
`created_at` datetime NOT NULL,
|
||||
`expires_at` datetime NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE `users` (
|
||||
`id` char(36) NOT NULL DEFAULT '',
|
||||
`id` char(36) NOT NULL,
|
||||
`github_id` int(11) unsigned NOT NULL,
|
||||
`github_login` varchar(255) NOT NULL DEFAULT '',
|
||||
`github_name` varchar(255) NOT NULL DEFAULT '',
|
|
@ -0,0 +1,29 @@
|
|||
CREATE TABLE `jobs` (
|
||||
`id` CHAR(36) NOT NULL PRIMARY KEY,
|
||||
`command` VARCHAR(255) NOT NULL,
|
||||
`args` TEXT NOT NULL,
|
||||
`flags` TEXT NOT NULL,
|
||||
`user_id` CHAR(36) DEFAULT NULL,
|
||||
`state` VARCHAR(20) NOT NULL,
|
||||
`created_at` DATETIME DEFAULT NULL,
|
||||
`started_at` DATETIME DEFAULT NULL,
|
||||
`finished_at` DATETIME DEFAULT NULL
|
||||
);
|
||||
-- PRAGMA table_info(jobs);
|
||||
|
||||
CREATE TABLE `sessions` (
|
||||
`id` CHAR(36) NOT NULL PRIMARY KEY,
|
||||
`user_id` CHAR(36) NOT NULL,
|
||||
`created_at` DATETIME NOT NULL,
|
||||
`expires_at` DATETIME NOT NULL
|
||||
);
|
||||
-- PRAGMA table_info(sessions);
|
||||
|
||||
CREATE TABLE `users` (
|
||||
`id` CHAR(36) NOT NULL PRIMARY KEY,
|
||||
`github_id` UNSIGNED BIGINT NOT NULL,
|
||||
`github_login` VARCHAR(255) NOT NULL DEFAULT '',
|
||||
`github_name` VARCHAR(255) NOT NULL DEFAULT '',
|
||||
`github_picture` VARCHAR(255) NOT NULL DEFAULT ''
|
||||
);
|
||||
-- PRAGMA table_info(users);
|
Loading…
Reference in New Issue