inventory/db-init.sh

36 lines
812 B
Bash

INIT="-- table:newtable
CREATE TABLE public.newtable (
id integer NOT NULL,
data json NOT NULL,
created_at date DEFAULT CURRENT_TIMESTAMP NOT NULL,
updated_at date DEFAULT '0001-01-01'::date NOT NULL,
deleted_at date DEFAULT '0001-01-01'::date NOT NULL,
is_deleted boolean DEFAULT false NOT NULL
);
ALTER TABLE public.newtable OWNER TO postgres;
ALTER TABLE public.newtable ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
SEQUENCE NAME public.newtable_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1
);
SELECT pg_catalog.setval('public.newtable_id_seq', 1, false);
-- /table:newtable
"
TABLES=(
projects
bookmarks
notes
contacts
collections
)
for TABLE in ${TABLES[@]}; do
echo "$INIT" \
| sd 'newtable' "$TABLE" \
>> init.sql
done