Skip to content

Instantly share code, notes, and snippets.

@redhoodie
Last active March 5, 2019 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save redhoodie/6d2f78401886c61344e85a2aec33fb35 to your computer and use it in GitHub Desktop.
Save redhoodie/6d2f78401886c61344e85a2aec33fb35 to your computer and use it in GitHub Desktop.
require 'date'
require 'active_support/time'
current_id = 123
starting_date = Date.new(2019,03,05)
times = [
[9, 0, 60],
[11, 30, 30],
[13, 30, 30],
[15, 30, 30],
[17, 30, 30],
[19, 30, 30],
]
days = 14
owner = 609907
sql_statement = ''
rows = []
sql_template = <<-SQL
SELECT * FROM SCHEDULED_EVENT ORDER BY ID DESC;
INSERT INTO SCHEDULED_EVENT (ID,
SCHEDULED_DATE,
DURATION,
STAFF_PERSON,
TYPE,
STATUS,
OWNER,
REQUESTED,
CREATE_DATE,
WEB_ID,
DIFF_HASH,
ROOM_USED,
PACKAGE_ITEM)
VALUES%s;
SQL
sql_row_template = "\n(%d, '%s', %d, 100000000017581806, 609904, 'Booked', %s, FALSE, NOW(), NULL, NULL, NULL, NULL)";
(0..days).each do |d|
date = (starting_date + d.days)
times.each do |time|
(hour, minute, duration) = time
appointment_start_time = DateTime.new(date.year, date.month, date.day, hour, minute, 0)
rows.push sql_row_template % [current_id, appointment_start_time.to_s(:db), duration, owner]
current_id = current_id + 1
end
end
puts sql_template % [rows.join(',')]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment