From 787e020294dcb6d0642ade5c1a8e35ce22ba01b6 Mon Sep 17 00:00:00 2001 From: Swordsteel Date: Fri, 22 Nov 2024 21:58:37 +0100 Subject: [PATCH] add NodeEntity --- sql/004-nodes.sql | 31 +++++++++++++++++++ .../kotlin/ltd/hlaeja/entity/NodeEntity.kt | 16 ++++++++++ 2 files changed, 47 insertions(+) create mode 100644 sql/004-nodes.sql create mode 100644 src/main/kotlin/ltd/hlaeja/entity/NodeEntity.kt diff --git a/sql/004-nodes.sql b/sql/004-nodes.sql new file mode 100644 index 0000000..511926f --- /dev/null +++ b/sql/004-nodes.sql @@ -0,0 +1,31 @@ +-- Table: public.nodes +-- DROP TABLE IF EXISTS public.nodes; + +CREATE TABLE IF NOT EXISTS public.nodes +( + id UUID DEFAULT gen_uuid_v7(), + timestamp TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, + client UUID NOT NULL, + device UUID NOT NULL, + name VARCHAR(50) NOT NULL, + CONSTRAINT pk_nodes PRIMARY KEY (id), + CONSTRAINT fk_nodes_type FOREIGN KEY (device) REFERENCES public.devices (id) ON DELETE NO ACTION ON UPDATE NO ACTION +); + +ALTER TABLE IF EXISTS public.nodes + OWNER to role_administrator; + + +-- Index: public.i_nodes_type +-- DROP INDEX IF EXISTS public.i_nodes_type; + +CREATE INDEX IF NOT EXISTS i_nodes_device ON public.nodes (device); + + +-- Revoke all permissions from existing roles +REVOKE ALL ON TABLE public.nodes FROM role_administrator, role_maintainer, role_support, role_service; + +-- Grant appropriate permissions +GRANT ALL ON TABLE public.nodes TO role_administrator; +GRANT SELECT, INSERT, UPDATE ON TABLE public.nodes TO role_maintainer, role_service; +GRANT SELECT ON TABLE public.nodes TO role_support; diff --git a/src/main/kotlin/ltd/hlaeja/entity/NodeEntity.kt b/src/main/kotlin/ltd/hlaeja/entity/NodeEntity.kt new file mode 100644 index 0000000..a1e3916 --- /dev/null +++ b/src/main/kotlin/ltd/hlaeja/entity/NodeEntity.kt @@ -0,0 +1,16 @@ +package ltd.hlaeja.entity + +import java.time.ZonedDateTime +import java.util.UUID +import org.springframework.data.annotation.Id +import org.springframework.data.relational.core.mapping.Table + +@Table("nodes") +data class NodeEntity( + @Id + val id: UUID? = null, + val timestamp: ZonedDateTime, + val client: UUID, + val device: UUID, + val name: String, +)