diff --git a/sql/003-devices.sql b/sql/003-devices.sql new file mode 100644 index 0000000..c584bcb --- /dev/null +++ b/sql/003-devices.sql @@ -0,0 +1,29 @@ +-- Table: public.devices +-- DROP TABLE IF EXISTS public.devices; + +CREATE TABLE IF NOT EXISTS public.devices +( + id UUID DEFAULT gen_uuid_v7(), + timestamp TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, + type UUID NOT NULL, + CONSTRAINT pk_devices PRIMARY KEY (id), + CONSTRAINT fk_devices_type FOREIGN KEY (type) REFERENCES public.types (id) ON DELETE NO ACTION ON UPDATE NO ACTION +); + +ALTER TABLE IF EXISTS public.devices + OWNER to role_administrator; + + +-- Index: public.i_devices_type +-- DROP INDEX IF EXISTS public.i_devices_type; + +CREATE INDEX IF NOT EXISTS i_devices_type ON public.devices (type); + + +-- Revoke all permissions from existing roles +REVOKE ALL ON TABLE public.devices FROM role_administrator, role_maintainer, role_support, role_service; + +-- Grant appropriate permissions +GRANT ALL ON TABLE public.devices TO role_administrator; +GRANT SELECT, INSERT, UPDATE ON TABLE public.devices TO role_maintainer, role_service; +GRANT SELECT ON TABLE public.devices TO role_support; diff --git a/src/main/kotlin/ltd/hlaeja/entity/DeviceEntity.kt b/src/main/kotlin/ltd/hlaeja/entity/DeviceEntity.kt new file mode 100644 index 0000000..1630087 --- /dev/null +++ b/src/main/kotlin/ltd/hlaeja/entity/DeviceEntity.kt @@ -0,0 +1,14 @@ +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("devices") +data class DeviceEntity( + @Id + val id: UUID? = null, + val timestamp: ZonedDateTime, + val type: UUID, +)