From 3544ecb5f7efad12173f372ed66de7e343c22def Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 24 Aug 2025 00:51:34 +0200 Subject: [PATCH] Create jobs migrations --- .cish/push/matrix.sh | 4 ++++ .pg_format | 7 ++++++ api/go.mod | 4 ++-- api/job.go | 5 ++++ api/migrations/000001_jobs.down.sql | 10 ++++++++ api/migrations/000001_jobs.up.sql | 37 +++++++++++++++++++++++++++++ shell.nix | 3 +++ 7 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 .pg_format create mode 100644 api/job.go create mode 100644 api/migrations/000001_jobs.down.sql create mode 100644 api/migrations/000001_jobs.up.sql diff --git a/.cish/push/matrix.sh b/.cish/push/matrix.sh index e6e28d0..f2b09c5 100644 --- a/.cish/push/matrix.sh +++ b/.cish/push/matrix.sh @@ -2,6 +2,10 @@ cish start postgres +if [[ true ]]; then + true +fi + for job in v1.22.0 v1.0.0 titi; do cish run ../ex.sh --version=$job diff --git a/.pg_format b/.pg_format new file mode 100644 index 0000000..c9795ff --- /dev/null +++ b/.pg_format @@ -0,0 +1,7 @@ +tabs=1 +function-case=1 #lowercase +keyword-case=1 +type-case=1 +no-space-function=1 +keep-newline=1 +nogrouping=1 diff --git a/api/go.mod b/api/go.mod index 412a2c3..f3ec387 100644 --- a/api/go.mod +++ b/api/go.mod @@ -3,9 +3,11 @@ module github.com/zoriya/cish/api go 1.24.5 require ( + github.com/go-git/go-git/v6 v6.0.0-20250819122726-39261590f7f3 github.com/jackc/pgx/v5 v5.7.5 github.com/labstack/echo/v4 v4.13.4 github.com/ren3gadem4rm0t/github-hook-types-go v0.1.1 + github.com/spf13/viper v1.20.1 ) require ( @@ -18,7 +20,6 @@ require ( github.com/fsnotify/fsnotify v1.8.0 // indirect github.com/go-git/gcfg/v2 v2.0.2 // indirect github.com/go-git/go-billy/v6 v6.0.0-20250627091229-31e2a16eef30 // indirect - github.com/go-git/go-git/v6 v6.0.0-20250819122726-39261590f7f3 // indirect github.com/go-viper/mapstructure/v2 v2.2.1 // indirect github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect github.com/google/go-github/v74 v74.0.0 // indirect @@ -39,7 +40,6 @@ require ( github.com/spf13/afero v1.12.0 // indirect github.com/spf13/cast v1.7.1 // indirect github.com/spf13/pflag v1.0.6 // indirect - github.com/spf13/viper v1.20.1 // indirect github.com/src-d/gcfg v1.4.0 // indirect github.com/subosito/gotenv v1.6.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect diff --git a/api/job.go b/api/job.go new file mode 100644 index 0000000..e03826c --- /dev/null +++ b/api/job.go @@ -0,0 +1,5 @@ +package main + +func CreateJob(script string) { + +} diff --git a/api/migrations/000001_jobs.down.sql b/api/migrations/000001_jobs.down.sql new file mode 100644 index 0000000..a5c8ef6 --- /dev/null +++ b/api/migrations/000001_jobs.down.sql @@ -0,0 +1,10 @@ +begin; + +drop table job_step; +drop table jobs; + +drop type event; +drop type status; +drop type bash_type; + +commit; diff --git a/api/migrations/000001_jobs.up.sql b/api/migrations/000001_jobs.up.sql new file mode 100644 index 0000000..1eba864 --- /dev/null +++ b/api/migrations/000001_jobs.up.sql @@ -0,0 +1,37 @@ +begin; + +create type event as enum('push', 'pull_request', 'tags'); +create type status as enum('finished', 'waiting', 'running', 'error'); + +create table jobs( + id int not null primary key, + handle uuid not null, + name varchar(255) not null, + + repository_id int not null references repositories(id) on delete cascade, + ref varchar not null, + event event not null, + + started_at timestamptz not null, + finished_at timestamptz, + status status not null, + + parent int references jobs(id) on delete cascade +); + +create type bash_type as enum('command', 'loop', 'if'); + +create table job_step( + id int not null primary key, + job_id int not null references jobs(id) on delete cascade, + command text not null, + type bash_type not null, + status status not null, + exit_code int, + logs text not null, + + started_at timestamptz, + finished_at timestamptz +); + +commit; diff --git a/shell.nix b/shell.nix index 3bc600c..192af07 100644 --- a/shell.nix +++ b/shell.nix @@ -3,5 +3,8 @@ pkgs.mkShell { packages = with pkgs; [ go websocat + (go-migrate.overrideAttrs (oldAttrs: { + tags = ["postgres"]; + })) ]; }