Skip to content

Commit

Permalink
Set NOT NULL to columns where it matters
Browse files Browse the repository at this point in the history
  • Loading branch information
tszolar committed Jul 25, 2016
1 parent 4f3e82c commit 7522a00
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 49 deletions.
87 changes: 87 additions & 0 deletions db/migrate/1469130929_add_not_null_constraints.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
Sequel.migration do
NOT_NULL_COLUMNS = {
courses: %i{
name
created_at
updated_at
},
events: %i{
starts_at
ends_at
created_at
updated_at
event_type
source_type
semester
},
faculty_semesters: %i{
code
faculty
update_parallels
first_week_parity
starts_at
teaching_ends_at
exams_start_at
ends_at
hour_starts
hour_duration
created_at
updated_at
},
parallels: %i{
parallel_type
course_id
code
semester
created_at
updated_at
faculty
},
people: %i{
full_name
access_token
created_at
updated_at
},
rooms: %i{
created_at
updated_at
},
schedule_exceptions: %i{
exception_type
name
created_at
updated_at
},
semester_periods: %i{
faculty_semester_id
created_at
updated_at
},
timetable_slots: %i{
day
parity
first_hour
duration
parallel_id
created_at
updated_at
}
}

up do
NOT_NULL_COLUMNS.each do |table, columns|
alter_table(table) do
columns.each { |column| set_column_not_null column }
end
end
end

down do
NOT_NULL_COLUMNS.each do |table, columns|
alter_table(table) do
columns.each { |column| set_column_allow_null column }
end
end
end
end
99 changes: 50 additions & 49 deletions db/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ ALTER SEQUENCE audits_id_seq OWNED BY audits.id;
CREATE TABLE courses (
id text NOT NULL,
department text,
name hstore,
created_at timestamp without time zone,
updated_at timestamp without time zone
name hstore NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);


Expand Down Expand Up @@ -341,27 +341,27 @@ CREATE TABLE events (
id bigint NOT NULL,
name hstore,
note hstore,
starts_at timestamp without time zone,
ends_at timestamp without time zone,
starts_at timestamp without time zone NOT NULL,
ends_at timestamp without time zone NOT NULL,
absolute_sequence_number integer,
created_at timestamp without time zone,
updated_at timestamp without time zone,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
teacher_ids text[],
student_ids text[],
relative_sequence_number integer,
deleted boolean DEFAULT false NOT NULL,
event_type text,
event_type text NOT NULL,
parallel_id bigint,
course_id text,
semester text,
semester text NOT NULL,
faculty integer,
capacity integer,
room_id text,
applied_schedule_exception_ids bigint[],
original_starts_at timestamp without time zone,
original_ends_at timestamp without time zone,
original_room_id text,
source_type event_source_type,
source_type event_source_type NOT NULL,
source_id text
);

Expand Down Expand Up @@ -391,19 +391,19 @@ ALTER SEQUENCE events_id_seq OWNED BY events.id;

CREATE TABLE faculty_semesters (
id integer NOT NULL,
code text,
faculty integer,
update_parallels boolean DEFAULT true,
first_week_parity integer,
starts_at date,
teaching_ends_at date,
exams_start_at date,
code text NOT NULL,
faculty integer NOT NULL,
update_parallels boolean DEFAULT true NOT NULL,
first_week_parity integer NOT NULL,
starts_at date NOT NULL,
teaching_ends_at date NOT NULL,
exams_start_at date NOT NULL,
exams_end_at date,
ends_at date,
hour_starts time without time zone[],
hour_duration integer,
created_at timestamp without time zone,
updated_at timestamp without time zone,
ends_at date NOT NULL,
hour_starts time without time zone[] NOT NULL,
hour_duration integer NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
update_other boolean DEFAULT false NOT NULL
);

Expand Down Expand Up @@ -433,17 +433,17 @@ ALTER SEQUENCE faculty_semesters_id_seq OWNED BY faculty_semesters.id;

CREATE TABLE parallels (
id bigint NOT NULL,
parallel_type text,
course_id text,
code integer,
parallel_type text NOT NULL,
course_id text NOT NULL,
code integer NOT NULL,
capacity integer,
occupied integer,
semester text,
created_at timestamp without time zone,
updated_at timestamp without time zone,
semester text NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
teacher_ids text[],
student_ids text[],
faculty integer,
faculty integer NOT NULL,
deleted_at timestamp without time zone
);

Expand Down Expand Up @@ -473,10 +473,10 @@ ALTER SEQUENCE parallels_id_seq OWNED BY parallels.id;

CREATE TABLE people (
id text NOT NULL,
full_name text,
created_at timestamp without time zone,
updated_at timestamp without time zone,
access_token uuid DEFAULT gen_random_uuid()
full_name text NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
access_token uuid DEFAULT gen_random_uuid() NOT NULL
);


Expand All @@ -491,8 +491,8 @@ CREATE TABLE rooms (
division text,
locality text,
type text,
created_at timestamp without time zone,
updated_at timestamp without time zone
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);


Expand All @@ -502,16 +502,16 @@ CREATE TABLE rooms (

CREATE TABLE schedule_exceptions (
id bigint NOT NULL,
exception_type integer,
name text,
exception_type integer NOT NULL,
name text NOT NULL,
note text,
starts_at timestamp without time zone,
ends_at timestamp without time zone,
faculty integer,
semester text,
timetable_slot_ids bigint[],
created_at timestamp without time zone,
updated_at timestamp without time zone,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
options hstore,
course_ids text[]
);
Expand Down Expand Up @@ -551,13 +551,13 @@ CREATE TABLE schema_migrations (

CREATE TABLE semester_periods (
id bigint NOT NULL,
faculty_semester_id integer,
faculty_semester_id integer NOT NULL,
starts_at date NOT NULL,
ends_at date NOT NULL,
type integer NOT NULL,
first_week_parity integer,
created_at timestamp without time zone,
updated_at timestamp without time zone,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
first_day_override integer,
irregular boolean DEFAULT false NOT NULL
);
Expand Down Expand Up @@ -588,13 +588,13 @@ ALTER SEQUENCE semester_periods_id_seq OWNED BY semester_periods.id;

CREATE TABLE timetable_slots (
id bigint NOT NULL,
day integer,
parity integer,
first_hour integer,
duration integer,
parallel_id bigint,
created_at timestamp without time zone,
updated_at timestamp without time zone,
day integer NOT NULL,
parity integer NOT NULL,
first_hour integer NOT NULL,
duration integer NOT NULL,
parallel_id bigint NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
room_id text,
deleted_at timestamp without time zone
);
Expand Down Expand Up @@ -1019,3 +1019,4 @@ INSERT INTO "schema_migrations" ("filename") VALUES ('1467309979_update_event_fu
INSERT INTO "schema_migrations" ("filename") VALUES ('1467312179_remove_source_timetable_slot_id.rb');
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');

0 comments on commit 7522a00

Please sign in to comment.