Skip to content

Instantly share code, notes, and snippets.

@mapehe
Created May 24, 2022 13:15
Show Gist options
  • Save mapehe/b3f64857bb65705bf6578646d85dd3f1 to your computer and use it in GitHub Desktop.
Save mapehe/b3f64857bb65705bf6578646d85dd3f1 to your computer and use it in GitHub Desktop.
Script for inserting timesheets for an interval
#!/bin/bash
MONTH=05
START_DAY=01
START_DAY=28
PREPARE=$(cat << EOF
DELETE FROM timesheet_entry;
DELETE FROM timesheet;
DELETE FROM task;
INSERT INTO task (project_id, name, created, updated, billable, status) VALUES (1, 'Eka', NOW(), NOW(), TRUE, 'ACTIVE');
INSERT INTO task (project_id, name, created, updated, billable, status) VALUES (2, 'Toka', NOW(), NOW(), TRUE, 'ACTIVE');
INSERT INTO timesheet (project_id, employee_id, name, allocation, created, updated, status) VALUES (1, 1, 'Eka', 100, NOW(), NOW(), 'ACTIVE');
INSERT INTO timesheet (project_id, employee_id, name, allocation, created, updated, status) VALUES (2, 2, 'Toka', 100, NOW(), NOW(), 'ACTIVE');
EOF
)
INSERT=$(cat << EOF
INSERT INTO timesheet_entry (timesheet_id, task_id, time_category_id, quantity, date, created, updated)
VALUES (
(SELECT id FROM timesheet WHERE name='Eka'),
(SELECT id FROM task WHERE name='Eka'),
(SELECT id FROM time_category WHERE name='Konsultointi'),
5, :v1, NOW(), NOW());
INSERT INTO timesheet_entry (timesheet_id, task_id, time_category_id, quantity, date, created, updated)
VALUES (
(SELECT id FROM timesheet WHERE name='Toka'),
(SELECT id FROM task WHERE name='Toka'),
(SELECT id FROM time_category WHERE name='Konsultointi'),
5, :v1, NOW(), NOW());
EOF
)
echo $PREPARE | PGPASSWORD=password psql -h localhost -U user -d epoc
for i in $(seq $START_DAY $END)
do
echo $INSERT | PGPASSWORD=password psql -h localhost -U user -d epoc -v v1="'2022-$MONTH-$i'"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment