From baf70e682001f6605513863269b928c15036811f Mon Sep 17 00:00:00 2001 From: aleidk Date: Wed, 5 Feb 2025 19:56:47 -0300 Subject: [PATCH] feat: add sources form and table --- .env.example | 2 + .justfile | 2 + docker/Dockerfile | 2 +- docker/docker-compose.yaml | 5 +++ src/app/index.sql | 1 + src/app/sources/create.sql | 7 +++ src/app/sources/index.sql | 45 +++++++++++++++++++ .../20250205190533_create_sources_table.sql | 2 +- src/index.sql | 6 --- src/shared/shell.json | 22 +++++++++ src/sqlpage/templates/pagination.handlebars | 17 +++++++ 11 files changed, 103 insertions(+), 8 deletions(-) create mode 100644 src/app/index.sql create mode 100644 src/app/sources/create.sql create mode 100644 src/app/sources/index.sql delete mode 100644 src/index.sql create mode 100644 src/shared/shell.json create mode 100644 src/sqlpage/templates/pagination.handlebars diff --git a/.env.example b/.env.example index 84874d5..eae5060 100644 --- a/.env.example +++ b/.env.example @@ -3,3 +3,5 @@ POSTGRES_USER=index POSTGRES_PASSWORD= DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}?sslmode=disable" + +SQLPAGE_WEB_ROOT=app diff --git a/.justfile b/.justfile index 04b421f..9686466 100644 --- a/.justfile +++ b/.justfile @@ -11,3 +11,5 @@ dev: docker compose up --watch dbmate +ARGS: (compose-exec "index dbmate" ARGS) + +migrate: (dbmate "migrate") diff --git a/docker/Dockerfile b/docker/Dockerfile index d9229e9..4cadceb 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -6,7 +6,7 @@ COPY --from=lovasoa/sqlpage:latest /usr/local/bin/sqlpage /usr/local/bin/sqlpage WORKDIR /app ENV SQLPAGE_WEB_ROOT=/app -ENV SQLPAGE_CONFIGURATION_DIRECTORY=/etc/sqlpage +ENV SQLPAGE_CONFIGURATION_DIRECTORY=/app/sqlpage RUN addgroup --gid 1000 --system index_user && \ adduser --uid 1000 --system --no-create-home --ingroup index_user index_user && \ diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index 799130e..efb80cc 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -17,3 +17,8 @@ services: db: image: postgres:17 env_file: ../.env + volumes: + - db_data:/var/lib/postgresql/data + +volumes: + db_data: diff --git a/src/app/index.sql b/src/app/index.sql new file mode 100644 index 0000000..0d98893 --- /dev/null +++ b/src/app/index.sql @@ -0,0 +1 @@ +SELECT 'dynamic' AS component, sqlpage.read_file_as_text('../shared/shell.json') AS properties; diff --git a/src/app/sources/create.sql b/src/app/sources/create.sql new file mode 100644 index 0000000..cf0f0f8 --- /dev/null +++ b/src/app/sources/create.sql @@ -0,0 +1,7 @@ +INSERT INTO + public.sources(name, uid, uri) +VALUES + (:name, :uid, :uri) +RETURNING 'redirect' AS component, 'index.sql' AS link +; + diff --git a/src/app/sources/index.sql b/src/app/sources/index.sql new file mode 100644 index 0000000..2eb0f06 --- /dev/null +++ b/src/app/sources/index.sql @@ -0,0 +1,45 @@ +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, + 'Sources' AS title; + +SELECT + 'name' AS name, + 'Name' AS label, + 8 AS width, + TRUE AS required; + +SELECT + 'uid' AS name, + 'Identifier' AS label, + 4 AS width, + 5 AS maxlength, + 1 AS minlength, + TRUE AS required; + +SELECT + 'uri' AS name, + 'URI' AS label; + +-- ╭─────────────────────────────────────────────────────────╮ +-- │ Table list │ +-- ╰─────────────────────────────────────────────────────────╯ +SELECT + 'table' AS component, + TRUE as sort, + TRUE as search; + +SELECT + * +FROM + public.sources; diff --git a/src/db/migrations/20250205190533_create_sources_table.sql b/src/db/migrations/20250205190533_create_sources_table.sql index 843efc1..36dac58 100644 --- a/src/db/migrations/20250205190533_create_sources_table.sql +++ b/src/db/migrations/20250205190533_create_sources_table.sql @@ -3,7 +3,7 @@ CREATE TABLE public.sources ( id serial PRIMARY KEY, name character varying(20) NOT NULL, uid character varying(8) NOT NULL, - uri character varying NOT NULL, + uri character varying, created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, updated_at timestamp with time zone, deleted_at timestamp with time zone diff --git a/src/index.sql b/src/index.sql deleted file mode 100644 index 3886b29..0000000 --- a/src/index.sql +++ /dev/null @@ -1,6 +0,0 @@ -SELECT 'list' AS component, - 'Popular websites TESTOOO' AS title; - -SELECT 'Hello' AS title, - 'world' AS description, - 'https://wikipedia.org' AS link; diff --git a/src/shared/shell.json b/src/shared/shell.json new file mode 100644 index 0000000..e3472df --- /dev/null +++ b/src/shared/shell.json @@ -0,0 +1,22 @@ +{ + "component": "shell", + "title": "Index", + "link": "/", + "layout": "boxed", + "sidebar": true, + "theme": "dark", + "menu_item": [ + { "link": "index.sql", "title": "Home" }, + { + "title": "Dependencies", + "icon": "brand-stackshare", + "submenu": [ + { + "link": "/sources/index.sql", + "title": "Sources", + "icon": "external-link" + } + ] + } + ] +} diff --git a/src/sqlpage/templates/pagination.handlebars b/src/sqlpage/templates/pagination.handlebars new file mode 100644 index 0000000..f5a3380 --- /dev/null +++ b/src/sqlpage/templates/pagination.handlebars @@ -0,0 +1,17 @@ +