From 28297aedf4eab0380aca1af1945f5cb6f812cd2a Mon Sep 17 00:00:00 2001 From: Bryan Mikaelian Date: Wed, 20 Nov 2024 09:17:19 -0500 Subject: [PATCH 1/5] Events table --- .../20241120133943-create-events.down.sql | 1 + .../20241120133943-create-events.up.sql | 11 +++ .../resources/database/migrations/schema.sql | 76 +++++++++++++++++++ docker-compose.yml | 4 +- 4 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 components/database/resources/database/migrations/20241120133943-create-events.down.sql create mode 100644 components/database/resources/database/migrations/20241120133943-create-events.up.sql diff --git a/components/database/resources/database/migrations/20241120133943-create-events.down.sql b/components/database/resources/database/migrations/20241120133943-create-events.down.sql new file mode 100644 index 0000000..653c740 --- /dev/null +++ b/components/database/resources/database/migrations/20241120133943-create-events.down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS events; diff --git a/components/database/resources/database/migrations/20241120133943-create-events.up.sql b/components/database/resources/database/migrations/20241120133943-create-events.up.sql new file mode 100644 index 0000000..2f85b35 --- /dev/null +++ b/components/database/resources/database/migrations/20241120133943-create-events.up.sql @@ -0,0 +1,11 @@ +CREATE TABLE IF NOT EXISTS events ( + id UUID PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(), + tenant_id BIGINT NOT NULL, + processed BOOLEAN NOT NULL DEFAULT false, + type TEXT NOT NULL, + payload JSONB NOT NULL +); + +--;; + +CREATE INDEX IF NOT EXISTS idx_events_tenant_processed ON events (tenant_id, processed); diff --git a/components/database/resources/database/migrations/schema.sql b/components/database/resources/database/migrations/schema.sql index 8b13789..c87e266 100644 --- a/components/database/resources/database/migrations/schema.sql +++ b/components/database/resources/database/migrations/schema.sql @@ -1 +1,77 @@ +-- +-- PostgreSQL database dump +-- + +-- Dumped from database version 16.5 (Debian 16.5-1.pgdg120+1) +-- Dumped by pg_dump version 16.3 + +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: events; Type: TABLE; Schema: public; Owner: venn +-- + +CREATE TABLE public.events ( + id uuid DEFAULT gen_random_uuid() NOT NULL, + tenant_id bigint NOT NULL, + processed boolean DEFAULT false NOT NULL, + type text NOT NULL, + payload jsonb NOT NULL +); + + +ALTER TABLE public.events OWNER TO venn; + +-- +-- Name: schema_migrations; Type: TABLE; Schema: public; Owner: venn +-- + +CREATE TABLE public.schema_migrations ( + id bigint NOT NULL, + applied timestamp without time zone, + description character varying(1024) +); + + +ALTER TABLE public.schema_migrations OWNER TO venn; + +-- +-- Name: events events_pkey; Type: CONSTRAINT; Schema: public; Owner: venn +-- + +ALTER TABLE ONLY public.events + ADD CONSTRAINT events_pkey PRIMARY KEY (id); + + +-- +-- Name: schema_migrations schema_migrations_id_key; Type: CONSTRAINT; Schema: public; Owner: venn +-- + +ALTER TABLE ONLY public.schema_migrations + ADD CONSTRAINT schema_migrations_id_key UNIQUE (id); + + +-- +-- Name: idx_events_tenant_processed; Type: INDEX; Schema: public; Owner: venn +-- + +CREATE INDEX idx_events_tenant_processed ON public.events USING btree (tenant_id, processed); + + +-- +-- PostgreSQL database dump complete +-- diff --git a/docker-compose.yml b/docker-compose.yml index e0d650a..985f320 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ services: venn_development_db: container_name: venn_development_db - image: postgres + image: postgres:16 restart: always environment: POSTGRES_USER: venn @@ -11,7 +11,7 @@ services: - 5432:5432 venn_test_db: container_name: venn_test_db - image: postgres + image: postgres:16 restart: always environment: POSTGRES_USER: venn From e9e91ad1e53b4974ad9d669ae35bf96eda172da3 Mon Sep 17 00:00:00 2001 From: Bryan Mikaelian Date: Fri, 22 Nov 2024 20:20:05 -0500 Subject: [PATCH 2/5] Setup a volume for pgsql --- .gitignore | 2 ++ docker-compose.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 4dffc32..0998d8d 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ log 1 projects/**/target development/resources/system.edn + +/tmp diff --git a/docker-compose.yml b/docker-compose.yml index 985f320..c5ef8e2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,5 +17,7 @@ services: POSTGRES_USER: venn POSTGRES_DB: venn_test POSTGRES_PASSWORD: password + volumes: + - ./tmp/data:/var/lib/postgrsql/data ports: - 5433:5432 From 9d15ad600c849f17d6c2bb1df54f765ad1161d1d Mon Sep 17 00:00:00 2001 From: Bryan Mikaelian Date: Fri, 22 Nov 2024 20:23:36 -0500 Subject: [PATCH 3/5] clj-kondo --- .../next.jdbc/config.edn | 8 +++++ .../github/seancorfield/next_jdbc.clj_kondo | 34 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 projects/agent/.clj-kondo/com.github.seancorfield/next.jdbc/config.edn create mode 100644 projects/agent/.clj-kondo/com.github.seancorfield/next.jdbc/hooks/com/github/seancorfield/next_jdbc.clj_kondo diff --git a/projects/agent/.clj-kondo/com.github.seancorfield/next.jdbc/config.edn b/projects/agent/.clj-kondo/com.github.seancorfield/next.jdbc/config.edn new file mode 100644 index 0000000..c02325b --- /dev/null +++ b/projects/agent/.clj-kondo/com.github.seancorfield/next.jdbc/config.edn @@ -0,0 +1,8 @@ +{:hooks + {:analyze-call + {next.jdbc/with-transaction + hooks.com.github.seancorfield.next-jdbc/with-transaction + next.jdbc/with-transaction+options + hooks.com.github.seancorfield.next-jdbc/with-transaction+options}} + :lint-as {next.jdbc/on-connection clojure.core/with-open + next.jdbc/on-connection+options clojure.core/with-open}} diff --git a/projects/agent/.clj-kondo/com.github.seancorfield/next.jdbc/hooks/com/github/seancorfield/next_jdbc.clj_kondo b/projects/agent/.clj-kondo/com.github.seancorfield/next.jdbc/hooks/com/github/seancorfield/next_jdbc.clj_kondo new file mode 100644 index 0000000..9fc398d --- /dev/null +++ b/projects/agent/.clj-kondo/com.github.seancorfield/next.jdbc/hooks/com/github/seancorfield/next_jdbc.clj_kondo @@ -0,0 +1,34 @@ +(ns hooks.com.github.seancorfield.next-jdbc + (:require [clj-kondo.hooks-api :as api])) + +(defn with-transaction + "Expands (with-transaction [tx expr opts] body) + to (let [tx expr] opts body) per clj-kondo examples." + [{:keys [:node]}] + (let [[binding-vec & body] (rest (:children node)) + [sym val opts] (:children binding-vec)] + (when-not (and sym val) + (throw (ex-info "No sym and val provided" {}))) + (let [new-node (api/list-node + (list* + (api/token-node 'let) + (api/vector-node [sym val]) + opts + body))] + {:node new-node}))) + +(defn with-transaction+options + "Expands (with-transaction+options [tx expr opts] body) + to (let [tx expr] opts body) per clj-kondo examples." + [{:keys [:node]}] + (let [[binding-vec & body] (rest (:children node)) + [sym val opts] (:children binding-vec)] + (when-not (and sym val) + (throw (ex-info "No sym and val provided" {}))) + (let [new-node (api/list-node + (list* + (api/token-node 'let) + (api/vector-node [sym val]) + opts + body))] + {:node new-node}))) From 3086531620b8b3776fe638c6b731766c7f9fc832 Mon Sep 17 00:00:00 2001 From: Bryan Mikaelian Date: Fri, 22 Nov 2024 20:25:25 -0500 Subject: [PATCH 4/5] remove schema --- .../resources/database/migrations/schema.sql | 77 ------------------- 1 file changed, 77 deletions(-) delete mode 100644 components/database/resources/database/migrations/schema.sql diff --git a/components/database/resources/database/migrations/schema.sql b/components/database/resources/database/migrations/schema.sql deleted file mode 100644 index c87e266..0000000 --- a/components/database/resources/database/migrations/schema.sql +++ /dev/null @@ -1,77 +0,0 @@ --- --- PostgreSQL database dump --- - --- Dumped from database version 16.5 (Debian 16.5-1.pgdg120+1) --- Dumped by pg_dump version 16.3 - -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: events; Type: TABLE; Schema: public; Owner: venn --- - -CREATE TABLE public.events ( - id uuid DEFAULT gen_random_uuid() NOT NULL, - tenant_id bigint NOT NULL, - processed boolean DEFAULT false NOT NULL, - type text NOT NULL, - payload jsonb NOT NULL -); - - -ALTER TABLE public.events OWNER TO venn; - --- --- Name: schema_migrations; Type: TABLE; Schema: public; Owner: venn --- - -CREATE TABLE public.schema_migrations ( - id bigint NOT NULL, - applied timestamp without time zone, - description character varying(1024) -); - - -ALTER TABLE public.schema_migrations OWNER TO venn; - --- --- Name: events events_pkey; Type: CONSTRAINT; Schema: public; Owner: venn --- - -ALTER TABLE ONLY public.events - ADD CONSTRAINT events_pkey PRIMARY KEY (id); - - --- --- Name: schema_migrations schema_migrations_id_key; Type: CONSTRAINT; Schema: public; Owner: venn --- - -ALTER TABLE ONLY public.schema_migrations - ADD CONSTRAINT schema_migrations_id_key UNIQUE (id); - - --- --- Name: idx_events_tenant_processed; Type: INDEX; Schema: public; Owner: venn --- - -CREATE INDEX idx_events_tenant_processed ON public.events USING btree (tenant_id, processed); - - --- --- PostgreSQL database dump complete --- - From f9954b85e7b675a511a8a5b97d1839afb7ca78c4 Mon Sep 17 00:00:00 2001 From: Bryan Mikaelian Date: Fri, 22 Nov 2024 20:35:41 -0500 Subject: [PATCH 5/5] schema --- .../resources/database/migrations/schema.sql | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 components/database/resources/database/migrations/schema.sql diff --git a/components/database/resources/database/migrations/schema.sql b/components/database/resources/database/migrations/schema.sql new file mode 100644 index 0000000..c87e266 --- /dev/null +++ b/components/database/resources/database/migrations/schema.sql @@ -0,0 +1,77 @@ +-- +-- PostgreSQL database dump +-- + +-- Dumped from database version 16.5 (Debian 16.5-1.pgdg120+1) +-- Dumped by pg_dump version 16.3 + +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: events; Type: TABLE; Schema: public; Owner: venn +-- + +CREATE TABLE public.events ( + id uuid DEFAULT gen_random_uuid() NOT NULL, + tenant_id bigint NOT NULL, + processed boolean DEFAULT false NOT NULL, + type text NOT NULL, + payload jsonb NOT NULL +); + + +ALTER TABLE public.events OWNER TO venn; + +-- +-- Name: schema_migrations; Type: TABLE; Schema: public; Owner: venn +-- + +CREATE TABLE public.schema_migrations ( + id bigint NOT NULL, + applied timestamp without time zone, + description character varying(1024) +); + + +ALTER TABLE public.schema_migrations OWNER TO venn; + +-- +-- Name: events events_pkey; Type: CONSTRAINT; Schema: public; Owner: venn +-- + +ALTER TABLE ONLY public.events + ADD CONSTRAINT events_pkey PRIMARY KEY (id); + + +-- +-- Name: schema_migrations schema_migrations_id_key; Type: CONSTRAINT; Schema: public; Owner: venn +-- + +ALTER TABLE ONLY public.schema_migrations + ADD CONSTRAINT schema_migrations_id_key UNIQUE (id); + + +-- +-- Name: idx_events_tenant_processed; Type: INDEX; Schema: public; Owner: venn +-- + +CREATE INDEX idx_events_tenant_processed ON public.events USING btree (tenant_id, processed); + + +-- +-- PostgreSQL database dump complete +-- +