Daniel Sheffield hace 19 horas
padre
commit
05f6b66f3e

+ 1 - 6
config/migrations/001_initial.sql

@@ -4,7 +4,6 @@ CREATE TABLE public.project (
     ggl_id bigint,
     description text
 );
-ALTER TABLE public.project OWNER TO postgres;
 ALTER TABLE ONLY public.project
     ADD CONSTRAINT description_uniq UNIQUE (description);
 ALTER TABLE ONLY public.project
@@ -23,7 +22,6 @@ CREATE TABLE public.items (
     duration interval,
     CONSTRAINT start_end_duration_ck CHECK ((((start IS NOT NULL) AND ("end" IS NOT NULL) AND ((duration IS NULL) OR (duration = ("end" - start)))) OR ((duration IS NOT NULL) AND ((start IS NOT NULL) OR ("end" IS NOT NULL)) AND ((start IS NULL) OR ("end" IS NULL)))))
 );
-ALTER TABLE public.items OWNER TO postgres;
 ALTER TABLE ONLY public.items
     ADD CONSTRAINT project_id_fk FOREIGN KEY (project_id) REFERENCES public.project(id);
 
@@ -35,7 +33,6 @@ CREATE VIEW public.timesheet AS
    FROM public.items
   GROUP BY ROLLUP((((COALESCE("end", (start + duration)) AT TIME ZONE 'UTC'::text))::date), project_id)
   ORDER BY (min(((COALESCE("end", (start + duration)) AT TIME ZONE 'UTC'::text))::date)) DESC, project_id;
-ALTER VIEW public.timesheet OWNER TO postgres;
 
 CREATE VIEW public.today AS
  SELECT id,
@@ -45,7 +42,6 @@ CREATE VIEW public.today AS
     (COALESCE("end", (start + duration)) AT TIME ZONE 'UTC'::text) AS "end"
    FROM public.items
   WHERE (((COALESCE("end", (start + duration)) AT TIME ZONE 'UTC'::text))::date = CURRENT_DATE);
-ALTER VIEW public.today OWNER TO postgres;
 
 CREATE PROCEDURE public.add_item(IN p_project_id numeric, IN p_description text, IN p_start time with time zone, IN p_end time with time zone, IN p_duration interval)
     LANGUAGE sql
@@ -60,7 +56,6 @@ VALUES
 	WHEN TRUE AND p_start IS NULL THEN ((current_date || ' ' || p_end)::timestamp with time zone) AT TIME ZONE 'UTC' - (SELECT COALESCE("end", start + duration) FROM items ORDER BY id DESC LIMIT 1)
 	ELSE p_duration END)
 $$;
-ALTER PROCEDURE public.add_item(IN p_project_id numeric, IN p_description text, IN p_start time with time zone, IN p_end time with time zone, IN p_duration interval) OWNER TO postgres;
 
 CREATE FUNCTION public.timesheet_day(p_ago interval DEFAULT '00:00:00'::interval) RETURNS SETOF public.timesheet
     LANGUAGE sql
@@ -75,4 +70,4 @@ CREATE FUNCTION public.timesheet_day(p_ago interval DEFAULT '00:00:00'::interval
 GROUP BY ROLLUP (project_id)
 ORDER BY project_id
 $$;
-ALTER FUNCTION public.timesheet_day(p_ago interval) OWNER TO postgres;
+GRANT ALL ON SCHEMA public TO das;

+ 1 - 2
config/migrations/003_tody_view.sql

@@ -10,5 +10,4 @@ CREATE VIEW public.today
    FROM items
   WHERE (COALESCE("end", start + duration) AT TIME ZONE 'UTC'::text)::date = CURRENT_DATE;
 
-ALTER TABLE public.today
-    OWNER TO postgres;
+GRANT ALL ON SCHEMA public TO das;

+ 1 - 2
config/migrations/004_timesheet_view.sql

@@ -8,5 +8,4 @@ CREATE OR REPLACE VIEW public.timesheet
   GROUP BY ROLLUP((COALESCE("end", start + duration) AT TIME ZONE 'UTC'::text)::date, project_id)
   ORDER BY (COALESCE("end", start + duration) AT TIME ZONE 'UTC'::text)::date DESC NULLS LAST, project_id;
 
-ALTER TABLE public.timesheet
-    OWNER TO postgres;
+GRANT ALL ON SCHEMA public TO das;

+ 1 - 1
config/sqlpage.yml

@@ -1,2 +1,2 @@
-database_url: "sqlite://./timesheet.db" #"postgres://postgres:postgres@localhost:5432/timesheet"
+database_url: "postgres://das@127.0.0.1:5432/timesheet"
 port: 6974 

+ 15 - 0
init.sh

@@ -0,0 +1,15 @@
+#!/bin/bash
+set -eou pipefail
+set -x
+SU=$(which doas)
+(
+    cd /home
+    doas -u postgres psql -d postgres -c "SELECT 1" || exit 1
+    doas -u postgres psql -d timesheet -c "SELECT 1" || doas -u postgres psql -d postgres <<EOF
+CREATE DATABASE timesheet;
+ALTER DATABASE timesheet OWNER TO das;
+\c timesheet
+CREATE ROLE das LOGIN;
+GRANT ALL ON SCHEMA public TO das;
+EOF
+)

+ 2 - 1
run.sh

@@ -1,2 +1,3 @@
 #!/bin/bash
-SLQPage/target/release/sqlpage
+set -eou pipefail
+SQLPage/target/release/sqlpage -w site -d config