CREATE TABLE stops_on_trip (
	_tripID varchar(30) not null,
	_stopID varchar(7) not null,
	_stopSeq integer NOT NULL,
	_stopDept DATETIME NOT NULL,
	_stopDeptOnNextDay boolean not NULL,
	_stopArri DATETIME NOT NULL,
	_stopArriOnNextDay boolean not NULL,
	PRIMARY KEY(_tripID, _stopID, _stopSeq)
);

CREATE TABLE trips (
	_tripID varchar(30) NOT NULL,
	_routeID varchar(4) not null,
	_serviceID varchar(15) NOT NULL,
	_tripHeadSign varchar(17) not null,
	PRIMARY KEY(_tripID)
);

CREATE TABLE trips_freq (
	_tripID varchar(30) NOT NULL,
	_start DATETIME NOT NULL,
	_end DATETIME NOT NULL,
	_end_next_day boolean not null,
	_headways integer not null,
	_freq integer default null
);

CREATE TABLE routes (
	_routeID varchar(4) not null,
	_agencyID varchar(3) not null,
	_routeName varchar(5) NOT NULL,
	_routeLongName varchar(80) NOT NULL,
	_routeType varchar(6) not NULL,
	PRIMARY KEY(_routeID)
);

CREATE TABLE schedule_rules (
	_serviceID varchar(15) NOT NULL,
	_serviceDay varchar(3) not null,
	_startPeriodDate DATE not null,
	_endPeriodDate DATE not null,
	PRIMARY KEY(_serviceID, _serviceDay)
);

CREATE TABLE stop_names (
	_stopID varchar(7) PRIMARY KEY not null,
	_stopName varchar(50) not null,
	_stopNameMarathi varchar(80) ,
	_stopRoad varchar(50) ,
	_stopArea varchar(50) 
);

CREATE TABLE stop_geo (
	_stopID varchar(7) PRIMARY KEY not null,
	_stopLat number NOT NULL,
	_stopLon number NOT NULL
);

CREATE TABLE bus_max_freq(
	_tripID varchar( 45 ) PRIMARY KEY,
	_freq int( 5 )
);

CREATE INDEX ix_stop_names_stopName ON stop_names ( _stopName );
CREATE INDEX ix_stops_on_trip_tripID ON stops_on_trip (_tripID);
CREATE INDEX ix_stops_on_trip_stopID ON stops_on_trip (_stopID);
CREATE INDEX ix_stops_on_trip_stopSeq ON stops_on_trip (_stopSeq);
CREATE INDEX ix_stops_on_trip_stopDept ON stops_on_trip (_stopDept);
CREATE INDEX ix_stops_on_trip_stopArri ON stops_on_trip (_stopArri);
CREATE INDEX ix_stops_on_trip_stopDeptOnNextDay ON stops_on_trip (_stopDeptOnNextDay);
CREATE INDEX ix_stops_on_trip_stopArriOnNextDay ON stops_on_trip (_stopArriOnNextDay);
CREATE INDEX ix_stops_on_trip_stopDeptEx ON stops_on_trip (_stopDept,_stopDeptOnNextDay);
CREATE INDEX ix_stops_on_trip_stopArriEx ON stops_on_trip (_stopArri,_stopArriOnNextDay);
CREATE INDEX ix_trips_routeID ON trips (_routeID);
CREATE INDEX ix_trips_serviceID ON trips (_serviceID);
CREATE INDEX ix_trips_tripHeadSign ON trips (_tripHeadSign);
CREATE INDEX ix_trips_freq_tripID ON trips_freq (_tripID);
CREATE INDEX ix_routes_agencyID ON routes (_agencyID);
CREATE INDEX ix_routes_routeName ON routes (_routeName);
CREATE INDEX ix_routes_routeType ON routes (_routeType);
CREATE INDEX ix_schedule_rules_serviceID ON schedule_rules (_serviceID);
CREATE INDEX ix_schedule_rules_serviceDay ON schedule_rules (_serviceDay);
CREATE INDEX ix_schedule_rules_startPeriodDate ON schedule_rules (_startPeriodDate);
CREATE INDEX ix_schedule_rules_endPeriodDate ON schedule_rules (_endPeriodDate);