-- create new lesson package types

ALTER TABLE users ADD COLUMN first_lesson_booked_at TIMESTAMP WITHOUT TIME ZONE;
ALTER TABLE users ADD COLUMN remind_take_lesson_times INTEGER NOT NULL DEFAULT 0;
ALTER TABLE users ADD COLUMN remind_take_lesson_at TIMESTAMP WITHOUT TIME ZONE;
ALTER TABLE users ADD COLUMN sent_first_lesson_instr_email_at TIMESTAMP WITHOUT TIME ZONE;
ALTER TABLE lesson_sessions ADD COLUMN sent_early_starting_notice BOOLEAN NOT NULL DEFAULT FALSE;

CREATE INDEX index_remind_take_lesson_times ON users USING btree(remind_take_lesson_times);
CREATE INDEX index_sent_first_lesson_instr_email_at ON users USING btree(sent_first_lesson_instr_email_at);
CREATE INDEX index_sent_early_starting_notice ON lesson_sessions USING btree(sent_early_starting_notice);
CREATE INDEX index_sen_starting_notice ON lesson_sessions USING btree(sent_starting_notice);



-- bootstrap first_lesson_booked_at
UPDATE users SET first_lesson_booked_at = (SELECT lesson_sessions.created_at FROM lesson_sessions WHERE users.id = lesson_sessions.user_id ORDER BY lesson_sessions.created_at LIMIT 1);