cmd/relui: use migrations for sqlc schema

Use migrations instead of maintaining a schema.sql. Having a schema dump
can be useful, but we can instead go with our migrations to avoid
confusion.

For golang/go#47401

Change-Id: I426ffd46e17d3aa381d5bc0d517c8529961702f0
Reviewed-on: https://go-review.googlesource.com/c/build/+/353552
Trust: Alexander Rakoczy <alex@golang.org>
Run-TryBot: Alexander Rakoczy <alex@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
diff --git a/cmd/relui/Makefile b/cmd/relui/Makefile
index 516a25b..bd1d643 100644
--- a/cmd/relui/Makefile
+++ b/cmd/relui/Makefile
@@ -35,9 +35,6 @@
 migrate-down-up: docker
 	docker run --rm --name=relui-dev-migrate -v $(POSTGRES_RUN_DEV) -e PGUSER=$(POSTGRES_USER) -e PGDATABASE=relui-dev $(DOCKER_TAG) --migrate-down-up
 
-schema.sql: migrate
-	docker exec postgres-dev pg_dump --username=$(POSTGRES_USER) --schema-only relui-dev > schema.sql
-
 .PHONY: test
 test: postgres-dev docker-test
 	docker run --rm --name=relui-test -v $(POSTGRES_RUN_DEV) -e PGUSER=$(POSTGRES_USER) -e PGDATABASE=relui-test golang/relui-test:$(VERSION)
diff --git a/cmd/relui/README.md b/cmd/relui/README.md
index 3892411..ec92780 100644
--- a/cmd/relui/README.md
+++ b/cmd/relui/README.md
@@ -52,20 +52,10 @@
 
 #### Running
 
-Migrations are automatically ran on application launch. Updating
-schema.sql, as documented below, will also run migrations. "Down"
+Migrations are automatically ran on application launch. "Down"
 migrations are not automatically run and must be manually invoked in
 `psql`, or by the `--migrate-down-up` flag or `make migrate-down-up`.
 
-#### cmd/relui/schema.sql
-
-`schema.sql` is updated by running the following command in this
-directory:
-
-```bash
-make schema.sql
-```
-
 ## Testing
 
 Run go test with the appropriate
