generated from alecodes/base-template
feat: allow to create entries
This commit is contained in:
parent
5dbdd5d84d
commit
2be95765e8
4 changed files with 284 additions and 94 deletions
|
|
@ -1,67 +1,14 @@
|
|||
SELECT
|
||||
'dynamic' AS component,
|
||||
sqlpage.read_file_as_text('../shared/shell.json') AS properties;
|
||||
|
||||
SELECT
|
||||
'form' AS component,
|
||||
TRUE AS auto_submit;
|
||||
|
||||
SELECT
|
||||
'source_id' AS name,
|
||||
'Source - group' AS label,
|
||||
'select' AS "type",
|
||||
FALSE AS autocomplete,
|
||||
(
|
||||
SELECT
|
||||
jsonb_agg(
|
||||
jsonb_build_object(
|
||||
'label',
|
||||
format('%s - %s', src.name, lg.name),
|
||||
'value',
|
||||
lg.id,
|
||||
'selected',
|
||||
lg.id = $source_id :: int
|
||||
)
|
||||
ORDER BY
|
||||
src.name,
|
||||
lg.name
|
||||
)
|
||||
FROM
|
||||
public.logic_groups AS lg
|
||||
INNER JOIN public.sources AS src ON lg.source_id = src.id
|
||||
) AS options;
|
||||
|
||||
SELECT
|
||||
'form' AS component,
|
||||
'Create' AS validate;
|
||||
|
||||
SELECT
|
||||
'Date' AS label,
|
||||
'date' AS name,
|
||||
'date' AS "type",
|
||||
CURRENT_DATE AS value,
|
||||
6 AS width;
|
||||
|
||||
SELECT
|
||||
'Time' AS label,
|
||||
'time' AS name,
|
||||
'time' AS "type",
|
||||
LOCALTIME(0) AS value,
|
||||
6 AS width;
|
||||
|
||||
SELECT
|
||||
'UID' AS label,
|
||||
'uid' AS name,
|
||||
'SOURCE:LOGIC-GROUP:DESAMBIGUATOR:ATOM' AS placeholder,
|
||||
TRUE AS disabled;
|
||||
|
||||
-- ── Desambiguator Definitions Start ─────────────────────────────────
|
||||
SET
|
||||
input =
|
||||
created_at = CURRENT_TIMESTAMP;
|
||||
|
||||
SET
|
||||
extra_data =
|
||||
SELECT
|
||||
jsonb_build_object(
|
||||
'id',
|
||||
dtp.id,
|
||||
'src_uid',
|
||||
src.uid,
|
||||
'lg_uid',
|
||||
lg.uid,
|
||||
'input_type',
|
||||
dtp.input_type,
|
||||
'placeholder',
|
||||
|
|
@ -72,36 +19,57 @@ FROM
|
|||
INNER JOIN public.sources AS src ON src.desambiguator_type_id = dtp.id
|
||||
INNER JOIN public.logic_groups AS lg ON lg.source_id = src.id
|
||||
WHERE
|
||||
lg.id = $source_id :: int;
|
||||
lg.id = :lg_id :: int;
|
||||
|
||||
SELECT
|
||||
'Desambiguator' AS label,
|
||||
'desambiguator' AS name,
|
||||
$input :: jsonb ->> 'input_type' AS "type",
|
||||
$input :: jsonb ->> 'placeholder' AS placeholder,
|
||||
6 AS width
|
||||
WHERE
|
||||
$input :: jsonb ->> 'id' = '1';
|
||||
SET
|
||||
og_desambiguator = :desambiguator;
|
||||
|
||||
SELECT
|
||||
'Desambiguator' AS label,
|
||||
'desambiguator' AS name,
|
||||
$input :: jsonb ->> 'input_type' AS "type",
|
||||
$input :: jsonb ->> 'placeholder' AS placeholder,
|
||||
CURRENT_DATE AS value,
|
||||
6 AS width
|
||||
WHERE
|
||||
$input :: jsonb ->> 'id' = '2';
|
||||
SET
|
||||
desambiguator = CASE
|
||||
$extra_data :: jsonb ->> 'input_type'
|
||||
WHEN 'date' THEN to_hex(
|
||||
-- Days since 1970-01-01 in hex
|
||||
EXTRACT(
|
||||
EPOCH
|
||||
FROM
|
||||
NOW()
|
||||
) :: bigint
|
||||
)
|
||||
ELSE :desambiguator
|
||||
END;
|
||||
|
||||
-- ── Desambiguator Definitions End ───────────────────────────────────
|
||||
SELECT
|
||||
'Atom' AS label,
|
||||
'atom' AS name,
|
||||
'FFF' AS placeholder,
|
||||
6 AS width;
|
||||
SET
|
||||
uid = format(
|
||||
'%s:%s:%s:%s',
|
||||
$extra_data :: jsonb ->> 'src_uid',
|
||||
$extra_data :: jsonb ->> 'lg_uid',
|
||||
:desambiguator,
|
||||
:atom
|
||||
);
|
||||
|
||||
SELECT
|
||||
'Description' AS label,
|
||||
'text' AS name,
|
||||
'What is this entry about?' AS placeholder,
|
||||
'textarea' AS "type";
|
||||
SET
|
||||
return_link = format(
|
||||
'form.sql?date=%s&time=%s&desambiguator=%s&lg_id=%s',
|
||||
:date,
|
||||
:time,
|
||||
:og_desambiguator,
|
||||
$extra_data :: jsonb ->> 'lg_uid'
|
||||
);
|
||||
|
||||
INSERT INTO
|
||||
public.entries(
|
||||
uid,
|
||||
desambiguator,
|
||||
text,
|
||||
logic_group_id,
|
||||
created_at
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
$uid,
|
||||
:desambiguator,
|
||||
:text,
|
||||
:lg_id :: int,
|
||||
:date :: date + :time :: time
|
||||
) RETURNING 'redirect' AS component,
|
||||
$return_link AS link;
|
||||
|
|
|
|||
139
src/app/entries/form.sql
Normal file
139
src/app/entries/form.sql
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
SELECT
|
||||
'dynamic' AS component,
|
||||
sqlpage.read_file_as_text('../shared/shell.json') AS properties;
|
||||
|
||||
SELECT
|
||||
'form' AS component,
|
||||
TRUE AS auto_submit;
|
||||
|
||||
SET
|
||||
lg_id = COALESCE($lg_id :: int, 1);
|
||||
|
||||
SELECT
|
||||
'lg_id' AS name,
|
||||
'Source - group' AS label,
|
||||
'select' AS "type",
|
||||
FALSE AS autocomplete,
|
||||
(
|
||||
SELECT
|
||||
jsonb_agg(
|
||||
jsonb_build_object(
|
||||
'label',
|
||||
format('%s - %s', src.name, lg.name),
|
||||
'value',
|
||||
lg.id,
|
||||
'selected',
|
||||
lg.id = $lg_id :: int
|
||||
)
|
||||
ORDER BY
|
||||
src.name,
|
||||
lg.name
|
||||
)
|
||||
FROM
|
||||
public.logic_groups AS lg
|
||||
INNER JOIN public.sources AS src ON lg.source_id = src.id
|
||||
) AS options;
|
||||
|
||||
SELECT
|
||||
'form' AS component,
|
||||
'Create' AS validate,
|
||||
'create.sql' AS "action";
|
||||
|
||||
SELECT
|
||||
'Date' AS label,
|
||||
'date' AS name,
|
||||
'date' AS "type",
|
||||
CURRENT_DATE AS value,
|
||||
6 AS width;
|
||||
|
||||
SELECT
|
||||
'Time' AS label,
|
||||
'time' AS name,
|
||||
'time' AS "type",
|
||||
LOCALTIME(0) AS value,
|
||||
6 AS width;
|
||||
|
||||
SELECT
|
||||
'UID' AS label,
|
||||
'uid' AS name,
|
||||
'SOURCE:LOGIC-GROUP:DESAMBIGUATOR:ATOM' AS placeholder,
|
||||
TRUE AS disabled;
|
||||
|
||||
-- ── Desambiguator Definitions Start ─────────────────────────────────
|
||||
SET
|
||||
input =
|
||||
SELECT
|
||||
jsonb_build_object(
|
||||
'id',
|
||||
dtp.id,
|
||||
'input_type',
|
||||
dtp.input_type,
|
||||
'placeholder',
|
||||
dtp.placeholder
|
||||
) AS obj
|
||||
FROM
|
||||
public.desambiguator_types dtp
|
||||
INNER JOIN public.sources AS src ON src.desambiguator_type_id = dtp.id
|
||||
INNER JOIN public.logic_groups AS lg ON lg.source_id = src.id
|
||||
WHERE
|
||||
lg.id = $lg_id :: int;
|
||||
|
||||
SELECT
|
||||
'lg_id' AS name,
|
||||
'hidden' AS TYPE,
|
||||
$input :: jsonb ->> 'id' AS value;
|
||||
|
||||
SELECT
|
||||
'Desambiguator' AS label,
|
||||
'desambiguator' AS name,
|
||||
$input :: jsonb ->> 'input_type' AS "type",
|
||||
$input :: jsonb ->> 'placeholder' AS placeholder,
|
||||
6 AS width
|
||||
WHERE
|
||||
$input :: jsonb ->> 'id' = '1';
|
||||
|
||||
SELECT
|
||||
'Desambiguator' AS label,
|
||||
'desambiguator' AS name,
|
||||
$input :: jsonb ->> 'input_type' AS "type",
|
||||
$input :: jsonb ->> 'placeholder' AS placeholder,
|
||||
CURRENT_DATE AS value,
|
||||
6 AS width
|
||||
WHERE
|
||||
$input :: jsonb ->> 'id' = '2';
|
||||
|
||||
-- ── Desambiguator Definitions End ───────────────────────────────────
|
||||
SELECT
|
||||
'Atom' AS label,
|
||||
'atom' AS name,
|
||||
'FFF' AS placeholder,
|
||||
6 AS width;
|
||||
|
||||
SELECT
|
||||
'Description' AS label,
|
||||
'text' AS name,
|
||||
'What is this entry about?' AS placeholder,
|
||||
'textarea' AS "type";
|
||||
|
||||
SELECT
|
||||
'table' AS component,
|
||||
'uid' AS monospace,
|
||||
'id' AS align_center,
|
||||
'created at' AS align_center,
|
||||
'uid' AS align_center,
|
||||
TRUE AS border,
|
||||
TRUE AS striped_rows,
|
||||
TRUE AS small;
|
||||
|
||||
SELECT
|
||||
id,
|
||||
to_char(created_at, 'YYYY-MM-DD HH12:MI:SS TZ') AS "Created At",
|
||||
upper(uid) AS uid,
|
||||
format('/entries/%s', id) AS link,
|
||||
left(text, 15) AS description
|
||||
FROM
|
||||
public.entries
|
||||
ORDER BY
|
||||
created_at
|
||||
LIMIT
|
||||
10;
|
||||
|
|
@ -28,7 +28,7 @@ SELECT
|
|||
'new' AS name,
|
||||
'' AS label,
|
||||
'New' AS value,
|
||||
'entries/create.sql' AS "formaction",
|
||||
'entries/form.sql' AS "formaction",
|
||||
'btn btn-success' AS class,
|
||||
'submit' AS "type";
|
||||
|
||||
|
|
@ -38,10 +38,16 @@ SELECT
|
|||
'No entries has been found...' AS empty_title;
|
||||
|
||||
SELECT
|
||||
name AS title,
|
||||
concat(
|
||||
to_char(created_at, 'YYYY-MM-DD HH12:MI:SS TZ'),
|
||||
' --- ',
|
||||
upper(uid)
|
||||
) AS title,
|
||||
format('/entries/%s', id) AS link,
|
||||
uid AS description
|
||||
text AS description
|
||||
FROM
|
||||
public.sources
|
||||
public.entries
|
||||
ORDER BY
|
||||
created_at
|
||||
LIMIT
|
||||
10;
|
||||
|
|
|
|||
77
src/db/migrations/20250207174953_add_table_entries.sql
Normal file
77
src/db/migrations/20250207174953_add_table_entries.sql
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
-- migrate:up
|
||||
CREATE TABLE public.entries (
|
||||
id serial NOT NULL,
|
||||
uid varchar NOT NULL,
|
||||
desambiguator text NOT NULL,
|
||||
text text,
|
||||
logic_group_id integer NOT NULL,
|
||||
created_at timestamp WITH time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
updated_at timestamp WITH time zone,
|
||||
deleted_at timestamp WITH time zone,
|
||||
PRIMARY KEY (id, created_at),
|
||||
CONSTRAINT fk_logic_group FOREIGN KEY (logic_group_id) REFERENCES public.logic_groups(id)
|
||||
) PARTITION BY RANGE (created_at);
|
||||
|
||||
CREATE INDEX index_entries_uid ON ONLY public.entries USING btree (uid);
|
||||
|
||||
CREATE SCHEMA entries_partitions;
|
||||
|
||||
CREATE TABLE entries_partitions.e2020 PARTITION OF public.entries FOR
|
||||
VALUES
|
||||
FROM
|
||||
('2020-01-01') TO ('2021-01-01');
|
||||
|
||||
CREATE TABLE entries_partitions.e2021 PARTITION OF public.entries FOR
|
||||
VALUES
|
||||
FROM
|
||||
('2021-01-01') TO ('2022-01-01');
|
||||
|
||||
CREATE TABLE entries_partitions.e2022 PARTITION OF public.entries FOR
|
||||
VALUES
|
||||
FROM
|
||||
('2022-01-01') TO ('2023-01-01');
|
||||
|
||||
CREATE TABLE entries_partitions.e2023 PARTITION OF public.entries FOR
|
||||
VALUES
|
||||
FROM
|
||||
('2023-01-01') TO ('2024-01-01');
|
||||
|
||||
CREATE TABLE entries_partitions.e2024 PARTITION OF public.entries FOR
|
||||
VALUES
|
||||
FROM
|
||||
('2024-01-01') TO ('2025-01-01');
|
||||
|
||||
CREATE TABLE entries_partitions.e2025 PARTITION OF public.entries FOR
|
||||
VALUES
|
||||
FROM
|
||||
('2025-01-01') TO ('2026-01-01');
|
||||
|
||||
CREATE TABLE entries_partitions.e2026 PARTITION OF public.entries FOR
|
||||
VALUES
|
||||
FROM
|
||||
('2026-01-01') TO ('2027-01-01');
|
||||
|
||||
CREATE TABLE entries_partitions.e2027 PARTITION OF public.entries FOR
|
||||
VALUES
|
||||
FROM
|
||||
('2027-01-01') TO ('2028-01-01');
|
||||
|
||||
CREATE TABLE entries_partitions.e2028 PARTITION OF public.entries FOR
|
||||
VALUES
|
||||
FROM
|
||||
('2028-01-01') TO ('2029-01-01');
|
||||
|
||||
CREATE TABLE entries_partitions.e2029 PARTITION OF public.entries FOR
|
||||
VALUES
|
||||
FROM
|
||||
('2029-01-01') TO ('2030-01-01');
|
||||
|
||||
CREATE TABLE entries_partitions.e2030 PARTITION OF public.entries FOR
|
||||
VALUES
|
||||
FROM
|
||||
('2030-01-01') TO ('2031-01-01');
|
||||
|
||||
-- migrate:down
|
||||
DROP TABLE public.entries;
|
||||
|
||||
DROP schema entries_partitions;
|
||||
Loading…
Add table
Add a link
Reference in a new issue