Skip to content

Commit

Permalink
Convert textual enums to proper enums
Browse files Browse the repository at this point in the history
  • Loading branch information
tszolar committed Jul 25, 2016
1 parent 7522a00 commit 3612c9c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
17 changes: 17 additions & 0 deletions db/migrate/1469463514_convert_text_to_enum.rb
@@ -0,0 +1,17 @@
Sequel.migration do
up do
extension :pg_enum
create_enum :event_type, %w(lecture tutorial laboratory course_event exam assessment teacher_timetable_slot)
set_column_type :events, :event_type, :event_type, using: 'event_type::event_type'
create_enum :parallel_type, %w(lecture tutorial laboratory)
set_column_type :parallels, :parallel_type, :parallel_type, using: 'parallel_type::parallel_type'
end

down do
extension :pg_enum
set_column_type :events, :event_type, :text
drop_enum :event_type
set_column_type :parallels, :parallel_type, :text
drop_enum :parallel_type
end
end
31 changes: 29 additions & 2 deletions db/schema.sql
Expand Up @@ -67,6 +67,32 @@ CREATE TYPE event_source_type AS ENUM (
);


--
-- Name: event_type; Type: TYPE; Schema: public; Owner: -
--

CREATE TYPE event_type AS ENUM (
'lecture',
'tutorial',
'laboratory',
'course_event',
'exam',
'assessment',
'teacher_timetable_slot'
);


--
-- Name: parallel_type; Type: TYPE; Schema: public; Owner: -
--

CREATE TYPE parallel_type AS ENUM (
'lecture',
'tutorial',
'laboratory'
);


--
-- Name: create_event(bigint, timestamp without time zone, timestamp without time zone, text); Type: FUNCTION; Schema: public; Owner: -
--
Expand Down Expand Up @@ -350,7 +376,7 @@ CREATE TABLE events (
student_ids text[],
relative_sequence_number integer,
deleted boolean DEFAULT false NOT NULL,
event_type text NOT NULL,
event_type event_type NOT NULL,
parallel_id bigint,
course_id text,
semester text NOT NULL,
Expand Down Expand Up @@ -433,7 +459,7 @@ ALTER SEQUENCE faculty_semesters_id_seq OWNED BY faculty_semesters.id;

CREATE TABLE parallels (
id bigint NOT NULL,
parallel_type text NOT NULL,
parallel_type parallel_type NOT NULL,
course_id text NOT NULL,
code integer NOT NULL,
capacity integer,
Expand Down Expand Up @@ -1020,3 +1046,4 @@ INSERT INTO "schema_migrations" ("filename") VALUES ('1467312179_remove_source_t
INSERT INTO "schema_migrations" ("filename") VALUES ('1467918523_add_absolute_sequence_numbers_to_course_events_exams.rb');
INSERT INTO "schema_migrations" ("filename") VALUES ('1469128840_remove_unused_tables.rb');
INSERT INTO "schema_migrations" ("filename") VALUES ('1469130929_add_not_null_constraints.rb');
INSERT INTO "schema_migrations" ("filename") VALUES ('1469463514_convert_text_to_enum.rb');

0 comments on commit 3612c9c

Please sign in to comment.