diff --git a/cmd/relui/schema.sql b/cmd/relui/schema.sql
deleted file mode 100644
index e1394b0..0000000
--- a/cmd/relui/schema.sql
+++ /dev/null
@@ -1,163 +0,0 @@
---
--- PostgreSQL database dump
---
-
--- Dumped from database version 13.3 (Debian 13.3-1.pgdg100+1)
--- Dumped by pg_dump version 13.3 (Debian 13.3-1.pgdg100+1)
-
-SET statement_timeout = 0;
-SET lock_timeout = 0;
-SET idle_in_transaction_session_timeout = 0;
-SET client_encoding = 'UTF8';
-SET standard_conforming_strings = on;
-SELECT pg_catalog.set_config('search_path', '', false);
-SET check_function_bodies = false;
-SET xmloption = content;
-SET client_min_messages = warning;
-SET row_security = off;
-
-SET default_tablespace = '';
-
-SET default_table_access_method = heap;
-
---
--- Name: migrations; Type: TABLE; Schema: public; Owner: postgres
---
-
-CREATE TABLE public.migrations (
-    version bigint NOT NULL,
-    dirty boolean NOT NULL
-);
-
-
-ALTER TABLE public.migrations OWNER TO postgres;
-
---
--- Name: task_logs; Type: TABLE; Schema: public; Owner: postgres
---
-
-CREATE TABLE public.task_logs (
-    id integer NOT NULL,
-    workflow_id uuid NOT NULL,
-    task_name text NOT NULL,
-    body text NOT NULL,
-    created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
-    updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
-);
-
-
-ALTER TABLE public.task_logs OWNER TO postgres;
-
---
--- Name: task_logs_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
---
-
-CREATE SEQUENCE public.task_logs_id_seq
-    AS integer
-    START WITH 1
-    INCREMENT BY 1
-    NO MINVALUE
-    NO MAXVALUE
-    CACHE 1;
-
-
-ALTER TABLE public.task_logs_id_seq OWNER TO postgres;
-
---
--- Name: task_logs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
---
-
-ALTER SEQUENCE public.task_logs_id_seq OWNED BY public.task_logs.id;
-
-
---
--- Name: tasks; Type: TABLE; Schema: public; Owner: postgres
---
-
-CREATE TABLE public.tasks (
-    workflow_id uuid NOT NULL,
-    name text NOT NULL,
-    finished boolean DEFAULT false NOT NULL,
-    result jsonb,
-    error text,
-    created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
-    updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
-);
-
-
-ALTER TABLE public.tasks OWNER TO postgres;
-
---
--- Name: workflows; Type: TABLE; Schema: public; Owner: postgres
---
-
-CREATE TABLE public.workflows (
-    id uuid NOT NULL,
-    params jsonb,
-    name text,
-    created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
-    updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
-);
-
-
-ALTER TABLE public.workflows OWNER TO postgres;
-
---
--- Name: task_logs id; Type: DEFAULT; Schema: public; Owner: postgres
---
-
-ALTER TABLE ONLY public.task_logs ALTER COLUMN id SET DEFAULT nextval('public.task_logs_id_seq'::regclass);
-
-
---
--- Name: migrations migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
---
-
-ALTER TABLE ONLY public.migrations
-    ADD CONSTRAINT migrations_pkey PRIMARY KEY (version);
-
-
---
--- Name: task_logs task_logs_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
---
-
-ALTER TABLE ONLY public.task_logs
-    ADD CONSTRAINT task_logs_pkey PRIMARY KEY (id);
-
-
---
--- Name: tasks tasks_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
---
-
-ALTER TABLE ONLY public.tasks
-    ADD CONSTRAINT tasks_pkey PRIMARY KEY (workflow_id, name);
-
-
---
--- Name: workflows workflows_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
---
-
-ALTER TABLE ONLY public.workflows
-    ADD CONSTRAINT workflows_pkey PRIMARY KEY (id);
-
-
---
--- Name: task_logs task_logs_workflow_id_task_name_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
---
-
-ALTER TABLE ONLY public.task_logs
-    ADD CONSTRAINT task_logs_workflow_id_task_name_fkey FOREIGN KEY (workflow_id, task_name) REFERENCES public.tasks(workflow_id, name);
-
-
---
--- Name: tasks tasks_workflow_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
---
-
-ALTER TABLE ONLY public.tasks
-    ADD CONSTRAINT tasks_workflow_id_fkey FOREIGN KEY (workflow_id) REFERENCES public.workflows(id);
-
-
---
--- PostgreSQL database dump complete
---
-
diff --git a/cmd/relui/sqlc.yaml b/cmd/relui/sqlc.yaml
index 6e54f54..f0e1ee8 100644
--- a/cmd/relui/sqlc.yaml
+++ b/cmd/relui/sqlc.yaml
@@ -3,7 +3,7 @@
   - name: "db"
     path: "../../internal/relui/db"
     queries: "../../internal/relui/queries"
-    schema: "schema.sql"
+    schema: "../../internal/relui/migrations/"
     engine: "postgresql"
     sql_package: "pgx/v4"
 overrides:
diff --git a/internal/relui/db/models.go b/internal/relui/db/models.go
index 8342e7a..bee4ac5 100644
--- a/internal/relui/db/models.go
+++ b/internal/relui/db/models.go
@@ -9,11 +9,6 @@
 	"github.com/google/uuid"
 )
 
-type Migration struct {
-	Version int64
-	Dirty   bool
-}
-
 type Task struct {
 	WorkflowID uuid.UUID
 	Name       string