diff --git a/.justfile b/.justfile index 9686466..110029f 100644 --- a/.justfile +++ b/.justfile @@ -13,3 +13,5 @@ dev: dbmate +ARGS: (compose-exec "index dbmate" ARGS) migrate: (dbmate "migrate") + +rollback: (dbmate "rollback") diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index efb80cc..af21718 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -5,11 +5,8 @@ services: build: context: .. dockerfile: ./docker/Dockerfile - develop: - watch: - - action: sync - path: ../src - target: /app + volumes: + - ../src:/app ports: - 3000:8080 env_file: ../.env diff --git a/src/app/logic_groups/create.sql b/src/app/logic_groups/create.sql new file mode 100644 index 0000000..e316f3e --- /dev/null +++ b/src/app/logic_groups/create.sql @@ -0,0 +1,7 @@ +INSERT INTO + public.logic_groups(name, uid, uri, source_id) +VALUES + (:name, :uid, :uri, :source_id :: int) +RETURNING + 'redirect' AS component, + 'index.sql' AS link; diff --git a/src/app/logic_groups/index.sql b/src/app/logic_groups/index.sql new file mode 100644 index 0000000..feb95dd --- /dev/null +++ b/src/app/logic_groups/index.sql @@ -0,0 +1,63 @@ +SELECT + 'dynamic' AS component, + sqlpage.read_file_as_text('../shared/shell.json') AS properties; + +-- ╭─────────────────────────────────────────────────────────╮ +-- │ Form │ +-- ╰─────────────────────────────────────────────────────────╯ +SELECT + 'form' AS component, + 'create.sql' AS "action", + 'Save' AS validate, + 'Logic Group' AS title; + +SELECT + 'source_id' AS name, + 'Source' AS label, + 'select' AS TYPE, + TRUE AS required, + TRUE AS searchable, + 'Select...' AS empty_option, + ( + SELECT + jsonb_agg(jsonb_build_object('label', name, 'value', id)) + FROM + public.sources + ) AS options; + +SELECT + 'name' AS name, + 'Name' AS label, + 8 AS width, + TRUE AS required; + +SELECT + 'uid' AS name, + 'Identifier' AS label, + 4 AS width, + 8 AS maxlength, + 1 AS minlength, + TRUE AS required; + +SELECT + 'uri' AS name, + 'URI' AS label; + +-- ╭─────────────────────────────────────────────────────────╮ +-- │ Table list │ +-- ╰─────────────────────────────────────────────────────────╯ +SELECT + 'table' AS component, + 'source' AS markdown, + TRUE AS sort, + TRUE AS search; + +SELECT + lg.id, + lg.uid, + format('[%s](/sources/%s)', src.name, src.id) AS Source, + lg.name, + lg.uri +FROM + public.logic_groups AS lg + INNER JOIN public.sources AS src ON lg.source_id = src.id; diff --git a/src/app/sources/index.sql b/src/app/sources/index.sql index 2eb0f06..2c763c5 100644 --- a/src/app/sources/index.sql +++ b/src/app/sources/index.sql @@ -5,11 +5,9 @@ SELECT -- ╭─────────────────────────────────────────────────────────╮ -- │ Form │ -- ╰─────────────────────────────────────────────────────────╯ - - SELECT 'form' AS component, - 'create.sql' AS action, + 'create.sql' AS "action", 'Save' AS validate, 'Sources' AS title; @@ -23,7 +21,7 @@ SELECT 'uid' AS name, 'Identifier' AS label, 4 AS width, - 5 AS maxlength, + 8 AS maxlength, 1 AS minlength, TRUE AS required; @@ -36,8 +34,8 @@ SELECT -- ╰─────────────────────────────────────────────────────────╯ SELECT 'table' AS component, - TRUE as sort, - TRUE as search; + TRUE AS sort, + TRUE AS search; SELECT * diff --git a/src/db/migrations/20250206220324_create_logic_groups_table.sql b/src/db/migrations/20250206220324_create_logic_groups_table.sql new file mode 100644 index 0000000..2537c20 --- /dev/null +++ b/src/db/migrations/20250206220324_create_logic_groups_table.sql @@ -0,0 +1,15 @@ +-- migrate:up +CREATE TABLE public.logic_groups ( + id serial PRIMARY KEY, + name character varying(20) NOT NULL, + uid character varying(8) NOT NULL, + uri character varying, + source_id int, + created_at timestamp WITH time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, + updated_at timestamp WITH time zone, + deleted_at timestamp WITH time zone, + CONSTRAINT fk_source FOREIGN KEY (source_id) REFERENCES public.sources(id) +); + +-- migrate:down +DROP TABLE public.logic_groups; diff --git a/src/shared/shell.json b/src/shared/shell.json index e3472df..ca8ae0c 100644 --- a/src/shared/shell.json +++ b/src/shared/shell.json @@ -11,6 +11,11 @@ "title": "Dependencies", "icon": "brand-stackshare", "submenu": [ + { + "link": "/logic_groups/index.sql", + "title": "Logic Groups", + "icon": "folder" + }, { "link": "/sources/index.sql", "title": "Sources",