--
--


SELECT pg_catalog.set_config('search_path', '', false);

--
-- Name: public; Type: SCHEMA; Schema: -; Owner: rdsadmin
--

-- *not* creating schema, since initdb creates it


ALTER SCHEMA public OWNER TO rdsadmin;

--
-- Name: tp_gnx_alert; Type: SCHEMA; Schema: -; Owner: tsbdbadmin
--

CREATE SCHEMA tp_gnx_alert;


ALTER SCHEMA tp_gnx_alert OWNER TO tsbdbadmin;

--
-- Name: tp_gnx_location; Type: SCHEMA; Schema: -; Owner: tsbdbadmin
--

CREATE SCHEMA tp_gnx_location;


ALTER SCHEMA tp_gnx_location OWNER TO tsbdbadmin;

--
-- Name: tp_location; Type: SCHEMA; Schema: -; Owner: tsbdbadmin
--

CREATE SCHEMA tp_location;


ALTER SCHEMA tp_location OWNER TO tsbdbadmin;

--
-- Name: tp_mifare_card_trip; Type: SCHEMA; Schema: -; Owner: tsbdbadmin
--

CREATE SCHEMA tp_mifare_card_trip;


ALTER SCHEMA tp_mifare_card_trip OWNER TO tsbdbadmin;

--
-- Name: tp_notification; Type: SCHEMA; Schema: -; Owner: tsbdbadmin
--

CREATE SCHEMA tp_notification;


ALTER SCHEMA tp_notification OWNER TO tsbdbadmin;

--
-- Name: tp_notification_log; Type: SCHEMA; Schema: -; Owner: tsbdbadmin
--

CREATE SCHEMA tp_notification_log;


ALTER SCHEMA tp_notification_log OWNER TO tsbdbadmin;

--
-- Name: tp_vehicle_activity; Type: SCHEMA; Schema: -; Owner: tsbdbadmin
--

CREATE SCHEMA tp_vehicle_activity;


ALTER SCHEMA tp_vehicle_activity OWNER TO tsbdbadmin;

--
-- Name: cube; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS cube WITH SCHEMA public;


--
-- Name: EXTENSION cube; Type: COMMENT; Schema: -; Owner: 
--

COMMENT ON EXTENSION cube IS 'data type for multidimensional cubes';


--
-- Name: dblink; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS dblink WITH SCHEMA public;


--
-- Name: EXTENSION dblink; Type: COMMENT; Schema: -; Owner: 
--

COMMENT ON EXTENSION dblink IS 'connect to other PostgreSQL databases from within a database';


--
-- Name: earthdistance; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS earthdistance WITH SCHEMA public;


--
-- Name: EXTENSION earthdistance; Type: COMMENT; Schema: -; Owner: 
--

COMMENT ON EXTENSION earthdistance IS 'calculate great-circle distances on the surface of the Earth';


--
-- Name: account_type; Type: TYPE; Schema: public; Owner: tsbdbadmin
--

CREATE TYPE public.account_type AS ENUM (
    'demo',
    'real'
);


ALTER TYPE public.account_type OWNER TO tsbdbadmin;

--
-- Name: enum_gender; Type: TYPE; Schema: public; Owner: tsbdbadmin
--

CREATE TYPE public.enum_gender AS ENUM (
    'Male',
    'Female'
);


ALTER TYPE public.enum_gender OWNER TO tsbdbadmin;

--
-- Name: enum_yes_no; Type: TYPE; Schema: public; Owner: tsbdbadmin
--

CREATE TYPE public.enum_yes_no AS ENUM (
    'Yes',
    'No'
);


ALTER TYPE public.enum_yes_no OWNER TO tsbdbadmin;

--
-- Name: enumactive; Type: TYPE; Schema: public; Owner: tsbdbadmin
--

CREATE TYPE public.enumactive AS ENUM (
    'active',
    'inactive'
);


ALTER TYPE public.enumactive OWNER TO tsbdbadmin;

--
-- Name: invoice_status; Type: TYPE; Schema: public; Owner: tsbdbadmin
--

CREATE TYPE public.invoice_status AS ENUM (
    'invoiced',
    'paid',
    'cancelled'
);


ALTER TYPE public.invoice_status OWNER TO tsbdbadmin;

--
-- Name: payment_mode; Type: TYPE; Schema: public; Owner: tsbdbadmin
--

CREATE TYPE public.payment_mode AS ENUM (
    'paypal',
    'bank',
    'wire-transfer',
    'cheque',
    'DD',
    'others',
    'by cash'
);


ALTER TYPE public.payment_mode OWNER TO tsbdbadmin;

--
-- Name: payment_status; Type: TYPE; Schema: public; Owner: tsbdbadmin
--

CREATE TYPE public.payment_status AS ENUM (
    'active',
    'waiting',
    'refund'
);


ALTER TYPE public.payment_status OWNER TO tsbdbadmin;

--
-- Name: payment_type; Type: TYPE; Schema: public; Owner: tsbdbadmin
--

CREATE TYPE public.payment_type AS ENUM (
    'subscription',
    'hardware',
    'service',
    'device',
    'accessories',
    'by cash'
);


ALTER TYPE public.payment_type OWNER TO tsbdbadmin;

--
-- Name: transportation_type; Type: TYPE; Schema: public; Owner: tsbdbadmin
--

CREATE TYPE public.transportation_type AS ENUM (
    'free',
    'charged'
);


ALTER TYPE public.transportation_type OWNER TO tsbdbadmin;

--
-- Name: tsbstatus; Type: TYPE; Schema: public; Owner: tsbdbadmin
--

CREATE TYPE public.tsbstatus AS ENUM (
    'active',
    'deactive',
    'removed'
);


ALTER TYPE public.tsbstatus OWNER TO tsbdbadmin;

--
-- Name: add_attendance_trigg_function(); Type: FUNCTION; Schema: public; Owner: tsbdbadmin
--

CREATE FUNCTION public.add_attendance_trigg_function() RETURNS trigger
    LANGUAGE plpgsql
    AS $$



DECLARE 

       new_student_id INTEGER;

       attendance_vehicleid INTEGER;

       attendance_count INTEGER;

       latitude numeric;

       longitude numeric;

       time_diff INTEGER;

       countstudent INTEGER;

       last_swipe time;

       shift_endtime time;

       droponly_flag INTEGER;

BEGIN

      IF (TG_OP = 'INSERT') THEN

droponly_flag=0;

            SELECT INTO new_student_id tsb_student.student_id FROM tsb_student WHERE tsb_student.student_mifare_card_id = NEW.mifare_card_id;

  IF (new_student_id IS NOT NULL) THEN

            SELECT INTO attendance_count COALESCE(max(attendance_flag_position),0) FROM tsb_attendance WHERE attendance_student_id = new_student_id and attendance_date = NEW.logged_date;

   attendance_count=attendance_count+1;

select INTO shift_endtime shift_end_time from tsb_shift,tsb_student where student_session=shift_id and tsb_student.student_id=new_student_id limit 1;

IF (shift_endtime<=NEW.logged_time) THEN

    IF (attendance_count<=2) THEN

attendance_count=3;

droponly_flag=1;

END IF;

END IF;

        IF (attendance_count<=4) THEN

            longitude=NEW.longitude;

            latitude=NEW.latitude;

            IF (NEW.longitude_direction = 'W') THEN

                longitude=NEW.longitude*-1;

            END IF;

            IF (NEW.latitude_direction = 'S') THEN

                latitude=NEW.latitude*-1;

            END IF;

select INTO attendance_vehicleid vehicle_id from tsb_vehicle where vehicle_imei=NEW.imei limit 1;

           IF (attendance_count=1 OR droponly_flag=1) THEN

                INSERT INTO tsb_attendance(attendance_student_id, attendance_date, attendance_check_in_out, attendance_flag_position,attendance_latitude,attendance_longitude,attendance_manual_attendance,attendance_vehicle_id) VALUES (new_student_id, NEW.logged_date, NEW.logged_time,attendance_count,latitude,longitude,NEW.mifare_card_manual_attendance,attendance_vehicleid);

            ELSE

               SELECT INTO time_diff COALESCE((EXTRACT(EPOCH FROM NEW.logged_time - attendance_check_in_out))::Integer,200) FROM tsb_attendance WHERE attendance_student_id = new_student_id and attendance_date = NEW.logged_date order by attendance_flag_position DESC limit 1;

                IF (time_diff>180) THEN

                    INSERT INTO tsb_attendance(attendance_student_id, attendance_date, attendance_check_in_out, attendance_flag_position,attendance_latitude,attendance_longitude,attendance_manual_attendance,attendance_vehicle_id) VALUES (new_student_id, NEW.logged_date, NEW.logged_time,attendance_count,latitude,longitude,NEW.mifare_card_manual_attendance,attendance_vehicleid );

                END IF;

            END IF;

        END IF;

        END IF;

        END IF;

      RETURN NULL;

END;

$$;


ALTER FUNCTION public.add_attendance_trigg_function() OWNER TO tsbdbadmin;

--
-- Name: add_vehicle_while_signaling(); Type: FUNCTION; Schema: public; Owner: tsbdbadmin
--

CREATE FUNCTION public.add_vehicle_while_signaling() RETURNS trigger
    LANGUAGE plpgsql
    AS $$


DECLARE 
     vehicle_count INTEGER;
BEGIN

    IF (TG_OP = 'INSERT') THEN
        SELECT INTO vehicle_count COALESCE(count(vehicle_imei),0) FROM tsb_vehicle WHERE vehicle_imei = new.imei and vehicle_status ='active';
        IF(vehicle_count=0) THEN
            INSERT INTO tsb_vehicle(vehicle_imei, vehicle_number, vehicle_reg_no) VALUES (NEW.imei,NEW.imei,NEW.imei);   
        END IF;
    END IF;
RETURN NULL;
END;


$$;


ALTER FUNCTION public.add_vehicle_while_signaling() OWNER TO tsbdbadmin;

--
-- Name: dblink_connect_masterdb(); Type: FUNCTION; Schema: public; Owner: tsbdbadmin
--

CREATE FUNCTION public.dblink_connect_masterdb() RETURNS character varying
    LANGUAGE plpgsql
    AS $$

 
 
 DECLARE 
connects VARCHAR; 
masterdb_name VARCHAR;
BEGIN	
masterdb_name=dblink_get_masterdb_name();
connects='hostaddr=127.0.0.1 dbname='||masterdb_name||' user=tsbdbadmin password=adminTSBDB123';
RETURN connects;
END;
  

$$;


ALTER FUNCTION public.dblink_connect_masterdb() OWNER TO tsbdbadmin;

--
-- Name: dblink_get_masterdb_name(); Type: FUNCTION; Schema: public; Owner: tsbdbadmin
--

CREATE FUNCTION public.dblink_get_masterdb_name() RETURNS character varying
    LANGUAGE plpgsql
    AS $$


    DECLARE 
BEGIN   
RETURN 'vt_masterdb';
END;

$$;


ALTER FUNCTION public.dblink_get_masterdb_name() OWNER TO tsbdbadmin;

--
-- Name: partition_function_attendance_user(); Type: FUNCTION; Schema: public; Owner: tsbdbadmin
--

CREATE FUNCTION public.partition_function_attendance_user() RETURNS trigger
    LANGUAGE plpgsql
    AS $_$



DECLARE

    _new_date text;

    _tablename text;

    _parent_tablename text;

    _schemaname text;

    _primary_column text;

    _check_column text;

    _newcheck_column text;

    notificationtext text; 

    rec record;

    tripid INTEGER;   

    triphistory INTEGER; 

    vehicleid INTEGER; 

    routeid INTEGER;

    helperid INTEGER;    

    driverid INTEGER; 

    shiftid INTEGER;

    newtripid INTEGER;

    newhelperid INTEGER;    

    newdriverid INTEGER;

    usertype VARCHAR;    

    ttype VARCHAR;    

    triptype VARCHAR;  

    vehicle_reg VARCHAR;  

    vehicle_num VARCHAR;   

    BEGIN

--Takes the current inbound 'time' value and determines when midnight is for the given date

    _parent_tablename:='tsb_attendance_user';

    _schemaname:='tp_attendance_user';

    _primary_column:='attendance_id';

    _check_column:='attendance_date';

    _newcheck_column=NEW.attendance_date;

    _new_date := translate(_newcheck_column::text,'-','_');

    _tablename := _parent_tablename||'_'||_new_date;

-- Check if the partition needed for the current record exists

    PERFORM 1

    FROM   pg_catalog.pg_class c

    JOIN   pg_catalog.pg_namespace n ON n.oid = c.relnamespace

    WHERE  c.relkind = 'r'

    AND    c.relname = _tablename

    AND    n.nspname = _schemaname;

-- If the partition needed does not yet exist, then we create it:

-- Note that || is string concatenation (joining two strings to make one)

    IF NOT FOUND THEN

        EXECUTE 'CREATE TABLE '|| _schemaname||'.' ||_tablename || ' (check ('||_check_column||' = ''' ||_newcheck_column || ''')) INHERITS (public.'|| _parent_tablename ||')';

    -- Table permissions are not inherited from the parent.

    -- If permissions change on the master be sure to change them on the child also.

        EXECUTE 'ALTER TABLE '|| _schemaname||'.' || quote_ident(_tablename) || ' OWNER TO tsbdbadmin';

        EXECUTE 'GRANT ALL ON TABLE '|| _schemaname||'.' || quote_ident(_tablename) || ' TO tsbdbadmin';

    -- Indexes are defined per child, so we assign a default index that uses the partition columns

        EXECUTE 'CREATE INDEX ' || quote_ident(_tablename||'_indx1') || ' ON '|| _schemaname||'.'|| quote_ident(_tablename) || ' ('|| _primary_column ||')';

    END IF;

-- Insert the current record into the correct partition, which we are sure will now exist.

    EXECUTE 'INSERT INTO '|| _schemaname||'.' || quote_ident(_tablename) || ' VALUES ($1.*)' USING NEW;

    triptype:='';

    SELECT INTO usertype user_role  FROM tsb_user where user_id=NEW.attendance_user_id and user_status = 'active';

    IF(usertype='driver') THEN

        SELECT INTO tripid,vehicleid,driverid,helperid,ttype trip_id,trip_vehicle_id ,trip_driver_id,trip_helper_id,trip_type  FROM tsb_trip

        where ((trip_start_time > NEW.attendance_check_in_out - INTERVAL '90 min') and (trip_start_time < NEW.attendance_check_in_out + INTERVAL '90 min')) and trip_status='active' and trip_driver_id=NEW.attendance_user_id and trip_vehicle_id=NEW.attendance_vehicle_id;

    ELSIF(usertype='helper') THEN

        SELECT INTO tripid,vehicleid,driverid,helperid,ttype trip_id,trip_vehicle_id ,trip_driver_id,trip_helper_id,trip_type  FROM tsb_trip

        where ((trip_start_time > NEW.attendance_check_in_out - INTERVAL '90 min') and (trip_start_time < NEW.attendance_check_in_out + INTERVAL '90 min')) and trip_status='active'  and trip_helper_id=NEW.attendance_user_id and trip_vehicle_id=NEW.attendance_vehicle_id;

    END IF; 

-- IF Trip exists enter to trip hisytory

    IF(tripid>0) THEN

        SELECT INTO triphistory trips_history_id  FROM tsb_trips_history where trips_history_trip_id=tripid and trips_history_start_date=NEW.attendance_date;

        IF(triphistory>0) THEN

            IF (NEW.attendance_flag_position%2 =0) THEN

                UPDATE tsb_trips_history set trips_history_end_time = NEW.attendance_check_in_out,trips_history_status = 'completed',trips_history_end_date=NEW.attendance_date  where trips_history_trip_id=tripid and trips_history_end_date=NEW.attendance_date;

            END IF;

            IF(usertype='driver') THEN

                UPDATE tsb_trips_history set trips_history_driver_id = driverid  where trips_history_trip_id=tripid and trips_history_end_date=NEW.attendance_date;

            ELSIF(usertype='helper') THEN

                UPDATE tsb_trips_history set trips_history_helper_id = helperid  where trips_history_trip_id=tripid and trips_history_end_date=NEW.attendance_date;

            END IF;

        ELSE

            INSERT INTO tsb_trips_history(trips_history_trip_id,trip_history_type,trips_history_driver_id,trips_history_start_date,trips_history_start_time,trips_history_status,trips_history_vehicle_id,trips_history_helper_id,trips_history_trip_type,trips_history_shift_id)

            VALUES (tripid, 'scheduled', driverid, NEW.attendance_date,NEW.attendance_check_in_out,'started', vehicleid,helperid,ttype,shiftid);

        END IF; 

    ELSE

-- IF no trip found for both user and vehicle, check with OR condition and reassign

        IF (NEW.attendance_flag_position%2 !=0) THEN

            IF(usertype ='driver') THEN

                select INTO tripid,vehicleid,driverid,helperid,ttype trip_id,trip_vehicle_id ,trip_driver_id,trip_helper_id,trip_type  

                from tsb_trip

                where ((trip_start_time > NEW.attendance_check_in_out - INTERVAL '90 min') and (trip_start_time < NEW.attendance_check_in_out + INTERVAL '90 min')) and (trip_driver_id=NEW.attendance_user_id or trip_vehicle_id= NEW.attendance_vehicle_id)  

                order by abs(extract(epoch from (trip_start_time -  NEW.attendance_check_in_out)));

                IF(tripid > 0) THEN

                    select INTO vehicle_reg,vehicle_num vehicle_reg_no,vehicle_number from tsb_vehicle where vehicle_id=vehicleid;

                    IF(driverid=NEW.attendance_user_id) THEN

                        UPDATE tsb_trip set trip_vehicle_id = NEW.attendance_vehicle_id where trip_id=tripid;

                        notificationtext='School vehicle changed, new vehicle details is,  Vehicle Number -'||vehicle_num||', Vehicle Register Number'||vehicle_reg;

                    --Send notification to Parents

                        FOR rec IN (SELECT * FROM tsb_user

                            inner join tsb_student on student_parent_id =user_id

                            inner join tsb_pickup on pickup_student_id =student_id

                            inner join tsb_pickup_point on pickup_point_id =pickup_pickup_point_id

                            inner join tsb_trip on trip_id =pickup_point_trip_id

                            where user_role='parent' and trip_id=tripid and trip_status='active' and user_status='active' and student_status='active' and pickup_point_status='active' and pickup_status='active')

                        LOOP

                            INSERT INTO tsb_notification(notification_text, notification_date, notification_time, notification_type,notification_status,notification_user_id) VALUES (notificationtext, now()::date, now()::timestamp(0),'alert','unread',rec.user_id );

                        END LOOP;

                    ELSE

                        UPDATE tsb_trip set trip_driver_id = NEW.attendance_user_id where trip_id=tripid;

                        notificationtext='Driver reassigned to  Vehicle Number -'||vehicle_num||', Vehicle Register Number'||vehicle_reg;

                    END IF;

                --Send notification to all TM

                    FOR rec IN (SELECT * FROM tsb_user where user_status='active' and (user_role='transport-manager' or  user_role='customer'))

                    LOOP

                        INSERT INTO tsb_notification(notification_text, notification_date, notification_time, notification_type,notification_status,notification_user_id) VALUES (notificationtext, now()::date, now()::timestamp(0),'alert','unread',rec.user_id );

                    END LOOP;

                END IF;

                ELSIF(usertype='helper') THEN

                    --select INTO tripid,vehicleid,driverid,helperid,ttype trip_id,trip_vehicle_id ,trip_driver_id,trip_helper_id,trip_type  

                    --from tsb_trip

                    --where (DATE_PART('hour', trip_start_time - NEW.attendance_check_in_out) = 0) 

                    -- and ( trip_helper_id=NEW.attendance_user_id or trip_vehicle_id= NEW.attendance_vehicle_id)  

                    --order by abs(extract(epoch from (trip_start_time -  NEW.attendance_check_in_out)));

                    select INTO tripid,vehicleid,driverid,helperid,ttype trip_id,trip_vehicle_id ,trip_driver_id,trip_helper_id,trip_type  

                    from tsb_trip

                    where ((trip_start_time > NEW.attendance_check_in_out - INTERVAL '90 min') and (trip_start_time < NEW.attendance_check_in_out + INTERVAL '90 min'))

                    and ( trip_helper_id=NEW.attendance_user_id or trip_vehicle_id= NEW.attendance_vehicle_id)  

                    order by abs(extract(epoch from (trip_start_time -  NEW.attendance_check_in_out)));

                    IF(tripid>0) THEN

                        select INTO vehicle_reg,vehicle_num vehicle_reg_no,vehicle_number from tsb_vehicle where vehicle_id=vehicleid;

                        IF(helperid=NEW.attendance_user_id) THEN

                            UPDATE tsb_trip set trip_vehicle_id = NEW.attendance_vehicle_id where trip_id=tripid;

                            notificationtext='School vehicle changed, new vehicle details is,  Vehicle Number -'||vehicle_num||', Vehicle Register Number'||vehicle_reg;

                            --Send notification to Parents

                            FOR rec IN (SELECT * FROM tsb_user

                            inner join tsb_student on student_parent_id =user_id

                            inner join tsb_pickup on pickup_student_id =student_id

                            inner join tsb_pickup_point on pickup_point_id =pickup_pickup_point_id

                            inner join tsb_trip on trip_id =pickup_point_trip_id

                            where user_role='parent' and trip_id=tripid and trip_status='active' and user_status='active' and student_status='active' and pickup_point_status='active' and pickup_status='active')

                            LOOP

                                INSERT INTO tsb_notification(notification_text, notification_date, notification_time, notification_type,notification_status,notification_user_id) VALUES (notificationtext, now()::date, now()::timestamp(0),'alert','unread',rec.user_id );

                            END LOOP;

                        ELSE

                            UPDATE tsb_trip set trip_helper_id = NEW.attendance_user_id where trip_id=tripid;

                            notificationtext='Bus assistant reassigned to  Vehicle Number -'||vehicle_num||', Vehicle Register Number'||vehicle_reg;

                        END IF;

                    --Send notification to all TM

                        FOR rec IN (SELECT * FROM tsb_user where user_status='active' and (user_role='transport-manager' or  user_role='customer'))

                        LOOP

                            INSERT INTO tsb_notification(notification_text, notification_date, notification_time, notification_type,notification_status,notification_user_id) VALUES (notificationtext, now()::date, now()::timestamp(0),'alert','unread',rec.user_id );

                        END LOOP;

                    END IF;

                END IF; 

            END IF;

        END IF;             

RETURN NULL;

END;


$_$;


ALTER FUNCTION public.partition_function_attendance_user() OWNER TO tsbdbadmin;

--
-- Name: partition_function_gnx_alert(); Type: FUNCTION; Schema: public; Owner: tsbdbadmin
--

CREATE FUNCTION public.partition_function_gnx_alert() RETURNS trigger
    LANGUAGE plpgsql
    AS $_$
DECLARE

_new_date text;
_tablename text;
_parent_tablename text;
_schemaname text;
_primary_column text;
_check_column text;
_newcheck_column text;

latitude numeric;
longitude numeric;
vehiclenumber VARCHAR;
vehicleregno VARCHAR; 
notificationtype VARCHAR;
notificationtext VARCHAR;
newtext VARCHAR;
customername VARCHAR;
vehicleid INTEGER;
poweron INTEGER;
poweroff INTEGER;
batterylow INTEGER;
simtrayopen INTEGER;
boxcoveropen INTEGER;
boxcoverclose INTEGER;
bateryremove INTEGER;
seatbelt INTEGER;
harshaccelaration INTEGER;
harshbrak INTEGER;
hardwareid INTEGER;
sendsms BOOLEAN;
rec record;
default_alert VARCHAR;
web_url VARCHAR;
android_url VARCHAR;
IOS_url VARCHAR;


BEGIN
sendsms = FALSE;
--Takes the current inbound 'time' value and determines when midnight is for the given date

    _parent_tablename:='gnx_alert';
    _schemaname:='tp_gnx_alert';
    _primary_column:='id';
    _check_column:='logged_date';
    _newcheck_column=NEW.logged_date;
        _new_date := translate(_newcheck_column::text,'-','_');
    _tablename := _parent_tablename||'_'||_new_date;

-- Check if the partition needed for the current record exists

    PERFORM 1
    FROM   pg_catalog.pg_class c
    JOIN   pg_catalog.pg_namespace n ON n.oid = c.relnamespace
    WHERE  c.relkind = 'r'
    AND    c.relname = _tablename
    AND    n.nspname = _schemaname;
    
-- If the partition needed does not yet exist, then we create it:
-- Note that || is string concatenation (joining two strings to make one)

    IF NOT FOUND THEN
        EXECUTE 'CREATE TABLE '|| _schemaname||'.' ||_tablename || ' (check ('||_check_column||' = ''' ||_newcheck_column || ''')) INHERITS (public.'|| _parent_tablename ||')';

    -- Table permissions are not inherited from the parent.
    -- If permissions change on the master be sure to change them on the child also.

        EXECUTE 'ALTER TABLE '|| _schemaname||'.' || quote_ident(_tablename) || ' OWNER TO tsbdbadmin';
        EXECUTE 'GRANT ALL ON TABLE '|| _schemaname||'.' || quote_ident(_tablename) || ' TO tsbdbadmin';

    -- Indexes are defined per child, so we assign a default index that uses the partition columns

        EXECUTE 'CREATE INDEX ' || quote_ident(_tablename||'_indx1') || ' ON '|| _schemaname||'.' || quote_ident(_tablename) || ' ('|| _primary_column ||')';
        EXECUTE 'ALTER TABLE ONLY '|| _schemaname||'.' || quote_ident(_tablename) || ' ADD CONSTRAINT alert_pkey'||'_'||_new_date ||' PRIMARY KEY (id)';
    END IF;

-- Insert the current record into the correct partition, which we are sure will now exist.

    SELECT INTO default_alert,web_url,android_url,IOS_url alert_default_status,alert_type_url_web,alert_type_url_android,alert_type_url_ios FROM gnx_alert_type
    join gnx_alert on alert_type = alert_type_alert_id
    join tsb_vehicle on vehicle_imei = imei and vehicle_device_type = alert_type_hardware_id and vehicle_status = 'active'
    where imei  = NEW.imei limit 1;
IF(default_alert = 'pending') THEN 
default_alert = 'pending';
ELSE
        default_alert = 'ignore';
    END IF;
    EXECUTE format('INSERT INTO '|| _schemaname|| '.' || quote_ident(_tablename) || ' (imei,cur_time,cur_date,logged_time,logged_date,gps_data_valid,latitude,latitude_direction,longitude,longitude_direction,alert_type,packet_type,packet_length,alert_status,alert_value,alert_description)
                        VALUES ($1,'||'$2'||',$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16)') USING NEW.imei,NEW.cur_time,NEW.cur_date,NEW.logged_time,NEW.logged_date,NEW.gps_data_valid,NEW.latitude,NEW.latitude_direction,NEW.longitude,NEW.longitude_direction,NEW.alert_type,NEW.packet_type,NEW.packet_length, default_alert,NEW.alert_value,NEW.alert_description;

    


    sendsms = FALSE;
    IF (TG_OP = 'INSERT') THEN 
        
        IF(default_alert = 'pending') THEN

            SELECT INTO poweron,poweroff,batterylow,simtrayopen,boxcoveropen,boxcoverclose,bateryremove,seatbelt,harshaccelaration,harshbrak  notification_settings_power_on,notification_settings_power_off,notification_settings_battery_low,notification_settings_simtary_open,notification_settings_boxcover_open,notification_settings_boxcover_close,notification_settings_battery_remove,notification_settings_seat_belt,notification_settings_harsh_accelaration,notification_settings_harsh_brak FROM tsb_notification_settings;
            notificationtype='alert';
            IF (NEW.gps_data_valid=1) THEN
                SELECT INTO vehiclenumber,vehicleregno,vehicleid,hardwareid  vehicle_number,vehicle_reg_no,vehicle_id,vehicle_device_type FROM tsb_vehicle  where vehicle_imei=NEW.imei and vehicle_status = 'active';
                
                SELECT  INTO notificationtype,notificationtext alert_type_type,alert_type_alert_name FROM gnx_alert_type where alert_type_hardware_id = hardwareid ;       
    
                IF (notificationtext IS NOT NULL) THEN 
                    notificationtext = notificationtext||' - '||vehiclenumber||' - '|| vehicleregno|| ' at '||NEW.logged_date ||' - '||New.logged_time;
                    FOR rec IN (SELECT user_id FROM tsb_user where (user_role='transport-manager' or  user_role='customer') and user_status='active')
                    LOOP 
                        INSERT INTO tsb_push_notification(push_notification_user_id,push_notification_message,push_notification_type, push_notification_date, push_notification_time, push_notification_status,push_notification_url,push_notification_android_link,push_notification_ios_link) VALUES (rec.user_id,notificationtext,notificationtype, now()::date, now()::timestamp(0),'pending', web_url||vehicleid,android_url||vehicleid,IOS_url||vehicleid );
                    END LOOP;
    
                END IF;
    
                IF (sendsms = TRUE) THEN 
                
                    FOR rec IN (SELECT user_id,user_customer_id FROM tsb_user where (user_role = 'maintenance') and user_status='active')
                    LOOP 
                        SELECT INTO customername customer_name FROM tsb_customer where customer_id=rec.user_customer_id;
                        newtext = notificationtext||' Customer Name - '||customername;
                        INSERT INTO tsb_sms_log(sms_log_user_id,sms_log_date,sms_log_time,sms_log_msg) VALUES (rec.user_id,now()::date,now()::timestamp(0),newtext);
                        newtext = '';
                    END LOOP;
    
                END IF;
            END IF;
        END IF;
    END IF;

 
    RETURN NULL;

END;


$_$;


ALTER FUNCTION public.partition_function_gnx_alert() OWNER TO tsbdbadmin;

--
-- Name: partition_function_location(); Type: FUNCTION; Schema: public; Owner: tsbdbadmin
--

CREATE FUNCTION public.partition_function_location() RETURNS trigger
    LANGUAGE plpgsql
    AS $_$


DECLARE

_new_time text;
_schemaname text;
_tablename text;
_startdate text;
_enddate text;
_result record;

speedval INTEGER;
cnt INTEGER;
polySides INTEGER;
vehicleid INTEGER;
rashdriveid INTEGER;
driverid INTEGER;
locatioliveid INTEGER;
locationlivedate date;
locationlivetime time;
vehiclenumber VARCHAR;
notificationtext VARCHAR;
rec record;
rashdrivedate timestamp;
speedlimitseconds INTEGER;
tablefullname text; 
locationid INTEGER;
speedbreak INTEGER;

BEGIN

--Takes the current inbound 'time' value and determines when midnight is for the given date

    _new_time := translate(NEW.logged_date::text,'-','_');
    _startdate := NEW.logged_date;
    _tablename := 'gnx_location_'||_new_time;
    _schemaname := 'tp_location';

    -- Check if the partition needed for the current record exists

    PERFORM 1
        FROM pg_catalog.pg_class c
        JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
        WHERE c.relkind = 'r'
        AND c.relname = _tablename
        AND n.nspname = _schemaname;

    -- If the partition needed does not yet exist, then we create it:
    -- Note that || is string concatenation (joining two strings to make one)

    IF NOT FOUND THEN
        _enddate:=_startdate::timestamp + INTERVAL '1 day';
        EXECUTE 'CREATE TABLE ' || _schemaname || '.' ||_tablename || ' (check (logged_date = ''' || NEW.logged_date || ''')) INHERITS (public.gnx_location)';

        -- Table permissions are not inherited from the parent.
        -- If permissions change on the master be sure to change them on the child also.

        EXECUTE 'ALTER TABLE ' || _schemaname || '.' || quote_ident(_tablename) || ' OWNER TO tsbdbadmin';
        EXECUTE 'GRANT ALL ON TABLE ' || _schemaname || '.' || quote_ident(_tablename) || ' TO tsbdbadmin';

        -- Indexes are defined per child, so we assign a default index that uses the partition columns
      
        EXECUTE 'CREATE INDEX ' || quote_ident(_tablename||'_indx1') || ' ON ' || _schemaname || '.' || quote_ident(_tablename) || ' (id)';
    END IF;

    -- check same data exist for avoid repeat entries
 
    tablefullname := _schemaname||'.'||quote_ident(_tablename);
    
    EXECUTE 'SELECT  id FROM '|| _schemaname||'.' || quote_ident(_tablename) || ' where logged_time= $2 and latitude= $3 and longitude= $4 and logged_date= $1 and imei= $5 and metering_status= $6 and gps_data_valid=$7' INTO locationid
    USING NEW.logged_date, NEW.logged_time, NEW.latitude,NEW.longitude,NEW.imei,NEW.metering_status,NEW.gps_data_valid ;
    
    IF(locationid > 0) THEN
        RETURN NULL;
    END IF;

    -- Insert the current record into the correct partition, which we are sure will now exist.

    EXECUTE 'INSERT INTO ' || _schemaname || '.'  || quote_ident(_tablename) || ' VALUES ($1.*)' USING NEW;
    
    IF (TG_OP = 'INSERT') THEN

        -- PERFORM pg_notify('nodejs_watchers', TG_TABLE_NAME || ',id,' || NEW.id );

        PERFORM pg_notify('nodejs_watchers', TG_TABLE_NAME || ',' || NEW.id || ',' || NEW.imei|| ',' || NEW.latitude|| ',' || NEW.latitude_direction|| ',' || NEW.longitude|| ',' || NEW.longitude_direction|| ',' || NEW.speed || ',' || NEW.heading_angle|| ',' || NEW.logged_date|| ',' || NEW.logged_time|| ',' || NEW.metering_status);
    
        SELECT INTO speedval customer_speed_limit FROM tsb_customer;
        SELECT INTO vehiclenumber,vehicleid  vehicle_number,vehicle_id   FROM tsb_vehicle where vehicle_imei=NEW.imei;
    
        IF((NEW.gps_data_valid=1 OR NEW.gps_data_valid=2) AND (NEW.latitude!=0)) THEN
            SELECT INTO locatioliveid,locationlivedate,locationlivetime id,logged_date,logged_time FROM gnx_live_location where imei=NEW.imei;
            IF(locatioliveid > 0) THEN
                IF(NEW.logged_date > locationlivedate OR (NEW.logged_date >= locationlivedate AND NEW.logged_time > locationlivetime)) THEN
                    UPDATE gnx_live_location set imei = NEW.imei,cur_time = NEW.cur_time,cur_date = NEW.cur_date,logged_time = NEW.logged_time,logged_date = NEW.logged_date,gps_data_valid = NEW.gps_data_valid,latitude = NEW.latitude,latitude_direction = NEW.latitude_direction,longitude = NEW.longitude,longitude_direction = NEW.longitude_direction,speed = NEW.speed,heading_angle = NEW.heading_angle,metering_status = NEW.metering_status,gsm_signal_strength = NEW.gsm_signal_strength,panic_status = NEW.panic_status,total_satellites = NEW.total_satellites,packet_type = NEW.packet_type,packet_length = NEW.packet_length,power_status = NEW.power_status,odometer_reading = NEW.odometer_reading,odometer_reading_gps = NEW.odometer_reading_gps,gps_quality = NEW.gps_quality where id = locatioliveid;
                END IF; 
            ELSE
                INSERT INTO gnx_live_location (imei,cur_time,cur_date,logged_time,logged_date,gps_data_valid,latitude,latitude_direction,longitude,longitude_direction,speed,heading_angle,metering_status,gsm_signal_strength,panic_status,total_satellites,packet_type,packet_length,power_status,odometer_reading,odometer_reading_gps,gps_quality) VALUES (NEW.imei, NEW.cur_time, NEW.cur_date, NEW.logged_time, NEW.logged_date, NEW.gps_data_valid, NEW.latitude, NEW.latitude_direction, NEW.longitude, NEW.longitude_direction, NEW.speed, NEW.heading_angle, NEW.metering_status, NEW.gsm_signal_strength, NEW.panic_status, NEW.total_satellites,NEW.packet_type,NEW.packet_length,NEW.power_status,NEW.odometer_reading, NEW.odometer_reading_gps, NEW.gps_quality);
            END IF;


 SELECT INTO locatioliveid,locationlivedate,locationlivetime id,logged_date,logged_time FROM gnx_health where imei=NEW.imei;
            IF(locatioliveid > 0) THEN
                IF(NEW.logged_date > locationlivedate OR (NEW.logged_date >= locationlivedate AND NEW.logged_time > locationlivetime)) THEN
                    UPDATE gnx_health set imei = NEW.imei,cur_time = NEW.cur_time,cur_date = NEW.cur_date,logged_time = NEW.logged_time,logged_date = NEW.logged_date,gps_data_valid = NEW.gps_data_valid,metering_status = NEW.metering_status,panic_status = NEW.panic_status,packet_type = NEW.packet_type,packet_length = NEW.packet_length,battery_charge_status = NEW.power_status where id = locatioliveid;
                END IF; 
            ELSE
                INSERT INTO gnx_health (imei,cur_time,cur_date,logged_time,logged_date,gps_data_valid,panic_status,battery_charge_status,battery_charge_level,battery_voltage,pending_gprs_packets,packet_type,packet_length,metering_status) VALUES 
                                              (NEW.imei, NEW.cur_time, NEW.cur_date, NEW.logged_time, NEW.logged_date, NEW.gps_data_valid, NEW.panic_status,NEW.power_status,50,12,0,NEW.packet_type,NEW.packet_length, NEW.metering_status);
            END IF;



        END IF;
        
        SELECT INTO speedbreak notification_settings_speed_break FROM tsb_notification_settings;
        IF(speedbreak = '1') THEN
            SELECT INTO driverid vehicle_assignment_driver_id  FROM tsb_vehicle_assignment where vehicle_assignment_vehicle_id = vehicleid;
            notificationtext='Speed limit exceed of one vehicle, details are vehicle number - '||vehiclenumber||', speed - '||NEW.speed||' on '||NEW.logged_date||' '||NEW.logged_time;
            IF (NEW.speed > speedval AND (NEW.metering_status='B' OR  NEW.metering_status='e') AND NEW.gps_data_valid=1) THEN
                IF(driverid>0) THEN
                    SELECT INTO rashdrivedate,rashdriveid rash_drive_date,rash_drive_id from tsb_rash_drive where rash_drive_vehicle_id=vehicleid and rash_drive_reason='speed_exceed' and rash_drive_driver_id=driverid order by rash_drive_id desc limit 1;
                    SELECT INTO speedlimitseconds EXTRACT(EPOCH FROM (DATE_TRUNC('second',(NEW.logged_date||' '||NEW.logged_time)::timestamptz) - rashdrivedate));
                    IF (speedlimitseconds>300 OR rashdriveid IS NULL) THEN
                        FOR rec IN (SELECT user_id FROM tsb_user where (user_role='transport-manager' or  user_role='customer') and user_status='active')
                        LOOP
                            INSERT INTO tsb_push_notification(push_notification_user_id,push_notification_message,push_notification_type, push_notification_date, push_notification_time, push_notification_status,push_notification_url,push_notification_android_link,push_notification_ios_link) VALUES (rec.user_id,notificationtext,'emergency', NEW.logged_date,NEW.logged_time,'pending','customer/report/ranking','track/'||vehicleid,'track/'||vehicleid);
                        END LOOP;
                        INSERT INTO tsb_rash_drive(rash_drive_vehicle_id,rash_drive_driver_id,rash_drive_reason, rash_drive_date) VALUES (vehicleid,driverid,'speed_exceed',(NEW.logged_date||' '||NEW.logged_time)::timestamptz);
                    END IF;
                END IF;
            END IF;
        END IF;
    END IF;
    RETURN NEW;
END;


$_$;


ALTER FUNCTION public.partition_function_location() OWNER TO tsbdbadmin;

--
-- Name: partition_function_mifare_card_trip(); Type: FUNCTION; Schema: public; Owner: tsbdbadmin
--

CREATE FUNCTION public.partition_function_mifare_card_trip() RETURNS trigger
    LANGUAGE plpgsql
    AS $_$


DECLARE

    _new_date text;

    _tablename text;

    _parent_tablename text;

    _schemaname text;

    _primary_column text;

    _check_column text;

    _newcheck_column text;

    new_trip_id INTEGER;

    max_flag INTEGER;

    new_trip_type text;

    trip_vehicle_id INTEGER;

    new_vehicle_id INTEGER;

    trip_route_id INTEGER;

    trip_shift INTEGER;

    trip_driver_id INTEGER;

    trip_helper_id INTEGER;

    new_history_id INTEGER;

    new_trips_history_status text;

    new_time text;

    time_diff INTEGER;

    flag_position INTEGER;

    veh_update INTEGER;

    attendance_inserted INTEGER;

    BEGIN

  --Takes the current inbound 'time' value and determines when midnight is for the given date

        _parent_tablename:='gnx_mifare_card_trip';

        _schemaname:='tp_mifare_card_trip';

        _primary_column:='id';

        _check_column:='logged_date';

        _newcheck_column=NEW.logged_date;

        _new_date := translate(_newcheck_column::text,'-','_');

        _tablename := _parent_tablename||'_'||_new_date;

    -- Check if the partition needed for the current record exists

        PERFORM 1

        FROM   pg_catalog.pg_class c

        JOIN   pg_catalog.pg_namespace n ON n.oid = c.relnamespace

        WHERE  c.relkind = 'r'

        AND    c.relname = _tablename

        AND    n.nspname = _schemaname;

    -- If the partition needed does not yet exist, then we create it:

    -- Note that || is string concatenation (joining two strings to make one)

        IF NOT FOUND THEN

            EXECUTE 'CREATE TABLE '|| _schemaname||'.' ||_tablename || ' (check ('||_check_column||' = ''' ||_newcheck_column || ''')) INHERITS (public.'|| _parent_tablename ||')';

        -- Table permissions are not inherited from the parent.

        -- If permissions change on the master be sure to change them on the child also.

            EXECUTE 'ALTER TABLE '|| _schemaname||'.' || quote_ident(_tablename) || ' OWNER TO tsbdbadmin';

            EXECUTE 'GRANT ALL ON TABLE '|| _schemaname||'.' || quote_ident(_tablename) || ' TO tsbdbadmin';

        -- Indexes are defined per child, so we assign a default index that uses the partition columns

            EXECUTE 'CREATE INDEX ' || quote_ident(_tablename||'_indx1') || ' ON '|| _schemaname||'.' || quote_ident(_tablename) || ' ('|| _primary_column ||')';

            EXECUTE 'ALTER TABLE ONLY '|| _schemaname||'.' || quote_ident(_tablename) || ' ADD CONSTRAINT mifare_card_trip_pkey'||'_'||_new_date ||' PRIMARY KEY (id)';

        END IF;

        EXECUTE 'SELECT id FROM ' || _schemaname ||'.' || quote_ident(_tablename) || ' WHERE logged_date = $1 AND logged_time = $2 AND mifare_card_id = $3 '

        INTO attendance_inserted

        USING NEW.logged_date, NEW.logged_time, NEW.mifare_card_id;

        IF (attendance_inserted IS NOT NULL) THEN

            RETURN NULL;

        END IF;

    -- Insert the current record into the correct partition, which we are sure will now exist.

        EXECUTE 'SELECT max(attendance_flag_position) FROM ' || _schemaname ||'.' || quote_ident(_tablename) || ' WHERE logged_date = $1 AND mifare_card_id = $2 '

        INTO max_flag

        USING NEW.logged_date,  NEW.mifare_card_id;

        IF (max_flag IS NOT NULL) THEN

            EXECUTE 'SELECT COALESCE((EXTRACT(EPOCH FROM $1 - logged_time ))::Integer,200) FROM ' || _schemaname ||'.' || quote_ident(_tablename) || ' WHERE logged_date = $2 AND mifare_card_id = $3 AND attendance_flag_position = $4 group by logged_time,attendance_flag_position order by attendance_flag_position DESC limit 1'

            INTO time_diff

            USING  NEW.logged_time, NEW.logged_date,  NEW.mifare_card_id, max_flag;

        ELSE 

            time_diff = 200;

        END IF;

        SELECT INTO new_trip_id,new_trip_type,trip_vehicle_id,trip_route_id,trip_shift ,trip_driver_id,trip_helper_id tsb_trip.trip_id,tsb_trip.trip_type,tsb_trip.trip_vehicle_id,tsb_trip.trip_route_id,tsb_trip.trip_shift ,tsb_trip.trip_driver_id,tsb_trip.trip_helper_id  FROM tsb_trip WHERE tsb_trip.trip_card_id = NEW.mifare_card_id and trip_status = 'active' limit 1;

        SELECT INTO new_vehicle_id vehicle_id FROM tsb_vehicle WHERE vehicle_imei = NEW.imei and vehicle_status = 'active';

        IF(new_vehicle_id = trip_vehicle_id) THEN

            IF(max_flag = 1) THEN

                IF(time_diff > 900) THEN

                    flag_position = 2;

                ELSE 

                    flag_position = NULL;

                END IF;

            ELSEIF (max_flag = 2) THEN

                flag_position = NULL;

            ELSE

                flag_position = 1;

            END IF;

        ELSEIF (max_flag = 1) THEN

            flag_position = 1;

            veh_update = 1;

        ELSEIF (max_flag = 2) THEN

            veh_update = 0;

            flag_position = NULL;

        ELSE

            veh_update = 1;

            flag_position = 1;

        END IF;

        EXECUTE format('INSERT INTO '|| _schemaname|| '.' || quote_ident(_tablename) || ' (imei,cur_time,cur_date,logged_time,logged_date, gps_data_valid, latitude, latitude_direction, longitude, longitude_direction, mifare_card_id, valid_invalid_vehicle_id, packet_length, bloack1_information1, bloack1_information2, packet_history, mifare_card_manual_attendance,attendance_flag_position)

                        VALUES ($1,'||'$2'||',$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18)') USING new.imei,new.cur_time,new.cur_date,new.logged_time,new.logged_date,new.gps_data_valid, new.latitude, new.latitude_direction, new.longitude, new.longitude_direction, new.mifare_card_id, new.valid_invalid_vehicle_id, new.packet_length, new.bloack1_information1, new.bloack1_information2, new.packet_history, new.mifare_card_manual_attendance,flag_position;

    -- Insert the current record into the correct partition, which we are sure will now exist.

        IF (TG_OP = 'INSERT' and new.attendance_flag_position IS NOT NULL) THEN

            IF (new_trip_id IS NOT NULL) THEN

                SELECT INTO new_history_id,new_trips_history_status tsb_trips_history.trips_history_id,tsb_trips_history.trips_history_status  FROM tsb_trips_history WHERE tsb_trips_history.trips_history_trip_id = new_trip_id and tsb_trips_history.trips_history_start_date = NEW.logged_date;

                IF (new_history_id IS NOT NULL and flag_position = 2) THEN

                    IF (new_trips_history_status = 'started'::text) THEN

                        UPDATE tsb_trips_history SET trips_history_status = 'completed',trips_history_end_date =NEW.logged_date ,trips_history_end_time =NEW.logged_time  WHERE  tsb_trips_history.trips_history_id = new_history_id ;

                    END IF;

                ELSE

                    IF (veh_update = 1) THEN

                        UPDATE tsb_trip SET trip_vehicle_id = new_vehicle_id WHERE tsb_trip.trip_id = new_trip_id ;

                        IF (new_trips_history_status = 'started'::text) THEN

                            UPDATE tsb_trips_history SET trips_history_vehicle_id = new_vehicle_id WHERE tsb_trips_history.trips_history_id = new_history_id ;

                        ELSE

                            INSERT INTO tsb_trips_history(trips_history_trip_id, trip_history_type, trips_history_driver_id, trips_history_start_date,trips_history_start_time,trips_history_end_date,trips_history_end_time,trips_history_km,trips_history_status,trips_history_vehicle_id,trips_history_route_id,trips_history_helper_id,trips_history_trip_type,trips_history_shift_id) VALUES (new_trip_id, 'scheduled', trip_driver_id, NEW.logged_date, NEW.logged_time, null, null,5,'started',new_vehicle_id,trip_route_id,trip_helper_id,new_trip_type,trip_shift);

                        END IF;

                    ELSEIF (flag_position = 1) THEN

                        INSERT INTO tsb_trips_history(trips_history_trip_id, trip_history_type, trips_history_driver_id, trips_history_start_date,trips_history_start_time,trips_history_end_date,trips_history_end_time,trips_history_km,trips_history_status,trips_history_vehicle_id,trips_history_route_id,trips_history_helper_id,trips_history_trip_type,trips_history_shift_id) VALUES (new_trip_id, 'scheduled', trip_driver_id, NEW.logged_date, NEW.logged_time, null, null,5,'started',new_vehicle_id,trip_route_id,trip_helper_id,new_trip_type,trip_shift);

                    END IF;

                END IF;

            END IF;

        END IF;

    RETURN NULL;

END;


$_$;


ALTER FUNCTION public.partition_function_mifare_card_trip() OWNER TO tsbdbadmin;

--
-- Name: partition_function_mifare_card_user(); Type: FUNCTION; Schema: public; Owner: tsbdbadmin
--

CREATE FUNCTION public.partition_function_mifare_card_user() RETURNS trigger
    LANGUAGE plpgsql
    AS $_$


DECLARE

    _new_date text;

    _tablename text;

    _parent_tablename text;

    _schemaname text;

    _primary_column text;

    _check_column text;

    _newcheck_column text;

    new_user_role text;

    settings_id INTEGER;

    addon_id INTEGER;

    new_user_id INTEGER;

    attendance_vehicleid INTEGER;

    attendance_count INTEGER;

    latitude numeric;

    attendance_flag_count INTEGER;

    longitude numeric;

    time_diff INTEGER;

    trip_history INTEGER;

    countstudent INTEGER;

    last_swipe time;

    shift_endtime time;

    trips_history_start time;

    droponly_flag INTEGER;

    last_attendance_time INTEGER;

    already_inserted INTEGER;

    attendance_inserted INTEGER;

    BEGIN

    SELECT INTO new_user_id tsb_user_card.card_user_id FROM tsb_user_card WHERE tsb_user_card.card_user_mifarecard_id = NEW.mifare_card_id;

        _parent_tablename:='tsb_attendance_user';

        _schemaname:='tp_attendance_user';

        _primary_column:='attendance_id';

        _check_column:='attendance_date';

        _newcheck_column=NEW.logged_date;

        _new_date := translate(_newcheck_column::text,'-','_');

        _tablename := _parent_tablename||'_'||_new_date;

    -- Check if the partition needed for the current record exists

        PERFORM 1

        FROM   pg_catalog.pg_class c

        JOIN   pg_catalog.pg_namespace n ON n.oid = c.relnamespace

        WHERE  c.relkind = 'r'

        AND    c.relname = _tablename

        AND    n.nspname = _schemaname;

    -- If the partition needed does not yet exist, then we create it:

    -- Note that || is string concatenation (joining two strings to make one)

        IF NOT FOUND THEN

            EXECUTE 'CREATE TABLE '|| _schemaname||'.' ||_tablename || ' (check ('||_check_column||' = ''' ||_newcheck_column || ''')) INHERITS (public.'|| _parent_tablename ||')';

        -- Table permissions are not inherited from the parent.

        -- If permissions change on the master be sure to change them on the child also.

            EXECUTE 'ALTER TABLE '|| _schemaname||'.' || quote_ident(_tablename) || ' OWNER TO tsbdbadmin';

            EXECUTE 'GRANT ALL ON TABLE '|| _schemaname||'.' || quote_ident(_tablename) || ' TO tsbdbadmin';

        -- Indexes are defined per child, so we assign a default index that uses the partition columns

            EXECUTE 'CREATE INDEX ' || quote_ident(_tablename||'_indx1') || ' ON '|| _schemaname||'.'|| quote_ident(_tablename) || ' ('|| _primary_column ||')';

            EXECUTE 'ALTER TABLE ONLY '|| _schemaname||'.' || quote_ident(_tablename) || ' ADD CONSTRAINT tsb_attendance_user_pkey'||'_'||_new_date ||' PRIMARY KEY (attendance_id)';

        END IF;

        -- SELECT INTO attendance_inserted attendance_id from tsb_attendance_user where attendance_date=NEW.logged_date and attendance_check_in_out=NEW.logged_time and attendance_user_id=new_user_id;

        EXECUTE 'SELECT attendance_id FROM ' || _schemaname ||'.' || quote_ident(_tablename) || ' WHERE attendance_date = $1 AND attendance_check_in_out = $2 AND attendance_user_id = $3 '

        INTO attendance_inserted

        USING NEW.logged_date, NEW.logged_time, new_user_id;

        IF (attendance_inserted > 0) THEN

            RETURN NULL;

        END IF;

    --Takes the current inbound 'time' value and determines when midnight is for the given date

        _parent_tablename:='gnx_mifare_card_user';

        _schemaname:='tp_mifare_card_user';

        _primary_column:='id';

        _check_column:='logged_date';

        _newcheck_column=NEW.logged_date;

        _new_date := translate(_newcheck_column::text,'-','_');

        _tablename := _parent_tablename||'_'||_new_date;

    -- Check if the partition needed for the current record exists

        PERFORM 1

        FROM   pg_catalog.pg_class c

        JOIN   pg_catalog.pg_namespace n ON n.oid = c.relnamespace

        WHERE  c.relkind = 'r'

        AND    c.relname = _tablename

        AND    n.nspname = _schemaname;

    -- If the partition needed does not yet exist, then we create it:

    -- Note that || is string concatenation (joining two strings to make one)

        IF NOT FOUND THEN

            EXECUTE 'CREATE TABLE '|| _schemaname||'.' ||_tablename || ' (check ('||_check_column||' = ''' ||_newcheck_column || ''')) INHERITS (public.'|| _parent_tablename ||')';

        -- Table permissions are not inherited from the parent.

        -- If permissions change on the master be sure to change them on the child also.

            EXECUTE 'ALTER TABLE '|| _schemaname||'.' || quote_ident(_tablename) || ' OWNER TO tsbdbadmin';

            EXECUTE 'GRANT ALL ON TABLE '|| _schemaname||'.' || quote_ident(_tablename) || ' TO tsbdbadmin';

        -- Indexes are defined per child, so we assign a default index that uses the partition columns

            EXECUTE 'CREATE INDEX ' || quote_ident(_tablename||'_indx1') || ' ON '|| _schemaname||'.' || quote_ident(_tablename) || ' ('|| _primary_column ||')';

            EXECUTE 'ALTER TABLE ONLY '|| _schemaname||'.' || quote_ident(_tablename) || ' ADD CONSTRAINT mifare_card_user_pkey'||'_'||_new_date ||' PRIMARY KEY (id)';

        END IF;

    -- Insert the current record into the correct partition, which we are sure will now exist.

        EXECUTE 'INSERT INTO '|| _schemaname||'.' || quote_ident(_tablename) || ' VALUES ($1.*)' USING NEW;

        _parent_tablename:='tsb_attendance_user';

        _schemaname:='tp_attendance_user';

        _primary_column:='attendance_id';

        _check_column:='attendance_date';

        _newcheck_column=NEW.logged_date;

        _new_date := translate(_newcheck_column::text,'-','_');

        _tablename := _parent_tablename||'_'||_new_date;

    -- Check if the partition needed for the current record exists

        PERFORM 1

        FROM   pg_catalog.pg_class c

        JOIN   pg_catalog.pg_namespace n ON n.oid = c.relnamespace

        WHERE  c.relkind = 'r'

        AND    c.relname = _tablename

        AND    n.nspname = _schemaname;

    -- If the partition needed does not yet exist, then we create it:

    -- Note that || is string concatenation (joining two strings to make one)

        IF NOT FOUND THEN

            EXECUTE 'CREATE TABLE '|| _schemaname||'.' ||_tablename || ' (check ('||_check_column||' = ''' ||_newcheck_column || ''')) INHERITS (public.'|| _parent_tablename ||')';

        -- Table permissions are not inherited from the parent.

        -- If permissions change on the master be sure to change them on the child also.

            EXECUTE 'ALTER TABLE '|| _schemaname||'.' || quote_ident(_tablename) || ' OWNER TO tsbdbadmin';

            EXECUTE 'GRANT ALL ON TABLE '|| _schemaname||'.' || quote_ident(_tablename) || ' TO tsbdbadmin';

        -- Indexes are defined per child, so we assign a default index that uses the partition columns

            EXECUTE 'CREATE INDEX ' || quote_ident(_tablename||'_indx1') || ' ON '|| _schemaname||'.'|| quote_ident(_tablename) || ' ('|| _primary_column ||')';

            EXECUTE 'ALTER TABLE ONLY '|| _schemaname||'.' || quote_ident(_tablename) || ' ADD CONSTRAINT tsb_attendance_user_pkey'||'_'||_new_date ||' PRIMARY KEY (attendance_id)';

        END IF;

    -- Insert the current record into the correct partition, which we are sure will now exist.

        IF (TG_OP = 'INSERT') THEN

            droponly_flag = 0;

            already_inserted = 0;

            -- SELECT INTO new_user_id tsb_user_card.card_user_id FROM tsb_user_card WHERE tsb_user_card.card_user_mifarecard_id = NEW.mifare_card_id;

            IF (new_user_id IS NOT NULL) THEN

                select INTO attendance_vehicleid vehicle_id from tsb_vehicle where vehicle_imei=NEW.imei limit 1;

                EXECUTE 'SELECT COALESCE((EXTRACT(EPOCH FROM $1 - attendance_check_in_out ))::Integer,0) FROM ' || _schemaname ||'.' || quote_ident(_tablename) || ' WHERE attendance_date = $2 AND attendance_user_id = $3 AND attendance_vehicle_id = $4 group by attendance_check_in_out,attendance_check_in_out order by attendance_check_in_out DESC limit 1'

                INTO last_attendance_time

                USING  NEW.logged_time, NEW.logged_date, new_user_id, attendance_vehicleid;

                -- SELECT INTO last_attendance_time COALESCE((EXTRACT(EPOCH FROM NEW.logged_time - attendance_check_in_out))::Integer,0) FROM tsb_attendance_user WHERE attendance_user_id = new_user_id and attendance_date = NEW.logged_date  and attendance_vehicle_id=attendance_vehicleid order by attendance_check_in_out desc limit 1;

                IF(NEW.mifare_card_manual_attendance = 1 AND NEW.attendance_flag_position <> 0) THEN

                    attendance_count = NEW.attendance_flag_position;

                    EXECUTE 'SELECT count(attendance_id)::Integer FROM ' || _schemaname ||'.' || quote_ident(_tablename) || ' WHERE attendance_date = $1 AND attendance_user_id = $2 AND attendance_flag_position = $3 '

                    INTO already_inserted

                    USING NEW.logged_date, new_user_id, NEW.attendance_flag_position;

                    -- SELECT INTO already_inserted count(tsb_attendance_user.attendance_id)::Integer FROM tsb_attendance_user WHERE tsb_attendance_user.attendance_user_id=new_user_id and tsb_attendance_user.attendance_flag_position=NEW.attendance_flag_position and tsb_attendance_user.attendance_date=NEW.logged_date;

                    IF (already_inserted = 0) THEN

                        droponly_flag = 1;

                    ELSE

                        droponly_flag = 0;

                    END IF;

                ELSE

                    -- SELECT INTO attendance_count COALESCE(max(attendance_flag_position),0) FROM tsb_attendance_user WHERE attendance_user_id = new_user_id and attendance_date = NEW.logged_date and attendance_vehicle_id=attendance_vehicleid; 

                    EXECUTE 'SELECT COALESCE(max(attendance_flag_position),0) FROM ' || _schemaname ||'.' || quote_ident(_tablename) || ' WHERE attendance_date = $1 AND attendance_user_id = $2 AND attendance_vehicle_id = $3 '

                    INTO attendance_count

                    USING NEW.logged_date, new_user_id, attendance_vehicleid;

                    IF ((attendance_count>0) AND (attendance_count%2!=0)) THEN

                        IF(last_attendance_time>(90*60))THEN

                            attendance_count=attendance_count+2;

                        ELSE

                            attendance_count = attendance_count+1;

                        END IF;

                    ELSE

                        attendance_count = attendance_count+1;

                    END IF;

                END IF;

                longitude=NEW.longitude;

                latitude=NEW.latitude;

                IF (NEW.longitude_direction = 'W') THEN

                    longitude=NEW.longitude*-1;

                END IF;

                IF (NEW.latitude_direction = 'S') THEN

                    latitude=NEW.latitude*-1;

                END IF;

                SELECT INTO attendance_vehicleid vehicle_id FROM tsb_vehicle WHERE vehicle_imei=NEW.imei and vehicle_status = 'active' limit 1;

                IF(last_attendance_time>(15*60) OR (attendance_count%2!=0 AND last_attendance_time>(3*60)) OR last_attendance_time=0 OR last_attendance_time is null)THEN

                    INSERT INTO tsb_attendance_user(attendance_user_id, attendance_date, attendance_check_in_out, attendance_flag_position,attendance_latitude,attendance_longitude,attendance_manual_attendance,attendance_vehicle_id,attendance_app_type) VALUES (new_user_id, NEW.logged_date, NEW.logged_time, attendance_count, latitude, longitude, NEW.mifare_card_manual_attendance,attendance_vehicleid,NEW.mifare_card_app_type);

                    EXECUTE 'SELECT COALESCE(max(attendance_flag_position),0) FROM ' || _schemaname ||'.' || quote_ident(_tablename) || ' WHERE attendance_date = $1 AND attendance_user_id = $2'

                    INTO attendance_flag_count

                    USING NEW.logged_date, new_user_id;

                    -- SELECT INTO attendance_flag_count COALESCE(max(attendance_flag_position),0) FROM tsb_attendance_user WHERE attendance_user_id = new_user_id and attendance_date = NEW.logged_date;

                    IF (attendance_flag_count = 1 OR attendance_flag_count = 3) THEN

                        SELECT INTO settings_id settings_trip_card FROM tsb_settings;

                        SELECT INTO addon_id addon_trip_card FROM tsb_addon;

                        IF (settings_id = 1 and addon_id =1) THEN

                            SELECT INTO trip_history,trips_history_start trips_history_trip_id,trips_history_start_time FROM tsb_trips_history WHERE trips_history_status = 'started' and trips_history_start_date = NEW.logged_date and trips_history_vehicle_id = attendance_vehicleid ORDER BY trips_history_start_time desc limit 1;

                            IF (trip_history IS NOT NULL) THEN

                                SELECT INTO new_user_role user_role FROM tsb_user WHERE user_id = new_user_id;

                                IF (new_user_role = 'driver') THEN

                                    UPDATE tsb_trips_history SET trips_history_driver_id = new_user_id WHERE tsb_trips_history.trips_history_trip_id = trip_history ;

                                    UPDATE tsb_trip SET trip_driver_id = new_user_id WHERE tsb_trip.trip_id = trip_history ;

                                ELSEIF (new_user_role = 'helper') THEN

                                    UPDATE tsb_trips_history SET trips_history_helper_id = new_user_id WHERE tsb_trips_history.trips_history_trip_id = trip_history ;

                                    UPDATE tsb_trip SET trip_helper_id = new_user_id WHERE tsb_trip.trip_id = trip_history ;

                                END IF;

                            END IF;

                        END IF;

                    END IF;

                END IF;

            END IF;

        END IF;

    RETURN NULL;

END;



$_$;


ALTER FUNCTION public.partition_function_mifare_card_user() OWNER TO tsbdbadmin;

--
-- Name: partition_function_notification(); Type: FUNCTION; Schema: public; Owner: tsbdbadmin
--

CREATE FUNCTION public.partition_function_notification() RETURNS trigger
    LANGUAGE plpgsql
    AS $_$

DECLARE

_tablename text;

_parent_tablename text;

_schemaname text;

_primary_column text;

_check_column text;

_newcheck_column text;

BEGIN

--Takes the current user id value and determines  table is already ixist or not

_parent_tablename:='tsb_notification';

_schemaname:='tp_notification';

_primary_column:='notification_id';

_check_column:='notification_user_id';

_newcheck_column=NEW.notification_user_id;

_tablename := _parent_tablename||'_'||_newcheck_column;

-- Check if the partition needed for the current record exists

PERFORM 1

FROM   pg_catalog.pg_class c

JOIN   pg_catalog.pg_namespace n ON n.oid = c.relnamespace

WHERE  c.relkind = 'r'

AND    c.relname = _tablename

AND    n.nspname = _schemaname;

-- If the partition needed does not yet exist, then we create it:

-- Note that || is string concatenation (joining two strings to make one)

IF NOT FOUND THEN

EXECUTE 'CREATE TABLE '|| _schemaname||'.' ||_tablename || ' (check ('||_check_column||' = ''' ||_newcheck_column || ''')) INHERITS (public.'|| _parent_tablename ||')';

-- Table permissions are not inherited from the parent.

-- If permissions change on the master be sure to change them on the child also.

EXECUTE 'ALTER TABLE '|| _schemaname||'.' || quote_ident(_tablename) || ' OWNER TO tsbdbadmin';

EXECUTE 'GRANT ALL ON TABLE '|| _schemaname||'.' || quote_ident(_tablename) || ' TO tsbdbadmin';

-- Indexes are defined per child, so we assign a default index that uses the partition columns

EXECUTE 'CREATE INDEX ' || quote_ident(_tablename||'_indx1') || ' ON '|| _schemaname||'.'  || quote_ident(_tablename) || ' ('|| _primary_column ||')';

END IF;

-- Insert the current record into the correct partition, which we are sure will now exist.

EXECUTE 'INSERT INTO '|| _schemaname||'.' || quote_ident(_tablename) || ' VALUES ($1.*)' USING NEW;

RETURN NULL;

END;

$_$;


ALTER FUNCTION public.partition_function_notification() OWNER TO tsbdbadmin;

--
-- Name: partition_function_notification_log(); Type: FUNCTION; Schema: public; Owner: tsbdbadmin
--

CREATE FUNCTION public.partition_function_notification_log() RETURNS trigger
    LANGUAGE plpgsql
    AS $_$


DECLARE

_new_date text;
_tablename text;
_parent_tablename text;
_schemaname text;
_primary_column text;
_check_column text;
_newcheck_column text;
BEGIN

--Takes the current inbound 'time' value and determines when midnight is for the given date


_parent_tablename:='tsb_notification_log';
_schemaname:='tp_notification_log';
_primary_column:='notification_log_id';
_check_column:='notification_log_date';
_newcheck_column=NEW.notification_log_date;

_new_date := translate(_newcheck_column::text,'-','_');
_tablename := _parent_tablename||'_'||_new_date;

-- Check if the partition needed for the current record exists

PERFORM 1

FROM   pg_catalog.pg_class c

JOIN   pg_catalog.pg_namespace n ON n.oid = c.relnamespace

WHERE  c.relkind = 'r'

AND    c.relname = _tablename

AND    n.nspname = _schemaname;

-- If the partition needed does not yet exist, then we create it:

-- Note that || is string concatenation (joining two strings to make one)

IF NOT FOUND THEN

EXECUTE 'CREATE TABLE '|| _schemaname||'.' ||_tablename || ' (check ('||_check_column||' = ''' ||_newcheck_column || ''')) INHERITS (public.'|| _parent_tablename ||')';

-- Table permissions are not inherited from the parent.

-- If permissions change on the master be sure to change them on the child also.

EXECUTE 'ALTER TABLE '|| _schemaname||'.' || quote_ident(_tablename) || ' OWNER TO tsbdbadmin';

EXECUTE 'GRANT ALL ON TABLE '|| _schemaname||'.' || quote_ident(_tablename) || ' TO tsbdbadmin';

-- Indexes are defined per child, so we assign a default index that uses the partition columns

EXECUTE 'CREATE INDEX ' || quote_ident(_tablename||'_indx1') || ' ON ' || _schemaname || ' . ' || quote_ident(_tablename) || ' ('|| _primary_column ||')';

EXECUTE 'ALTER TABLE ONLY '|| _schemaname||'.' || quote_ident(_tablename) || ' ADD CONSTRAINT tsb_notification_log_pkey'||'_'||_new_date ||' PRIMARY KEY (notification_log_id)';
END IF;

-- Insert the current record into the correct partition, which we are sure will now exist.

EXECUTE 'INSERT INTO '|| _schemaname||'.' || quote_ident(_tablename) || ' VALUES ($1.*)' USING NEW;

PERFORM pg_notify('nodejs_notification_statistics', TG_TABLE_NAME || ',' ||  NEW.notification_log_id || ',' || NEW.notification_log_priority);

RETURN NULL;


END;


$_$;


ALTER FUNCTION public.partition_function_notification_log() OWNER TO tsbdbadmin;

--
-- Name: partition_function_notification_settings_user(); Type: FUNCTION; Schema: public; Owner: tsbdbadmin
--

CREATE FUNCTION public.partition_function_notification_settings_user() RETURNS trigger
    LANGUAGE plpgsql
    AS $$

 
BEGIN

IF(NEW.user_role = 'fleet-manager' OR NEW.user_role = 'customer' OR NEW.user_role = 'transport-manager') THEN

INSERT INTO tsb_notification_settings(notification_settings_language,notification_settings_user_id) VALUES('en',NEW.user_id);
INSERT INTO tsb_notification_settings_email(notification_settings_language,notification_settings_user_id) VALUES('en',NEW.user_id);
INSERT INTO tsb_notification_settings_sms(notification_settings_language,notification_settings_user_id) VALUES('en',NEW.user_id);
INSERT INTO tsb_notification_settings_whatsapp(notification_settings_language,notification_settings_user_id) VALUES('en',NEW.user_id);

END IF;
RETURN NULL;
END;


$$;


ALTER FUNCTION public.partition_function_notification_settings_user() OWNER TO tsbdbadmin;

--
-- Name: partition_function_speed_limit(); Type: FUNCTION; Schema: public; Owner: tsbdbadmin
--

CREATE FUNCTION public.partition_function_speed_limit() RETURNS trigger
    LANGUAGE plpgsql
    AS $_$



DECLARE

    _driver_tablename text;
    _driver_parent_tablename text;
    _driver_schemaname text;
    _driver_primary_column text;
    _driver_newcheck_column text;
    _driver_check_column text;
    _rashdrive_date_time  timestamp;  

    BEGIN
    _driver_parent_tablename:='tsb_rash_drive_speed_limit';

    _driver_schemaname:='tp_speed_limit';
    _driver_primary_column:='speed_limit_id';
    _driver_check_column:= 'speed_limit_vehicle_id';
    _driver_newcheck_column :=NEW.speed_limit_vehicle_id;
    _driver_tablename := _driver_parent_tablename ||'_'||NEW.speed_limit_vehicle_id;
    _rashdrive_date_time := NEW.speed_limit_date;

    PERFORM 1
        FROM   pg_catalog.pg_class c
        JOIN   pg_catalog.pg_namespace n ON n.oid = c.relnamespace
        WHERE  c.relkind = 'r'
        AND    c.relname = _driver_tablename
        AND    n.nspname = _driver_schemaname;
        
        -- If the partition needed does not yet exist, then we create it:
        -- Note that || is string concatenation (joining two strings to make one)
        IF NOT FOUND THEN
            EXECUTE 'CREATE TABLE '|| _driver_schemaname || '.' || _driver_tablename ||
             ' (check ('||_driver_check_column||' = ''' ||_driver_newcheck_column || ''')) INHERITS
              ('|| _driver_parent_tablename ||')';
            
            -- Table permissions are not inherited from the parent.
            -- If permissions change on the master be sure to change them on the child also.
            EXECUTE 'ALTER TABLE '|| _driver_schemaname || '.' || quote_ident(_driver_tablename) || ' OWNER TO tsbdbadmin';
            EXECUTE 'GRANT ALL ON '|| _driver_schemaname||'.' || quote_ident(_driver_tablename) || ' TO tsbdbadmin';
            
            -- Indexes are defined per child, so we assign a default index that uses the partition columns
            EXECUTE 'CREATE INDEX ' || quote_ident(_driver_tablename||'_indx1') || ' ON '|| _driver_schemaname||'.' || quote_ident(_driver_tablename) || ' ('|| _driver_primary_column ||')';
            EXECUTE 'ALTER TABLE ONLY '|| _driver_schemaname||'.' || quote_ident(_driver_tablename) || ' ADD CONSTRAINT '|| _driver_primary_column||'_'||NEW.speed_limit_vehicle_id ||' PRIMARY KEY (speed_limit_id)';
        END IF;
        EXECUTE 'INSERT INTO '|| _driver_schemaname||'.' || quote_ident(_driver_tablename) || ' VALUES ($1.*)' USING NEW;
           RETURN NULL;
    END                


$_$;


ALTER FUNCTION public.partition_function_speed_limit() OWNER TO tsbdbadmin;

--
-- Name: partition_function_vehicle_activity(); Type: FUNCTION; Schema: public; Owner: tsbdbadmin
--

CREATE FUNCTION public.partition_function_vehicle_activity() RETURNS trigger
    LANGUAGE plpgsql
    AS $_$


DECLARE

_new_time text;

_schemaname text;

_tablename text;

_startdate text;

_enddate text;

_result record;

vehicleid INTEGER;

vehicle_activity_id INTEGER;

tablefullname text; 



BEGIN

--Takes the current inbound 'time' value and determines when midnight is for the given date

    _new_time := translate(NEW.vehicle_activity_date::text,'-','_');

    _startdate := NEW.vehicle_activity_date;

    _tablename := 'tsb_vehicle_activity_'||_new_time;

    _schemaname := 'tp_vehicle_activity';

    -- Check if the partition needed for the current record exists

    PERFORM 1

        FROM pg_catalog.pg_class c

        JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace

        WHERE c.relkind = 'r'

        AND c.relname = _tablename

        AND n.nspname = _schemaname;

    -- If the partition needed does not yet exist, then we create it:

    -- Note that || is string concatenation (joining two strings to make one)

    IF NOT FOUND THEN

        _enddate:=_startdate::timestamp + INTERVAL '1 day';

        EXECUTE 'CREATE TABLE ' || _schemaname || '.' ||_tablename || ' (check (vehicle_activity_date = ''' || NEW.vehicle_activity_date || ''')) INHERITS (public.tsb_vehicle_activity)';

        -- Table permissions are not inherited from the parent.

        -- If permissions change on the master be sure to change them on the child also.

        EXECUTE 'ALTER TABLE ' || _schemaname || '.' || quote_ident(_tablename) || ' OWNER TO tsbdbadmin';

        EXECUTE 'GRANT ALL ON TABLE ' || _schemaname || '.' || quote_ident(_tablename) || ' TO tsbdbadmin';

        -- Indexes are defined per child, so we assign a default index that uses the partition columns

        EXECUTE 'CREATE INDEX ' || quote_ident(_tablename||'_indx1') || ' ON ' || _schemaname || '.' || quote_ident(_tablename) || ' (vehicle_activity_id)';

    END IF;

    -- check same data exist for avoid repeat entries

    tablefullname := _schemaname||'.'||quote_ident(_tablename);

    EXECUTE 'SELECT  vehicle_activity_id FROM '|| _schemaname||'.' || quote_ident(_tablename) || ' where vehicle_activity_start_time= $2 and vehicle_activity_date= $1 and vehicle_activity_vehicle_id= $3 and vehicle_activity_status= $4' INTO vehicle_activity_id

    USING NEW.vehicle_activity_date, NEW.vehicle_activity_start_time, NEW.vehicle_activity_vehicle_id,NEW.vehicle_activity_status;

    IF(vehicle_activity_id > 0) THEN

        RETURN NULL;

    END IF;

    -- Insert the current record into the correct partition, which we are sure will now exist.

    EXECUTE 'INSERT INTO ' || _schemaname || '.'  || quote_ident(_tablename) || ' VALUES ($1.*)' USING NEW;

RETURN NULL;

END;


$_$;


ALTER FUNCTION public.partition_function_vehicle_activity() OWNER TO tsbdbadmin;

--
-- Name: send_notification_alert(); Type: FUNCTION; Schema: public; Owner: tsbdbadmin
--

CREATE FUNCTION public.send_notification_alert() RETURNS trigger
    LANGUAGE plpgsql
    AS $$

  DECLARE           

      vehiclenumber VARCHAR;

vehicleregno VARCHAR; 

notificationtype VARCHAR;

notificationtext VARCHAR;

 rec record;

    BEGIN	

IF (TG_OP = 'INSERT') THEN 

notificationtype='alert';

 IF (NEW.gps_data_valid=1) THEN

SELECT INTO vehiclenumber,vehicleregno  vehicle_number,vehicle_reg_no   FROM tsb_vehicle where vehicle_imei=NEW.imei;

IF (NEW.alert_type = '1') THEN 

notificationtext='Panic Alert received from one vehicle, details are vehicle number - '||vehiclenumber||', vehicle register number - '|| vehicleregno;

notificationtype='danger';

END IF;

IF (NEW.alert_type = '2') THEN 

notificationtext='Power ON alert received from one vehicle, details are vehicle number - '||vehiclenumber||', vehicle register number - '|| vehicleregno;

notificationtype='alert';

END IF;

IF (NEW.alert_type = '3') THEN 

notificationtext='Power OFF (Internal Battery ON) signal received from one vehicle, details are vehicle number - '||vehiclenumber||', vehicle register number - '|| vehicleregno;

notificationtype='alert';

END IF;

IF (NEW.alert_type = '4') THEN 

notificationtext=' Internal Battery Low signal received from one vehicle, details are vehicle number - '||vehiclenumber||', vehicle register number - '|| vehicleregno;

notificationtype='emergency';

END IF;

IF (NEW.alert_type = '5') THEN 

notificationtext='SIM Tray Open signal received from one vehicle, details are vehicle number - '||vehiclenumber||', vehicle register number - '|| vehicleregno;

notificationtype='emergency';

END IF;

IF (NEW.alert_type = 'V') THEN 

notificationtext=' Box Cover Open signal received from one vehicle, details are vehicle number - '||vehiclenumber||', vehicle register number - '|| vehicleregno;

notificationtype='alert';

END IF;

IF (NEW.alert_type = 'W') THEN 

notificationtext='Box Cover Close signal received from one vehicle, details are vehicle number - '||vehiclenumber||', vehicle register number - '|| vehicleregno;

notificationtype='alert';

END IF;

IF (NEW.alert_type = 'G') THEN 

notificationtext='Internal Battery Removed signal received from one vehicle, details are vehicle number - '||vehiclenumber||', vehicle register number - '|| vehicleregno;

notificationtype='emergency';

END IF;

IF (NEW.alert_type = 'T') THEN 

notificationtext='Seat belt alert ON signal received from one vehicle, details are vehicle number - '||vehiclenumber||', vehicle register number - '|| vehicleregno;

notificationtype='alert';

END IF;

IF (NEW.alert_type = 'a') THEN 

notificationtext='Harsh Acceleration signal received from one vehicle, details are vehicle number - '||vehiclenumber||', vehicle register number - '|| vehicleregno;

notificationtype='danger';

END IF;

IF (NEW.alert_type = 'b') THEN 

notificationtext='Harsh Bracking signal received from one vehicle, details are vehicle number - '||vehiclenumber||', vehicle register number - '|| vehicleregno;

notificationtype='danger';

END IF;

IF (notificationtext IS NOT NULL) THEN 

 FOR rec IN (SELECT * FROM tsb_user where user_role='transport-manager' or  user_role='customer')

 LOOP 

    INSERT INTO tsb_push_notification(push_notification_user_id,push_notification_message,push_notification_type, push_notification_date, push_notification_time, push_notification_status) VALUES (rec.user_id,notificationtext,notificationtype, now()::date, now()::timestamp(0),'pending' );

  END LOOP;

  END IF;

   END IF;

   END IF;

RETURN NULL;

END; 

$$;


ALTER FUNCTION public.send_notification_alert() OWNER TO tsbdbadmin;

--
-- Name: send_notification_exceed_speed(); Type: FUNCTION; Schema: public; Owner: tsbdbadmin
--

CREATE FUNCTION public.send_notification_exceed_speed() RETURNS trigger
    LANGUAGE plpgsql
    AS $$



    DECLARE 

       speedval INTEGER; 

       cnt INTEGER; 

       polySides INTEGER; 

       vehicleid INTEGER;

       rashdriveid INTEGER;

       driverid INTEGER;

      locatioliveid INTEGER;

       vehiclenumber VARCHAR; 

       notificationtext VARCHAR;   

        rec record;

 rashdrivedate timestamp;

       speedlimitseconds INTEGER;

    BEGIN	

IF (TG_OP = 'INSERT') THEN

PERFORM pg_notify('nodejs_watchers', TG_TABLE_NAME || ',id,' || NEW.id );

SELECT INTO speedval customer_speed_limit FROM tsb_customer;

SELECT INTO vehiclenumber,vehicleid  vehicle_number,vehicle_id   FROM tsb_vehicle where vehicle_imei=NEW.imei;

SELECT INTO locatioliveid id FROM gnx_live_location where imei=NEW.imei;

IF(locatioliveid>0) THEN

UPDATE gnx_live_location set imei=NEW.imei,cur_time=NEW.cur_time,cur_date=NEW.cur_date,logged_time=NEW.logged_time,logged_date=NEW.logged_date,gps_data_valid=NEW.gps_data_valid,latitude=NEW.latitude,latitude_direction=NEW.latitude_direction,longitude=NEW.longitude,longitude_direction=NEW.longitude_direction,speed=NEW.speed,heading_angle=NEW.heading_angle,metering_status=NEW.metering_status,gsm_signal_strength=NEW.gsm_signal_strength,panic_status=NEW.panic_status,total_satellites=NEW.total_satellites,packet_type=NEW.packet_type,packet_length=NEW.packet_length,power_status=NEW.power_status,odometer_reading=NEW.odometer_reading,odometer_reading_gps=NEW.odometer_reading_gps,gps_quality=NEW.gps_quality where id=locatioliveid;

ELSE

INSERT INTO gnx_live_location (imei,cur_time,cur_date,logged_time,logged_date,gps_data_valid,latitude,latitude_direction,longitude,longitude_direction,speed,heading_angle,metering_status,gsm_signal_strength,panic_status,total_satellites,packet_type,packet_length,power_status,odometer_reading,odometer_reading_gps,gps_quality) VALUES (NEW.imei, NEW.cur_time, NEW.cur_date, NEW.logged_time, NEW.logged_date, NEW.gps_data_valid, NEW.latitude, NEW.latitude_direction, NEW.longitude, NEW.longitude_direction, NEW.speed, NEW.heading_angle, NEW.metering_status, NEW.gsm_signal_strength, NEW.panic_status, NEW.total_satellites,NEW.packet_type,NEW.packet_length,NEW.power_status,NEW.odometer_reading, NEW.odometer_reading_gps, NEW.gps_quality);

    END IF;

SELECT INTO driverid vehicle_assignment_driver_id  FROM tsb_vehicle_assignment where vehicle_assignment_vehicle_id=vehicleid;

notificationtext='Speed limit exceed of one vehicle, details are vehicle number - '||vehiclenumber||', speed - '||NEW.speed||' on '||NEW.logged_date||' '||NEW.logged_time;

 IF (NEW.speed > speedval AND (NEW.metering_status='B' OR  NEW.metering_status='e') AND NEW.gps_data_valid=1) THEN      

IF(driverid>0) THEN

 SELECT INTO rashdrivedate,rashdriveid rash_drive_date,rash_drive_id from tsb_rash_drive where rash_drive_vehicle_id=vehicleid and rash_drive_driver_id=driverid order by rash_drive_id desc limit 1; 

SELECT INTO speedlimitseconds EXTRACT(EPOCH FROM (DATE_TRUNC('second',(NEW.logged_date||' '||NEW.logged_time)::timestamptz) - rashdrivedate));

 IF (speedlimitseconds>60 OR rashdriveid<1) THEN

 FOR rec IN (SELECT user_id FROM tsb_user where (user_role='transport-manager' or  user_role='customer') and user_status='active')

 LOOP

INSERT INTO tsb_push_notification(push_notification_user_id,push_notification_message,push_notification_type, push_notification_date, push_notification_time, push_notification_status,push_notification_url,push_notification_android_link,push_notification_ios_link) VALUES (rec.user_id,notificationtext,'emergency', NEW.logged_date,NEW.logged_time,'pending','school/report/ranking','track/'||vehicleid,'track/'||vehicleid);

  END LOOP; 

      INSERT INTO tsb_rash_drive(rash_drive_vehicle_id,rash_drive_driver_id,rash_drive_reason, rash_drive_date) VALUES (vehicleid,driverid,'speed_exceed',(NEW.logged_date||' '||NEW.logged_time)::timestamptz);

      END IF;

      END IF;

            END IF;

            END IF;

 RETURN NULL;

END; 

$$;


ALTER FUNCTION public.send_notification_exceed_speed() OWNER TO tsbdbadmin;

--
-- Name: send_notification_panic_alert(); Type: FUNCTION; Schema: public; Owner: tsbdbadmin
--

CREATE FUNCTION public.send_notification_panic_alert() RETURNS trigger
    LANGUAGE plpgsql
    AS $$

DECLARE 

       vehiclenumber VARCHAR; 

vehicleregno VARCHAR; 

       notificationtext VARCHAR;   

        rec record;

    BEGIN	

IF (TG_OP = 'INSERT') THEN 

 IF (NEW.panic_status=1 AND NEW.gps_data_valid=1) THEN

SELECT INTO vehiclenumber,vehicleregno  vehicle_number,vehicle_reg_no   FROM tsb_vehicle where vehicle_imei=NEW.imei;

notificationtext='Panic Alert received from one vehicle, details are vehicle number - '||vehiclenumber||', vehicle register number - '|| vehicleregno;

 FOR rec IN (SELECT * FROM tsb_user where user_role='transport-manager' or  user_role='customer')

 LOOP

      INSERT INTO tsb_notification(notification_text, notification_date, notification_time, notification_type,notification_status,	notification_user_id) VALUES (notificationtext, now()::date, now()::timestamp(0),'alert','unread',rec.user_id );

  END LOOP;

 FOR rec IN (SELECT * FROM tsb_user_apps where user_apps_type='transport_manager' or  user_apps_type='customer')

 LOOP

      INSERT INTO tsb_push_notification(push_notification_apps_id,push_notification_message,push_notification_type, push_notification_date, push_notification_time, push_notification_status) VALUES (rec.user_apps_id,notificationtext,'emergency', now()::date, now()::timestamp(0),'pending' );

  END LOOP;

            END IF;

   END IF;

RETURN NULL;

END;

$$;


ALTER FUNCTION public.send_notification_panic_alert() OWNER TO tsbdbadmin;

--
-- Name: update_vehicle_count_in_statistics(); Type: FUNCTION; Schema: public; Owner: tsbdbadmin
--

CREATE FUNCTION public.update_vehicle_count_in_statistics() RETURNS trigger
    LANGUAGE plpgsql
    AS $$

 
DECLARE 
customerid INTEGER; 
connects VARCHAR; 
test VARCHAR; 
	BEGIN	
		SELECT INTO customerid customer_id FROM tsb_customer;
		IF (customerid>0) THEN
   			SELECT INTO connects dblink_connect_masterdb();
   			IF (TG_OP = 'INSERT') THEN 
      			select INTO test dblink_exec(connects, 'update master_statistics set statistics_vehicle_count = (statistics_vehicle_count+1) where statistics_customer_id = '||customerid::text||';'::text); 
   			ELSEIF (TG_OP = 'UPDATE') THEN 
     			IF(OLD.vehicle_status<>'removed' AND NEW.vehicle_status='removed') THEN
                              select INTO test dblink_exec(connects, 'update master_statistics set statistics_vehicle_count = (statistics_vehicle_count-1) where statistics_customer_id = '||customerid::text||';'::text); 
     			END IF;
   			ELSEIF (TG_OP = 'DELETE') THEN    
     			IF(OLD.vehicle_status<>'removed') THEN
        	              select INTO test dblink_exec(connects, 'update master_statistics set statistics_vehicle_count = (statistics_vehicle_count-1) where statistics_customer_id = '||customerid::text||';'::text); 
     			END IF;
   			END IF;
		END IF;
	RETURN NULL;
END;
 

$$;


ALTER FUNCTION public.update_vehicle_count_in_statistics() OWNER TO tsbdbadmin;



--
-- Name: gnx_alert; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.gnx_alert (
    id integer NOT NULL,
    imei character varying(20),
    cur_time time without time zone,
    cur_date date,
    logged_time time without time zone,
    logged_date date,
    gps_data_valid smallint,
    latitude numeric,
    latitude_direction character(1),
    longitude numeric,
    longitude_direction character(1),
    alert_type character varying(10),
    packet_type smallint,
    packet_length smallint,
    alert_status character varying(200) DEFAULT 'pending'::character varying NOT NULL,
    alert_value character varying(50),
    alert_description text
);


ALTER TABLE public.gnx_alert OWNER TO tsbdbadmin;

--
-- Name: alert_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.alert_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.alert_id_seq OWNER TO tsbdbadmin;

--
-- Name: alert_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.alert_id_seq OWNED BY public.gnx_alert.id;


--
-- Name: tsb_audio; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_audio (
    audio_id integer NOT NULL,
    audio_title character varying(150),
    audio_file character varying(250),
    audio_date date
);


ALTER TABLE public.tsb_audio OWNER TO tsbdbadmin;

--
-- Name: audio_management_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.audio_management_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.audio_management_id_seq OWNER TO tsbdbadmin;

--
-- Name: audio_management_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.audio_management_id_seq OWNED BY public.tsb_audio.audio_id;


--
-- Name: gnx_frequency; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.gnx_frequency (
    id integer NOT NULL,
    imei character varying(20),
    vehicle_moving_detection smallint,
    location_freq_vehicle_notmoving smallint,
    location_freq_vehicle_ismoving smallint,
    direction_devation smallint,
    distance_travelled smallint,
    health_packet smallint,
    panic_mode smallint,
    panic_mode_timeout smallint
);


ALTER TABLE public.gnx_frequency OWNER TO tsbdbadmin;

--
-- Name: data_config_from_server_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.data_config_from_server_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.data_config_from_server_id_seq OWNER TO tsbdbadmin;

--
-- Name: data_config_from_server_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.data_config_from_server_id_seq OWNED BY public.gnx_frequency.id;


--
-- Name: tsb_driver; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_driver (
    driver_id integer NOT NULL,
    driver_licence_number character varying(40),
    driver_licence_issue_date date,
    driver_licence_expire_date date,
    driver_licence_type character varying(50),
    driver_experience integer,
    driver_total_distance_traveled integer,
    driver_licence_area character varying(40),
    driver_status character varying DEFAULT 'active'::character varying NOT NULL,
    driver_mifare_card_no character varying(30)
);


ALTER TABLE public.tsb_driver OWNER TO tsbdbadmin;

--
-- Name: driver_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.driver_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.driver_id_seq OWNER TO tsbdbadmin;

--
-- Name: driver_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.driver_id_seq OWNED BY public.tsb_driver.driver_id;


--
-- Name: tsb_email_driver; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_email_driver (
    email_driver_id integer NOT NULL,
    email_driver_route character varying(50),
    email_driver_vehicle character varying(50),
    email_driver_driver character varying(50),
    email_driver_subject character varying(100),
    email_driver_message text,
    email_driver_datetime date
);


ALTER TABLE public.tsb_email_driver OWNER TO tsbdbadmin;

--
-- Name: email_driver_email_driver_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.email_driver_email_driver_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.email_driver_email_driver_id_seq OWNER TO tsbdbadmin;

--
-- Name: email_driver_email_driver_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.email_driver_email_driver_id_seq OWNED BY public.tsb_email_driver.email_driver_id;


--
-- Name: gnx_alert_type; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.gnx_alert_type (
    alert_type_alert_id character varying(10) NOT NULL,
    alert_type_alert_name character varying(250),
    alert_type_hardware_id integer,
    alert_type_id integer NOT NULL,
    alert_type_type character varying(50) DEFAULT 'alert'::character varying,
    alert_default_status character varying(30) DEFAULT 'ignore'::character varying,
    alert_type_url_web character varying(250) DEFAULT '#'::character varying,
    alert_type_url_android character varying(250) DEFAULT NULL::character varying,
    alert_type_url_ios character varying(250) DEFAULT NULL::character varying
);


ALTER TABLE public.gnx_alert_type OWNER TO tsbdbadmin;

--
-- Name: gnx_alert_type_alert_type_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.gnx_alert_type_alert_type_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.gnx_alert_type_alert_type_id_seq OWNER TO tsbdbadmin;

--
-- Name: gnx_alert_type_alert_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.gnx_alert_type_alert_type_id_seq OWNED BY public.gnx_alert_type.alert_type_id;


--
-- Name: gnx_can_configuration; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.gnx_can_configuration (
    can_cfg_id integer NOT NULL,
    can_cfg_imei character varying(20),
    can_cfg_status smallint,
    can_cfg_communication_type smallint,
    can_cfg_frequency smallint
);


ALTER TABLE public.gnx_can_configuration OWNER TO tsbdbadmin;

--
-- Name: TABLE gnx_can_configuration; Type: COMMENT; Schema: public; Owner: tsbdbadmin
--

COMMENT ON TABLE public.gnx_can_configuration IS 'CAN_CFG';


--
-- Name: gnx_can_configuration_can_cfg_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.gnx_can_configuration_can_cfg_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.gnx_can_configuration_can_cfg_id_seq OWNER TO tsbdbadmin;

--
-- Name: gnx_can_configuration_can_cfg_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.gnx_can_configuration_can_cfg_id_seq OWNED BY public.gnx_can_configuration.can_cfg_id;


--
-- Name: gnx_class_mifare; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.gnx_class_mifare (
    class_mifare_id integer NOT NULL,
    class_mifare_imei character varying(20),
    class_mifare_cur_time time without time zone,
    class_mifare_cur_date date,
    class_mifare_logged_time time without time zone,
    class_mifa_logged_date date,
    class_mifare_packet_type smallint,
    class_mifare_card_valid smallint,
    class_mifare_card_id character varying(20),
    class_mifare_card_info character varying(20)
);


ALTER TABLE public.gnx_class_mifare OWNER TO tsbdbadmin;

--
-- Name: gnx_class_mifare_gnx_mifare_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.gnx_class_mifare_gnx_mifare_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.gnx_class_mifare_gnx_mifare_id_seq OWNER TO tsbdbadmin;

--
-- Name: gnx_class_mifare_gnx_mifare_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.gnx_class_mifare_gnx_mifare_id_seq OWNED BY public.gnx_class_mifare.class_mifare_id;


--
-- Name: gnx_device; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.gnx_device (
    time_offset character varying(20),
    password_1 character varying(25),
    password_2 character varying(25),
    password_3 character varying(25),
    password_4 character varying(25),
    password_5 character varying(25),
    enable_8_bit integer,
    enable_ack integer,
    enable_battery integer,
    vehicle_moving_detection integer,
    sleep_mode integer,
    enable_accelerometer integer,
    imei character varying(20),
    packet_length integer,
    gnx_device_id integer NOT NULL
);


ALTER TABLE public.gnx_device OWNER TO tsbdbadmin;

--
-- Name: gnx_device_gnx_device_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.gnx_device_gnx_device_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.gnx_device_gnx_device_id_seq OWNER TO tsbdbadmin;

--
-- Name: gnx_device_gnx_device_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.gnx_device_gnx_device_id_seq OWNED BY public.gnx_device.gnx_device_id;


--
-- Name: gnx_digital_input_output; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.gnx_digital_input_output (
    id integer NOT NULL,
    imei character varying(20),
    packet_length smallint,
    packet_type smallint,
    curr_time time without time zone,
    curr_date date,
    logged_time time without time zone,
    logged_date date,
    latitude numeric,
    latitude_direction character(1),
    longitude numeric,
    longitude_direction character(1),
    status_di1 integer,
    status_di2 integer,
    status_di3 integer,
    status_di4 integer,
    status_do1 integer,
    status_do2 integer,
    gps_data_valid integer
);


ALTER TABLE public.gnx_digital_input_output OWNER TO tsbdbadmin;

--
-- Name: gnx_digital_input_output_pid; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.gnx_digital_input_output_pid
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.gnx_digital_input_output_pid OWNER TO tsbdbadmin;

--
-- Name: gnx_digital_input_output_pid; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.gnx_digital_input_output_pid OWNED BY public.gnx_digital_input_output.id;


--
-- Name: gnx_ejerk; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.gnx_ejerk (
    ejerk_id integer NOT NULL,
    ejerk_imei character varying(20),
    ejerk_packet_length integer,
    ejerk_packet_type smallint,
    ejerk_current_time time without time zone,
    ejerk_current_date date,
    ejerk_logged_time time without time zone,
    ejerk_logged_date date,
    ejerk_gps_data_valid smallint,
    ejerk_latitude numeric,
    ejerk_latitude_direction character(1),
    ejerk_longitude numeric,
    ejerk_longitude_direction character(1),
    ejerk_speed numeric,
    ejerk_event_x_axis character varying(1),
    ejerk_event_y_axis character varying(1),
    ejerk_event_z_axis character varying(1),
    ejerk_jerk_x_axis numeric,
    ejerk_jerk_y_axis numeric,
    ejerk_jerk_z_axis numeric,
    ejerk_day_x_axis integer,
    ejerk_day_y_axis integer,
    ejerk_day_z_axis integer,
    ejerk_accumulated integer,
    ejerk_accumulated_x_axis integer,
    ejerk_accumulated_y_axis integer,
    ejerk_accumulated_z_axis integer,
    ejerk_gnx_version character varying(20)
);


ALTER TABLE public.gnx_ejerk OWNER TO tsbdbadmin;

--
-- Name: TABLE gnx_ejerk; Type: COMMENT; Schema: public; Owner: tsbdbadmin
--

COMMENT ON TABLE public.gnx_ejerk IS 'table used to store GNX_ejerk signal packet from device';


--
-- Name: gnx_ejerk_ejerk_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.gnx_ejerk_ejerk_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.gnx_ejerk_ejerk_id_seq OWNER TO tsbdbadmin;

--
-- Name: gnx_ejerk_ejerk_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.gnx_ejerk_ejerk_id_seq OWNED BY public.gnx_ejerk.ejerk_id;


--
-- Name: gnx_gprs; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.gnx_gprs (
    id integer NOT NULL,
    apn character varying(40),
    ip_address character varying(150),
    port_number bigint,
    max_sms_allowed bigint,
    phone_no_one bigint,
    phone_no_two bigint,
    password character varying(20),
    imei character varying(20),
    username character varying(40),
    user_password character varying(40)
);


ALTER TABLE public.gnx_gprs OWNER TO tsbdbadmin;

--
-- Name: gnx_hardware_type; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.gnx_hardware_type (
    hardware_id integer NOT NULL,
    hardware_name character varying(250)
);


ALTER TABLE public.gnx_hardware_type OWNER TO tsbdbadmin;

--
-- Name: gnx_health; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.gnx_health (
    id integer NOT NULL,
    imei character varying(20),
    cur_time time without time zone,
    cur_date date,
    logged_time time without time zone,
    logged_date date,
    gps_data_valid smallint,
    panic_status smallint,
    battery_charge_status smallint,
    battery_charge_level smallint,
    battery_voltage numeric,
    pending_gprs_packets integer,
    packet_type smallint,
    packet_length smallint,
    metering_status character(1)
);


ALTER TABLE public.gnx_health OWNER TO tsbdbadmin;

--
-- Name: gnx_j1939; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.gnx_j1939 (
    gnx_j1939_id integer NOT NULL,
    gnx_j1939_imei character varying(20),
    gnx_j1939_packet_length smallint,
    gnx_j1939_packet_type smallint,
    gnx_j1939_curr_time time without time zone,
    gnx_j1939_curr_date date,
    gnx_j1939_log_time time without time zone,
    gnx_j1939_log_date date,
    gnx_j1939_gps_data_valid smallint,
    gnx_j1939_lat numeric,
    gnx_j1939_lat_direction character(1),
    gnx_j1939_long numeric,
    gnx_j1939_long_direction character(1),
    gnx_j1939_pgn character varying(20),
    gnx_j1939_pgn_cfg_number smallint,
    gnx_j1939_response_msg character varying(30)
);


ALTER TABLE public.gnx_j1939 OWNER TO tsbdbadmin;

--
-- Name: TABLE gnx_j1939; Type: COMMENT; Schema: public; Owner: tsbdbadmin
--

COMMENT ON TABLE public.gnx_j1939 IS 'GNX_J1939';


--
-- Name: gnx_j1939_configuration; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.gnx_j1939_configuration (
    j1939_cfg_id integer NOT NULL,
    j1939_cfg_imei character varying(20),
    j1939_cfg_maximum_pgn smallint,
    j1939_cfg_pgn_cfg_number smallint,
    j1939_cfg_priority character varying(20),
    j1939_cfg_pgn character varying(20),
    j1939_cfg_source_addr character varying(20),
    j1939_cfg_no_of_bytes character varying(20),
    j1939_cfg_starting_bytes character varying(20)
);


ALTER TABLE public.gnx_j1939_configuration OWNER TO tsbdbadmin;

--
-- Name: TABLE gnx_j1939_configuration; Type: COMMENT; Schema: public; Owner: tsbdbadmin
--

COMMENT ON TABLE public.gnx_j1939_configuration IS 'J1939_CFG';


--
-- Name: gnx_j1939_configuration_j1939_cfg_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.gnx_j1939_configuration_j1939_cfg_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.gnx_j1939_configuration_j1939_cfg_id_seq OWNER TO tsbdbadmin;

--
-- Name: gnx_j1939_configuration_j1939_cfg_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.gnx_j1939_configuration_j1939_cfg_id_seq OWNED BY public.gnx_j1939_configuration.j1939_cfg_id;


--
-- Name: gnx_j1939_gnx_j1939_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.gnx_j1939_gnx_j1939_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.gnx_j1939_gnx_j1939_id_seq OWNER TO tsbdbadmin;

--
-- Name: gnx_j1939_gnx_j1939_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.gnx_j1939_gnx_j1939_id_seq OWNED BY public.gnx_j1939.gnx_j1939_id;


--
-- Name: gnx_java_exception; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.gnx_java_exception (
    exception_id integer NOT NULL,
    exception_message character varying,
    exception_logged_date date,
    exception_logged_time time without time zone
);


ALTER TABLE public.gnx_java_exception OWNER TO tsbdbadmin;

--
-- Name: gnx_live_location; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.gnx_live_location (
    id integer NOT NULL,
    imei character varying(20),
    cur_time time without time zone,
    cur_date date,
    logged_time time without time zone,
    logged_date date,
    gps_data_valid smallint,
    latitude numeric,
    latitude_direction character(1),
    longitude numeric,
    longitude_direction character(1),
    speed integer,
    heading_angle numeric,
    metering_status character(1),
    gsm_signal_strength smallint,
    panic_status smallint,
    total_satellites smallint,
    packet_type smallint,
    packet_length smallint,
    power_status smallint,
    odometer_reading bigint,
    odometer_reading_gps bigint,
    gps_quality character(1),
    first_odometer_reading bigint,
    all_data json
);


ALTER TABLE public.gnx_live_location OWNER TO tsbdbadmin;

--
-- Name: gnx_location; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.gnx_location (
    id integer NOT NULL,
    imei character varying(20),
    cur_time time without time zone,
    cur_date date,
    logged_time time without time zone,
    logged_date date,
    gps_data_valid smallint,
    latitude numeric,
    latitude_direction character(1),
    longitude numeric,
    longitude_direction character(1),
    speed integer,
    heading_angle numeric,
    metering_status character(1),
    gsm_signal_strength smallint,
    panic_status smallint,
    total_satellites smallint,
    packet_type smallint,
    packet_length smallint,
    power_status smallint,
    odometer_reading bigint,
    odometer_reading_gps bigint,
    gps_quality character(1)
);


ALTER TABLE public.gnx_location OWNER TO tsbdbadmin;

--
-- Name: gnx_mifare_card; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.gnx_mifare_card (
    id integer NOT NULL,
    imei character varying(20),
    cur_time time without time zone,
    cur_date date,
    logged_time time without time zone,
    logged_date date,
    gps_data_valid smallint,
    latitude numeric,
    latitude_direction character(1),
    longitude numeric,
    longitude_direction character(1),
    mifare_card_id character varying(40),
    valid_invalid_vehicle_id smallint,
    packet_length smallint,
    bloack1_information1 character varying(20),
    bloack1_information2 character varying(20),
    packet_history smallint,
    mifare_card_manual_attendance smallint DEFAULT 0
);


ALTER TABLE public.gnx_mifare_card OWNER TO tsbdbadmin;

--
-- Name: gnx_mifare_card_trip; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.gnx_mifare_card_trip (
    id integer NOT NULL,
    imei character varying(20),
    cur_time time without time zone,
    cur_date date,
    logged_time time without time zone,
    logged_date date,
    gps_data_valid smallint,
    latitude numeric,
    latitude_direction character(1),
    longitude numeric,
    longitude_direction character(1),
    mifare_card_id character varying(40),
    valid_invalid_vehicle_id smallint,
    packet_length smallint,
    bloack1_information1 character varying(20),
    bloack1_information2 character varying(500),
    packet_history smallint,
    mifare_card_manual_attendance smallint DEFAULT 0,
    attendance_flag_position smallint DEFAULT 0
);


ALTER TABLE public.gnx_mifare_card_trip OWNER TO tsbdbadmin;

--
-- Name: gnx_mifare_card_user; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.gnx_mifare_card_user (
    id integer NOT NULL,
    imei character varying(20),
    cur_time time without time zone,
    cur_date date,
    logged_time time without time zone,
    logged_date date,
    gps_data_valid smallint,
    latitude numeric,
    latitude_direction character(1),
    longitude numeric,
    longitude_direction character(1),
    mifare_card_id character varying(40),
    valid_invalid_vehicle_id smallint,
    packet_length smallint,
    bloack1_information1 character varying(20),
    bloack1_information2 character varying(500),
    packet_history smallint,
    mifare_card_manual_attendance smallint DEFAULT 0,
    attendance_flag_position smallint DEFAULT 0,
    mifare_card_app_type character varying(30) DEFAULT 'tracking hardware'::text,
    mifare_card_user_id integer,
    mifare_card_user_type character varying(30) DEFAULT 'student'::text
);


ALTER TABLE public.gnx_mifare_card_user OWNER TO tsbdbadmin;

--
-- Name: gnx_pid; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.gnx_pid (
    gnx_pid_id integer NOT NULL,
    gnx_pid_imei character varying(20),
    gnx_pid_packet_length smallint,
    gnx_pid_packet_type smallint,
    gnx_pid_curr_time time without time zone,
    gnx_pid_curr_date date,
    gnx_pid_log_time time without time zone,
    gnx_pid_log_date date,
    gnx_pid_gps_data_valid smallint,
    gnx_pid_lat numeric,
    gnx_pid_lat_direction character(1),
    gnx_pid_long numeric,
    gnx_pid_long_direction character(1),
    gnx_pid_vehicle_speed smallint,
    gnx_pid_engine_rpm smallint,
    gnx_pid_engine_load_value smallint,
    gnx_pid_engine_colent_temp smallint
);


ALTER TABLE public.gnx_pid OWNER TO tsbdbadmin;

--
-- Name: TABLE gnx_pid; Type: COMMENT; Schema: public; Owner: tsbdbadmin
--

COMMENT ON TABLE public.gnx_pid IS 'GNX_PID';


--
-- Name: gnx_pid_gnx_pid_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.gnx_pid_gnx_pid_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.gnx_pid_gnx_pid_id_seq OWNER TO tsbdbadmin;

--
-- Name: gnx_pid_gnx_pid_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.gnx_pid_gnx_pid_id_seq OWNED BY public.gnx_pid.gnx_pid_id;


--
-- Name: gnx_pjerk; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.gnx_pjerk (
    pjerk_id integer NOT NULL,
    pjerk_imei character varying(20),
    pjerk_packet_length integer,
    pjerk_packet_type smallint,
    pjerk_current_time time without time zone,
    pjerk_current_date date,
    pjerk_logged_time time without time zone,
    pjerk_logged_date date,
    pjerk_gps_data_valid smallint,
    pjerk_latitude numeric,
    pjerk_latitude_direction character(1),
    pjerk_longitude numeric,
    pjerk_longitude_direction character(1),
    pjerk_speed numeric,
    pjerk_day_x_axis integer,
    pjerk_day_y_axis integer,
    pjerk_day_z_axis integer,
    pjerk_accumulated integer,
    pjerk_accumulated_x_axis integer,
    pjerk_accumulated_y_axis integer,
    pjerk_accumulated_z_axis integer,
    pjerk_gnx_version character varying(20)
);


ALTER TABLE public.gnx_pjerk OWNER TO tsbdbadmin;

--
-- Name: TABLE gnx_pjerk; Type: COMMENT; Schema: public; Owner: tsbdbadmin
--

COMMENT ON TABLE public.gnx_pjerk IS 'table used to store GNX_PJERK signal packet from device';


--
-- Name: gnx_pjerk_pjerk_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.gnx_pjerk_pjerk_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.gnx_pjerk_pjerk_id_seq OWNER TO tsbdbadmin;

--
-- Name: gnx_pjerk_pjerk_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.gnx_pjerk_pjerk_id_seq OWNED BY public.gnx_pjerk.pjerk_id;


--
-- Name: gnx_vehicle; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.gnx_vehicle (
    gnx_vehicle_id integer NOT NULL,
    gnx_vehicle_imei character varying(20),
    gnx_vehicle_meter_serial_no character varying(40),
    gnx_vehicle_engine_number character varying(40),
    gnx_vehicle_chassis_number character varying(40),
    gnx_vehicle_route_id character varying(40),
    gnx_vehicle_device_model_number character varying(40),
    gnx_vehicle_registration_number character varying(40)
);


ALTER TABLE public.gnx_vehicle OWNER TO tsbdbadmin;

--
-- Name: gnx_vls; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.gnx_vls (
    vls_id integer NOT NULL,
    vls_imei character varying(20),
    vls_packet_length integer,
    vls_packet_type smallint,
    vls_current_time time without time zone,
    vls_current_date date,
    vls_logged_time time without time zone,
    vls_logged_date date,
    vls_gps_data_valid smallint,
    vls_latitude numeric,
    vls_latitude_direction character(1),
    vls_longitude numeric,
    vls_longitude_direction character(1),
    vls_metering_status character(1),
    vls_alert_start_time time without time zone,
    vls_alert_start_date date,
    vls_alert_end_time time without time zone,
    vls_alert_end_date date,
    vls_odometer numeric,
    vls_odometer_gps numeric,
    vls_packet_id character varying(20),
    vls_gnx_version character varying(20)
);


ALTER TABLE public.gnx_vls OWNER TO tsbdbadmin;

--
-- Name: TABLE gnx_vls; Type: COMMENT; Schema: public; Owner: tsbdbadmin
--

COMMENT ON TABLE public.gnx_vls IS 'table used to store GNX_vls signal packet from device';


--
-- Name: gnx_vls_vls_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.gnx_vls_vls_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.gnx_vls_vls_id_seq OWNER TO tsbdbadmin;

--
-- Name: gnx_vls_vls_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.gnx_vls_vls_id_seq OWNED BY public.gnx_vls.vls_id;


--
-- Name: healthstatus_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.healthstatus_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.healthstatus_id_seq OWNER TO tsbdbadmin;

--
-- Name: healthstatus_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.healthstatus_id_seq OWNED BY public.gnx_health.id;


--
-- Name: java_exception_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.java_exception_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.java_exception_id_seq OWNER TO tsbdbadmin;

--
-- Name: java_exception_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.java_exception_id_seq OWNED BY public.gnx_java_exception.exception_id;


--
-- Name: live_location_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.live_location_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.live_location_id_seq OWNER TO tsbdbadmin;

--
-- Name: live_location_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.live_location_id_seq OWNED BY public.gnx_live_location.id;


--
-- Name: location_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.location_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.location_id_seq OWNER TO tsbdbadmin;

--
-- Name: location_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.location_id_seq OWNED BY public.gnx_location.id;


--
-- Name: tsb_logo; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_logo (
    logo_id integer NOT NULL,
    logo_logo character varying(250),
    logo_map_logo character varying(250),
    logo_map_bus character varying(250),
    logo_email character varying(250),
    logo_map_bus_available character varying(250),
    logo_map_bus_untracked character varying(250),
    logo_email_banner character varying(250),
    logo_trip_start_point character varying(250),
    logo_trip_end_point character varying(250),
    logo_bus_idle character varying(250),
    logo_scheduled_trip_drawing character varying,
    logo_real_time_trip_drawing character varying,
    logo_historical_trip_drawing character varying,
    logo_geofence_drawing character varying
);


ALTER TABLE public.tsb_logo OWNER TO tsbdbadmin;

--
-- Name: logo_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.logo_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.logo_id_seq OWNER TO tsbdbadmin;

--
-- Name: logo_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.logo_id_seq OWNED BY public.tsb_logo.logo_id;


--
-- Name: master_location; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.master_location (
    location_id integer NOT NULL,
    location_name character varying(100),
    location_latitude numeric,
    location_longitude numeric,
    location_address character varying(100)
);


ALTER TABLE public.master_location OWNER TO tsbdbadmin;

--
-- Name: master_location_location_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.master_location_location_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.master_location_location_id_seq OWNER TO tsbdbadmin;

--
-- Name: master_location_location_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.master_location_location_id_seq OWNED BY public.master_location.location_id;


--
-- Name: tsb_parking_slot; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_parking_slot (
    slot_id integer NOT NULL,
    slot_code character varying(120),
    slot_name character varying(250),
    address character varying(250),
    slot_gps_latitude numeric,
    slot_gps_longitude numeric,
    school_id integer,
    slot_status character varying(250)
);


ALTER TABLE public.tsb_parking_slot OWNER TO tsbdbadmin;

--
-- Name: master_parking_slot_slot_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.master_parking_slot_slot_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.master_parking_slot_slot_id_seq OWNER TO tsbdbadmin;

--
-- Name: master_parking_slot_slot_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.master_parking_slot_slot_id_seq OWNED BY public.tsb_parking_slot.slot_id;


--
-- Name: tsb_message; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_message (
    message_id integer NOT NULL,
    message_from_id bigint,
    message_to_id bigint,
    message_parent_id bigint,
    message_content text,
    message_date_time timestamp without time zone,
    message_status character varying(10)
);


ALTER TABLE public.tsb_message OWNER TO tsbdbadmin;

--
-- Name: message_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.message_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.message_id_seq OWNER TO tsbdbadmin;

--
-- Name: message_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.message_id_seq OWNED BY public.tsb_message.message_id;


--
-- Name: mifare_card_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.mifare_card_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.mifare_card_id_seq OWNER TO tsbdbadmin;

--
-- Name: mifare_card_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.mifare_card_id_seq OWNED BY public.gnx_mifare_card.id;


--
-- Name: mifare_card_trip_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.mifare_card_trip_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.mifare_card_trip_id_seq OWNER TO tsbdbadmin;

--
-- Name: mifare_card_trip_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.mifare_card_trip_id_seq OWNED BY public.gnx_mifare_card_trip.id;


--
-- Name: mifare_card_user_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.mifare_card_user_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.mifare_card_user_id_seq OWNER TO tsbdbadmin;

--
-- Name: mifare_card_user_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.mifare_card_user_id_seq OWNED BY public.gnx_mifare_card_user.id;


--
-- Name: tsb_notification_log; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_notification_log (
    notification_log_id integer NOT NULL,
    notification_log_student_id bigint,
    notification_log_priority smallint,
    notification_log_cron_name character varying(100),
    notification_log_date date,
    notification_log_time time without time zone
);


ALTER TABLE public.tsb_notification_log OWNER TO tsbdbadmin;

--
-- Name: notification_log_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.notification_log_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.notification_log_id_seq OWNER TO tsbdbadmin;

--
-- Name: notification_log_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.notification_log_id_seq OWNED BY public.tsb_notification_log.notification_log_id;


--
-- Name: tsb_parkingslot_geofence; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_parkingslot_geofence (
    geofence_id integer NOT NULL,
    geofence_parkingslot_id integer,
    geofence_draw_point character varying(200),
    geofence_details character varying(15),
    geofence_draw_type character varying(15)
);


ALTER TABLE public.tsb_parkingslot_geofence OWNER TO tsbdbadmin;

--
-- Name: parkingslot_geofence_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.parkingslot_geofence_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.parkingslot_geofence_id_seq OWNER TO tsbdbadmin;

--
-- Name: parkingslot_geofence_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.parkingslot_geofence_id_seq OWNED BY public.tsb_parkingslot_geofence.geofence_id;


--
-- Name: tsb_pickup_change; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_pickup_change (
    pickup_change_id integer NOT NULL,
    pickup_change_student_id integer,
    pickup_change_route_id integer,
    pickup_change_latitude numeric,
    pickup_change_longitude numeric,
    pickup_change_status character varying(15)
);


ALTER TABLE public.tsb_pickup_change OWNER TO tsbdbadmin;

--
-- Name: pickup_change_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.pickup_change_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.pickup_change_id_seq OWNER TO tsbdbadmin;

--
-- Name: pickup_change_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.pickup_change_id_seq OWNED BY public.tsb_pickup_change.pickup_change_id;


--
-- Name: tsb_pickup; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_pickup (
    pickup_id integer NOT NULL,
    pickup_student_id integer,
    pickup_pickup_point_id integer,
    pickup_route_id integer,
    pickup_vehicle_id integer,
    pickup_type character varying(20),
    pickup_status character varying(40) DEFAULT 'active'::character varying
);


ALTER TABLE public.tsb_pickup OWNER TO tsbdbadmin;

--
-- Name: pickup_details_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.pickup_details_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.pickup_details_id_seq OWNER TO tsbdbadmin;

--
-- Name: pickup_details_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.pickup_details_id_seq OWNED BY public.tsb_pickup.pickup_id;


--
-- Name: tsb_pickup_point; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_pickup_point (
    pickup_point_id integer NOT NULL,
    pickup_point_route_id integer,
    pickup_point_name character varying(100),
    pickup_point_code character varying(100),
    pickup_point_distance_from_source numeric,
    pickup_point_priority smallint,
    pickup_point_latitude numeric,
    pickup_point_longitude numeric,
    pickup_point_status character varying(40) DEFAULT 'active'::character varying,
    pickup_point_trip_id integer,
    pickup_point_eta time without time zone
);


ALTER TABLE public.tsb_pickup_point OWNER TO tsbdbadmin;

--
-- Name: pickup_point_master_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.pickup_point_master_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.pickup_point_master_id_seq OWNER TO tsbdbadmin;

--
-- Name: pickup_point_master_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.pickup_point_master_id_seq OWNED BY public.tsb_pickup_point.pickup_point_id;


--
-- Name: tsb_instant_pickup; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_instant_pickup (
    instant_pickup_id integer NOT NULL,
    instant_pickup_passenger_id bigint,
    instant_pickup_pickup_point character varying(200),
    instant_pickup_drop_point character varying(200),
    instant_pickup_pickup_time time without time zone,
    instant_pickup_pickup_date date,
    instant_pickup_repeat smallint,
    instant_pickup_status smallint,
    instant_pickup_latitude numeric,
    instant_pickup_longitude numeric,
    instant_drop_latitude numeric,
    instant_drop_longitude numeric,
    instant_pickup_vehicle_id integer,
    instant_pickup_driver_id integer,
    instant_pickup_helper_id integer,
    instant_pickup_end_date date,
    instant_pickup_end_time time without time zone
);


ALTER TABLE public.tsb_instant_pickup OWNER TO tsbdbadmin;

--
-- Name: pickup_unasigned_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.pickup_unasigned_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.pickup_unasigned_id_seq OWNER TO tsbdbadmin;

--
-- Name: pickup_unasigned_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.pickup_unasigned_id_seq OWNED BY public.tsb_instant_pickup.instant_pickup_id;


--
-- Name: tsb_rash_drive; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_rash_drive (
    rash_drive_id integer NOT NULL,
    rash_drive_vehicle_id integer,
    rash_drive_driver_id integer,
    rash_drive_reason character varying(1000),
    rash_drive_date timestamp without time zone
);


ALTER TABLE public.tsb_rash_drive OWNER TO tsbdbadmin;

--
-- Name: rash_drive_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.rash_drive_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.rash_drive_id_seq OWNER TO tsbdbadmin;

--
-- Name: rash_drive_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.rash_drive_id_seq OWNED BY public.tsb_rash_drive.rash_drive_id;


--
-- Name: tsb_calculator_geofence; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_calculator_geofence (
    geofence_id integer NOT NULL,
    geofence_calculator_id integer,
    geofence_draw_point character varying(200),
    geofence_details character varying(15),
    geofence_draw_type character varying(15),
    geofence_name character varying
);


ALTER TABLE public.tsb_calculator_geofence OWNER TO tsbdbadmin;

--
-- Name: route_map_border_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.route_map_border_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.route_map_border_id_seq OWNER TO tsbdbadmin;

--
-- Name: route_map_border_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.route_map_border_id_seq OWNED BY public.tsb_calculator_geofence.geofence_id;


--
-- Name: tsb_route; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_route (
    route_id integer NOT NULL,
    route_name character varying(60),
    route_description character varying(100),
    route_status character varying(40) DEFAULT 'active'::character varying,
    route_start_point character varying,
    route_start_latitude character varying,
    route_start_longitude character varying,
    route_end_point character varying,
    route_end_latitude character varying,
    route_end_longitude character varying
);


ALTER TABLE public.tsb_route OWNER TO tsbdbadmin;

--
-- Name: route_master_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.route_master_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.route_master_id_seq OWNER TO tsbdbadmin;

--
-- Name: route_master_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.route_master_id_seq OWNED BY public.tsb_route.route_id;


--
-- Name: tsb_signal_server; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_signal_server (
    signal_server_id bigint NOT NULL,
    signal_server_packet character varying(500),
    signal_server_datetime timestamp without time zone,
    signal_server_status character varying(10)
);


ALTER TABLE public.tsb_signal_server OWNER TO tsbdbadmin;

--
-- Name: TABLE tsb_signal_server; Type: COMMENT; Schema: public; Owner: tsbdbadmin
--

COMMENT ON TABLE public.tsb_signal_server IS 'here we store signal to device';


--
-- Name: signal_server_signal_server_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.signal_server_signal_server_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.signal_server_signal_server_id_seq OWNER TO tsbdbadmin;

--
-- Name: signal_server_signal_server_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.signal_server_signal_server_id_seq OWNED BY public.tsb_signal_server.signal_server_id;


--
-- Name: sms_data_config_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.sms_data_config_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.sms_data_config_id_seq OWNER TO tsbdbadmin;

--
-- Name: sms_data_config_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.sms_data_config_id_seq OWNED BY public.gnx_gprs.id;


--
-- Name: tsb_sms_log; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_sms_log (
    sms_log_id integer NOT NULL,
    sms_log_priority smallint,
    sms_log_date date,
    sms_log_time time without time zone,
    sms_log_student_id smallint,
    sms_log_cron_name character varying(100)
);


ALTER TABLE public.tsb_sms_log OWNER TO tsbdbadmin;

--
-- Name: sms_log_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.sms_log_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.sms_log_id_seq OWNER TO tsbdbadmin;

--
-- Name: sms_log_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.sms_log_id_seq OWNED BY public.tsb_sms_log.sms_log_id;


--
-- Name: tsb_trips_history; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_trips_history (
    trips_history_id integer NOT NULL,
    trips_history_trip_id bigint,
    trip_history_type character varying(15),
    trips_history_driver_id bigint,
    trips_history_start_date date,
    trips_history_start_time time without time zone,
    trips_history_end_date date,
    trips_history_end_time time without time zone,
    trips_history_km numeric,
    trips_history_status character varying(20) NOT NULL,
    trips_history_vehicle_id integer,
    trips_history_route_id integer,
    trips_history_helper_id integer,
    trips_history_trip_type character varying(20),
    trips_history_shift_id integer
);


ALTER TABLE public.tsb_trips_history OWNER TO tsbdbadmin;

--
-- Name: trips_history_trips_history_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.trips_history_trips_history_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.trips_history_trips_history_id_seq OWNER TO tsbdbadmin;

--
-- Name: trips_history_trips_history_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.trips_history_trips_history_id_seq OWNED BY public.tsb_trips_history.trips_history_id;


--
-- Name: tsb_addon; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_addon (
    addon_customer_id integer NOT NULL,
    addon_autorouting smallint DEFAULT 0,
    addon_manual_routing smallint DEFAULT 0,
    addon_accountant smallint DEFAULT 0,
    addon_tag_vendor smallint DEFAULT 0,
    addon_support smallint DEFAULT 0,
    addon_surveyor_planner smallint DEFAULT 0,
    addon_trip_card smallint DEFAULT 0,
    addon_employee_attendance smallint DEFAULT 0,
    addon_cashless smallint DEFAULT 0,
    addon_green_card smallint DEFAULT 0,
    addon_driver_attendance smallint DEFAULT 0,
    addon_dispatch smallint DEFAULT '0'::smallint
);


ALTER TABLE public.tsb_addon OWNER TO tsbdbadmin;

--
-- Name: tsb_alert_comments; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_alert_comments (
    alert_comments_id integer NOT NULL,
    alert_comments_user_id integer,
    alert_comments_date date,
    alert_comments_time time without time zone,
    alert_comments_text text,
    alert_comments_status character varying(100) DEFAULT 'active'::character varying,
    alert_comments_alert_id integer
);


ALTER TABLE public.tsb_alert_comments OWNER TO tsbdbadmin;

--
-- Name: tsb_alert_comments_alert_comments_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_alert_comments_alert_comments_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_alert_comments_alert_comments_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_alert_comments_alert_comments_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_alert_comments_alert_comments_id_seq OWNED BY public.tsb_alert_comments.alert_comments_id;


--
-- Name: tsb_announcement; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_announcement (
    announcement_id integer NOT NULL,
    announcement_type character varying(50) NOT NULL,
    announcement_content character varying(2000),
    announcement_date date,
    announcement_image character varying(250)
);


ALTER TABLE public.tsb_announcement OWNER TO tsbdbadmin;

--
-- Name: tsb_announcement_announcement_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_announcement_announcement_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_announcement_announcement_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_announcement_announcement_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_announcement_announcement_id_seq OWNED BY public.tsb_announcement.announcement_id;


--
-- Name: tsb_apps; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_apps (
    apps_customer_id integer NOT NULL,
    apps_tm_android_version character varying(15) DEFAULT '0.0.0'::character varying,
    apps_tm_ios_version character varying(15) DEFAULT '0.0.0'::character varying,
    apps_fm_android_version character varying(15) DEFAULT '0.0.0'::character varying,
    apps_fm_ios_version character varying(15) DEFAULT '0.0.0'::character varying,
    apps_dc_android_version character varying(15) DEFAULT '0.0.0'::character varying,
    apps_dc_ios_version character varying(15) DEFAULT '0.0.0'::character varying
);


ALTER TABLE public.tsb_apps OWNER TO tsbdbadmin;

--
-- Name: tsb_apps_apps_customer_d_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_apps_apps_customer_d_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_apps_apps_customer_d_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_apps_apps_customer_d_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_apps_apps_customer_d_seq OWNED BY public.tsb_apps.apps_customer_id;


--
-- Name: tsb_area; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_area (
    area_id character varying(20) NOT NULL,
    area_name character varying(50),
    area_address character varying(250),
    area_country character varying(50),
    area_city character varying(50),
    area_land_mark character varying(250),
    area_parent character varying(20),
    area_latitude numeric,
    area_longitude numeric,
    area_speed_limit integer
);


ALTER TABLE public.tsb_area OWNER TO tsbdbadmin;

--
-- Name: tsb_area_area_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_area_area_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_area_area_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_area_area_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_area_area_id_seq OWNED BY public.tsb_area.area_id;


--
-- Name: tsb_area_geofence; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_area_geofence (
    geofence_area_id integer NOT NULL,
    geofence_area_area_id character varying,
    geofence_area_draw_point character varying(200),
    geofence_area_details character varying(15),
    geofence_area_draw_type character varying(15),
    geofence_area_parent_id character varying(20)
);


ALTER TABLE public.tsb_area_geofence OWNER TO tsbdbadmin;

--
-- Name: tsb_area_geofence_geofence_area_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_area_geofence_geofence_area_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_area_geofence_geofence_area_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_area_geofence_geofence_area_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_area_geofence_geofence_area_id_seq OWNED BY public.tsb_area_geofence.geofence_area_id;


--
-- Name: tsb_attendance_anomalies; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_attendance_anomalies (
    attendance_anomalies_id integer NOT NULL,
    attendance_anomalies_type smallint
);


ALTER TABLE public.tsb_attendance_anomalies OWNER TO tsbdbadmin;

--
-- Name: tsb_attendance_user; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_attendance_user (
    attendance_id integer NOT NULL,
    attendance_user_id integer,
    attendance_date date,
    attendance_check_in_out time without time zone,
    attendance_flag_position smallint,
    attendance_latitude numeric DEFAULT 0,
    attendance_longitude numeric DEFAULT 0,
    attendance_manual_attendance smallint DEFAULT 0,
    attendance_location character varying(500),
    attendance_vehicle_id integer DEFAULT 0,
    attendance_app_type character varying(30) DEFAULT 'tracking-hardware'::text
);


ALTER TABLE public.tsb_attendance_user OWNER TO tsbdbadmin;

--
-- Name: tsb_calculator_list; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_calculator_list (
    calculator_list_id integer NOT NULL,
    calculator_list_calculator_id integer,
    calculator_list_title character varying,
    calculator_status character varying(50),
    calculator_type character varying
);


ALTER TABLE public.tsb_calculator_list OWNER TO tsbdbadmin;

--
-- Name: tsb_calculator_list_calculator_list_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_calculator_list_calculator_list_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_calculator_list_calculator_list_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_calculator_list_calculator_list_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_calculator_list_calculator_list_id_seq OWNED BY public.tsb_calculator_list.calculator_list_id;


--
-- Name: tsb_cctv; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_cctv (
    cctv_imei character varying(20) NOT NULL,
    cctv_ip character varying(20),
    cctv_port bigint,
    cctv_username character varying(40),
    cctv_password character varying(40),
    cctv_sdk character varying(50)
);


ALTER TABLE public.tsb_cctv OWNER TO tsbdbadmin;

--
-- Name: tsb_customer; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_customer (
    customer_id bigint NOT NULL,
    customer_name character varying(100),
    customer_city character varying(40),
    customer_country character varying(40),
    customer_mobile bigint,
    customer_email character varying(150),
    customer_port character varying(100),
    customer_address character varying(500),
    customer_latitude numeric,
    customer_longitude numeric,
    customer_time_zone character varying(100),
    customer_parent_android_key character varying(300),
    customer_browser_google_key character varying(300) DEFAULT 300,
    customer_api_key character varying(40),
    customer_status character varying(10) DEFAULT 'active'::character varying,
    customer_timezone_utc_offset character varying(150) NOT NULL,
    customer_current_academic_year bigint,
    customer_speed_limit integer DEFAULT 50,
    customer_weekend_days character varying(20),
    customer_tm_android_key character varying(300),
    customer_tm_ios_pem character varying(300),
    customer_driver_android_key character varying(300),
    customer_helper_android_key character varying(300),
    customer_attendant_android_key character varying(300),
    customer_plan bigint,
    customer_account_type public.account_type DEFAULT 'demo'::public.account_type,
    customer_expiry_date date,
    customer_joining_date date,
    customer_transportation_type public.transportation_type DEFAULT 'charged'::public.transportation_type,
    customer_date_format character varying(15) DEFAULT 'd-m-Y'::character varying,
    customer_currency integer,
    customer_customer_geofence integer,
    customer_pickup_geofence integer,
    customer_principal_name character varying(100),
    customer_website character varying(300),
    customer_parent_ios_pem character varying(300),
    customer_distributor_id integer,
    customer_page_limit integer DEFAULT 25,
    customer_notification_radius numeric DEFAULT 3,
    customer_display_key character varying(100),
    customer_pos_ios_pem character varying(300),
    customer_franchise_id integer,
    customer_transportation_geofence integer,
    customer_category character varying,
    customer_organisation_type character varying,
    customer_business_domain_name character varying,
    customer_vehicel_credits integer DEFAULT 2,
    customer_dispatch_android_key character varying(300)
);


ALTER TABLE public.tsb_customer OWNER TO tsbdbadmin;

--
-- Name: tsb_customer_customer_timezone_utc_offset_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_customer_customer_timezone_utc_offset_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_customer_customer_timezone_utc_offset_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_customer_customer_timezone_utc_offset_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_customer_customer_timezone_utc_offset_seq OWNED BY public.tsb_customer.customer_timezone_utc_offset;


--
-- Name: tsb_customer_geofence; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_customer_geofence (
    geofence_id integer NOT NULL,
    geofence_draw_point character varying(200),
    geofence_details character varying(15),
    geofence_draw_type character varying(15),
    geofence_customer_id integer
);


ALTER TABLE public.tsb_customer_geofence OWNER TO tsbdbadmin;

--
-- Name: tsb_customer_geofence_geofence_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_customer_geofence_geofence_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_customer_geofence_geofence_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_customer_geofence_geofence_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_customer_geofence_geofence_id_seq OWNED BY public.tsb_customer_geofence.geofence_id;


--
-- Name: tsb_email_helper; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_email_helper (
    email_helper_id integer NOT NULL,
    email_helper_route character varying(50),
    email_helper_vehicle character varying(50),
    email_helper_helper character varying(50),
    email_helper_subject character varying(100),
    email_helper_message text,
    email_helper_datetime date
);


ALTER TABLE public.tsb_email_helper OWNER TO tsbdbadmin;

--
-- Name: tsb_email_helper_email_helper_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_email_helper_email_helper_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_email_helper_email_helper_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_email_helper_email_helper_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_email_helper_email_helper_id_seq OWNED BY public.tsb_email_helper.email_helper_id;


--
-- Name: tsb_email_staff; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_email_staff (
    email_staff_id integer NOT NULL,
    email_staff_type character varying(100),
    email_staff_name character varying(100),
    email_staff_subject character varying(100),
    email_staff_message text,
    email_staff_date date
);


ALTER TABLE public.tsb_email_staff OWNER TO tsbdbadmin;

--
-- Name: tsb_email_staff_email_staff_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_email_staff_email_staff_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_email_staff_email_staff_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_email_staff_email_staff_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_email_staff_email_staff_id_seq OWNED BY public.tsb_email_staff.email_staff_id;


--
-- Name: tsb_fleat_maintenance; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_fleat_maintenance (
    fleat_maintenance_id integer NOT NULL,
    fleat_maintenance_bus_id integer,
    fleat_mantenance_task character varying(100),
    fleat_mantenance_duration integer,
    fleat_mantenance_start_date date,
    fleat_mantenance_next_due_date date,
    fleat_mantenance_task_type character varying(100),
    fleat_mantenance_off_road integer,
    fleat_maintenance_due_mode character varying(40) DEFAULT 'date'::character varying,
    fleat_maintenance_due_milage character varying(40),
    fleat_maintenance_invoice_no character varying(200),
    fleat_maintenance_expense character varying,
    fleat_maintenance_expensee character varying
);


ALTER TABLE public.tsb_fleat_maintenance OWNER TO tsbdbadmin;

--
-- Name: tsb_fleat_maintenance_fleat_maintenance_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_fleat_maintenance_fleat_maintenance_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_fleat_maintenance_fleat_maintenance_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_fleat_maintenance_fleat_maintenance_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_fleat_maintenance_fleat_maintenance_id_seq OWNED BY public.tsb_fleat_maintenance.fleat_maintenance_id;


--
-- Name: tsb_holiday; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_holiday (
    holiday_id integer NOT NULL,
    holiday_name character varying(100),
    holiday_date date,
    holiday_desc character varying(2000),
    holiday_status character varying(20) DEFAULT 'active'::character varying
);


ALTER TABLE public.tsb_holiday OWNER TO tsbdbadmin;

--
-- Name: tsb_holiday_holiday_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_holiday_holiday_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_holiday_holiday_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_holiday_holiday_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_holiday_holiday_id_seq OWNED BY public.tsb_holiday.holiday_id;


--
-- Name: tsb_instant_repeat; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_instant_repeat (
    instant_repeat_pickup_id bigint NOT NULL,
    instant_repeat_repeat_end_date date,
    instant_repeat_monday smallint,
    instant_repeat_tuesday smallint,
    instant_repeat_wednesday smallint,
    instant_repeat_thursday smallint,
    instant_repeat_friday smallint,
    instant_repeat_saturday smallint,
    instant_repeat_sunday smallint
);


ALTER TABLE public.tsb_instant_repeat OWNER TO tsbdbadmin;

--
-- Name: tsb_invoice; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_invoice (
    invoice_id integer NOT NULL,
    invoice_date date,
    invoice_amount numeric,
    invoice_status public.invoice_status DEFAULT 'invoiced'::public.invoice_status,
    invoice_from_id integer,
    invoice_to_id integer
);


ALTER TABLE public.tsb_invoice OWNER TO tsbdbadmin;

--
-- Name: tsb_invoice_item; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_invoice_item (
    invoice_item_id integer NOT NULL,
    invoice_item_invoice_id bigint,
    invoice_item_name character varying(100),
    invoice_item_amount numeric,
    invoice_item_qty integer
);


ALTER TABLE public.tsb_invoice_item OWNER TO tsbdbadmin;

--
-- Name: tsb_mailqueue; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_mailqueue (
    mailqueue_id integer NOT NULL,
    mailqueue_to_email character varying(200),
    mailqueue_bcc text,
    mailqueue_to_name character varying(200),
    mailqueue_subject character varying(250),
    mailqueue_body text,
    mailqueue_date timestamp without time zone,
    mailqueue_status character varying(20) DEFAULT 0,
    mailqueue_template character varying(50)
);


ALTER TABLE public.tsb_mailqueue OWNER TO tsbdbadmin;

--
-- Name: tsb_mailqueue_mailqueue_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_mailqueue_mailqueue_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_mailqueue_mailqueue_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_mailqueue_mailqueue_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_mailqueue_mailqueue_id_seq OWNED BY public.tsb_mailqueue.mailqueue_id;


--
-- Name: tsb_message_relation; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_message_relation (
    message_relation_master_message_id bigint NOT NULL,
    message_relation_message_id bigint
);


ALTER TABLE public.tsb_message_relation OWNER TO tsbdbadmin;

--
-- Name: tsb_message_thread; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_message_thread (
    message_thread_id integer NOT NULL,
    message_thread_from_id integer,
    message_thread_to_id integer,
    message_thread_subject character varying(100),
    message_thread_date_time timestamp without time zone
);


ALTER TABLE public.tsb_message_thread OWNER TO tsbdbadmin;

--
-- Name: tsb_message_tread_message_thread_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_message_tread_message_thread_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_message_tread_message_thread_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_message_tread_message_thread_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_message_tread_message_thread_id_seq OWNED BY public.tsb_message_thread.message_thread_id;


--
-- Name: tsb_notification; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_notification (
    notification_id integer NOT NULL,
    notification_text character varying(1000),
    notification_date date,
    notification_time time without time zone,
    notification_type character varying(15),
    notification_status character varying(10),
    notification_user_id integer NOT NULL,
    notification_url character varying(100) DEFAULT '#'::character varying,
    notification_android_link character varying(100),
    notification_ios_link character varying(100),
    notification_settings_untracked smallint
);


ALTER TABLE public.tsb_notification OWNER TO tsbdbadmin;

--
-- Name: tsb_notification_driver; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_notification_driver (
    notification_driver_id integer NOT NULL,
    notification_driver_route character varying(50),
    notification_driver_vehicle character varying(50),
    notification_driver_driver character varying(50),
    notification_driver_message text,
    notification_driver_datetime date,
    notification_driver_role character varying(50)
);


ALTER TABLE public.tsb_notification_driver OWNER TO tsbdbadmin;

--
-- Name: tsb_notification_driver_notification_driver_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_notification_driver_notification_driver_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_notification_driver_notification_driver_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_notification_driver_notification_driver_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_notification_driver_notification_driver_id_seq OWNED BY public.tsb_notification_driver.notification_driver_id;


--
-- Name: tsb_notification_notification_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_notification_notification_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_notification_notification_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_notification_notification_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_notification_notification_id_seq OWNED BY public.tsb_notification.notification_id;


--
-- Name: tsb_notification_settings; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_notification_settings (
    notification_settings_id integer NOT NULL,
    notification_settings_announcement smallint,
    notification_settings_holiday smallint,
    notification_settings_pickup_point smallint,
    notification_settings_language character varying(20),
    notification_settings_speed_break smallint DEFAULT 1,
    notification_settings_geofence_break smallint DEFAULT 1,
    notification_settings_power_on smallint DEFAULT 1,
    notification_settings_power_off smallint DEFAULT 1,
    notification_settings_battery_low smallint DEFAULT 1,
    notification_settings_simtary_open smallint DEFAULT 1,
    notification_settings_boxcover_open smallint DEFAULT 1,
    notification_settings_boxcover_close smallint DEFAULT 1,
    notification_settings_battery_remove smallint DEFAULT 1,
    notification_settings_seat_belt smallint DEFAULT 1,
    notification_settings_harsh_accelaration smallint DEFAULT 1,
    notification_settings_harsh_brak smallint DEFAULT 1,
    notification_settings_user_id integer,
    notification_settings_driver_licence smallint DEFAULT 1,
    notification_settings_pushnotification smallint DEFAULT 1,
    notification_settings_subscription smallint DEFAULT 1,
    notification_settings_user smallint DEFAULT 1,
    notification_settings_vehicle_tax smallint DEFAULT 1,
    notification_settings_vehicle_insurance smallint DEFAULT 1,
    notification_settings_vehicle_licence smallint DEFAULT 1,
    notification_settings_vehicle_maintenance smallint DEFAULT 1,
    notification_settings_vehicle_track smallint DEFAULT 1,
    notification_settings_vehicle_trip smallint DEFAULT 1,
    notification_settings_audible smallint DEFAULT 1,
    notification_settings_message smallint DEFAULT 1,
    notification_settings_helper smallint DEFAULT 1,
    notification_settings_untracked smallint DEFAULT 1,
    notification_settings_maintenance_days integer DEFAULT 7,
    notification_settings_taxexpiry_days integer DEFAULT 7,
    notification_settings_insurance_days integer DEFAULT 7,
    notification_settings_permit_days integer DEFAULT 7,
    notification_settings_maintenance_milage integer DEFAULT 500,
    notification_settings_next_inspection_date integer DEFAULT 7,
    notification_settings_parking_slots smallint DEFAULT 0
);


ALTER TABLE public.tsb_notification_settings OWNER TO tsbdbadmin;

--
-- Name: tsb_notification_settings_email; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_notification_settings_email (
    notification_settings_id integer NOT NULL,
    notification_settings_announcement smallint DEFAULT 1,
    notification_settings_holiday smallint DEFAULT 1,
    notification_settings_pickup_point smallint DEFAULT 1,
    notification_settings_language character varying(20),
    notification_settings_speed_break smallint DEFAULT 1,
    notification_settings_geofence_break smallint DEFAULT 1,
    notification_settings_power_on smallint DEFAULT 1,
    notification_settings_power_off smallint DEFAULT 1,
    notification_settings_battery_low smallint DEFAULT 1,
    notification_settings_simtary_open smallint DEFAULT 1,
    notification_settings_boxcover_open smallint DEFAULT 1,
    notification_settings_boxcover_close smallint DEFAULT 1,
    notification_settings_battery_remove smallint DEFAULT 1,
    notification_settings_seat_belt smallint DEFAULT 1,
    notification_settings_harsh_accelaration smallint DEFAULT 1,
    notification_settings_harsh_brak smallint DEFAULT 1,
    notification_settings_driver_licence smallint DEFAULT 1,
    notification_settings_pushnotification smallint DEFAULT 1,
    notification_settings_subscription smallint DEFAULT 1,
    notification_settings_user smallint DEFAULT 1,
    notification_settings_vehicle_tax smallint DEFAULT 1,
    notification_settings_vehicle_insurance smallint DEFAULT 1,
    notification_settings_vehicle_licence smallint DEFAULT 1,
    notification_settings_vehicle_maintenance smallint DEFAULT 1,
    notification_settings_vehicle_track smallint DEFAULT 1,
    notification_settings_vehicle_trip smallint DEFAULT 1,
    notification_settings_audible smallint DEFAULT 1,
    notification_settings_message smallint DEFAULT 1,
    notification_settings_helper smallint DEFAULT 1,
    notification_settings_user_id integer,
    notification_settings_untracked smallint DEFAULT 1,
    notification_settings_parking_slots smallint DEFAULT 0
);


ALTER TABLE public.tsb_notification_settings_email OWNER TO tsbdbadmin;

--
-- Name: tsb_notification_settings_notification_settings_email_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_notification_settings_notification_settings_email_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_notification_settings_notification_settings_email_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_notification_settings_notification_settings_email_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_notification_settings_notification_settings_email_id_seq OWNED BY public.tsb_notification_settings_email.notification_settings_id;


--
-- Name: tsb_notification_settings_notification_settings_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_notification_settings_notification_settings_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_notification_settings_notification_settings_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_notification_settings_notification_settings_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_notification_settings_notification_settings_id_seq OWNED BY public.tsb_notification_settings.notification_settings_id;


--
-- Name: tsb_notification_settings_sms; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_notification_settings_sms (
    notification_settings_id integer NOT NULL,
    notification_settings_announcement smallint DEFAULT 0,
    notification_settings_holiday smallint DEFAULT 0,
    notification_settings_pickup_point smallint DEFAULT 0,
    notification_settings_language character varying(20),
    notification_settings_speed_break smallint DEFAULT 0,
    notification_settings_geofence_break smallint DEFAULT 0,
    notification_settings_power_on smallint DEFAULT 0,
    notification_settings_power_off smallint DEFAULT 0,
    notification_settings_battery_low smallint DEFAULT 0,
    notification_settings_simtary_open smallint DEFAULT 0,
    notification_settings_boxcover_open smallint DEFAULT 0,
    notification_settings_boxcover_close smallint DEFAULT 0,
    notification_settings_battery_remove smallint DEFAULT 0,
    notification_settings_seat_belt smallint DEFAULT 0,
    notification_settings_harsh_accelaration smallint DEFAULT 0,
    notification_settings_harsh_brak smallint DEFAULT 0,
    notification_settings_driver_licence smallint DEFAULT 0,
    notification_settings_pushnotification smallint DEFAULT 0,
    notification_settings_subscription smallint DEFAULT 0,
    notification_settings_user smallint DEFAULT 0,
    notification_settings_vehicle_tax smallint DEFAULT 0,
    notification_settings_vehicle_insurance smallint DEFAULT 0,
    notification_settings_vehicle_licence smallint DEFAULT 0,
    notification_settings_vehicle_maintenance smallint DEFAULT 0,
    notification_settings_vehicle_track smallint DEFAULT 0,
    notification_settings_vehicle_trip smallint DEFAULT 0,
    notification_settings_audible smallint DEFAULT 0,
    notification_settings_message smallint DEFAULT 0,
    notification_settings_helper smallint DEFAULT 0,
    notification_settings_user_id integer,
    notification_settings_untracked smallint DEFAULT 1,
    notification_settings_parking_slots smallint DEFAULT 0
);


ALTER TABLE public.tsb_notification_settings_sms OWNER TO tsbdbadmin;

--
-- Name: tsb_notification_settings_notification_settings_sms_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_notification_settings_notification_settings_sms_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_notification_settings_notification_settings_sms_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_notification_settings_notification_settings_sms_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_notification_settings_notification_settings_sms_id_seq OWNED BY public.tsb_notification_settings_sms.notification_settings_id;


--
-- Name: tsb_notification_settings_whatsapp; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_notification_settings_whatsapp (
    notification_settings_id integer NOT NULL,
    notification_settings_announcement smallint DEFAULT 0,
    notification_settings_holiday smallint DEFAULT 0,
    notification_settings_pickup_point smallint DEFAULT 0,
    notification_settings_language character varying(20),
    notification_settings_speed_break smallint DEFAULT 0,
    notification_settings_geofence_break smallint DEFAULT 0,
    notification_settings_power_on smallint DEFAULT 0,
    notification_settings_power_off smallint DEFAULT 0,
    notification_settings_battery_low smallint DEFAULT 0,
    notification_settings_simtary_open smallint DEFAULT 0,
    notification_settings_boxcover_open smallint DEFAULT 0,
    notification_settings_boxcover_close smallint DEFAULT 0,
    notification_settings_battery_remove smallint DEFAULT 0,
    notification_settings_seat_belt smallint DEFAULT 0,
    notification_settings_harsh_accelaration smallint DEFAULT 0,
    notification_settings_harsh_brak smallint DEFAULT 0,
    notification_settings_driver_licence smallint DEFAULT 0,
    notification_settings_pushnotification smallint DEFAULT 0,
    notification_settings_subscription smallint DEFAULT 0,
    notification_settings_user smallint DEFAULT 0,
    notification_settings_vehicle_tax smallint DEFAULT 0,
    notification_settings_vehicle_insurance smallint DEFAULT 0,
    notification_settings_vehicle_licence smallint DEFAULT 0,
    notification_settings_vehicle_maintenance smallint DEFAULT 0,
    notification_settings_vehicle_track smallint DEFAULT 0,
    notification_settings_vehicle_trip smallint DEFAULT 0,
    notification_settings_audible smallint DEFAULT 0,
    notification_settings_message smallint DEFAULT 0,
    notification_settings_helper smallint DEFAULT 0,
    notification_settings_user_id integer,
    notification_settings_untracked smallint DEFAULT 1,
    notification_settings_parking_slots smallint DEFAULT 0
);


ALTER TABLE public.tsb_notification_settings_whatsapp OWNER TO tsbdbadmin;

--
-- Name: tsb_notification_settings_notification_settings_whatsapp_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_notification_settings_notification_settings_whatsapp_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_notification_settings_notification_settings_whatsapp_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_notification_settings_notification_settings_whatsapp_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_notification_settings_notification_settings_whatsapp_id_seq OWNED BY public.tsb_notification_settings_whatsapp.notification_settings_id;


--
-- Name: tsb_notification_tm; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_notification_tm (
    notification_tm_id integer NOT NULL,
    notification_tm_name text,
    notification_tm_message text,
    notification_tm_date date
);


ALTER TABLE public.tsb_notification_tm OWNER TO tsbdbadmin;

--
-- Name: tsb_notification_tm_notification_tm_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_notification_tm_notification_tm_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_notification_tm_notification_tm_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_notification_tm_notification_tm_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_notification_tm_notification_tm_id_seq OWNED BY public.tsb_notification_tm.notification_tm_id;


--
-- Name: tsb_parkingslot_suggestions; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_parkingslot_suggestions (
    suggested_slot_id integer NOT NULL,
    suggested_count integer
);


ALTER TABLE public.tsb_parkingslot_suggestions OWNER TO tsbdbadmin;

--
-- Name: tsb_passenger; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_passenger (
    passenger_id integer NOT NULL,
    passenger_name character varying(150),
    passenger_mob bigint
);


ALTER TABLE public.tsb_passenger OWNER TO tsbdbadmin;

--
-- Name: tsb_passenger_passenger_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_passenger_passenger_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_passenger_passenger_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_passenger_passenger_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_passenger_passenger_id_seq OWNED BY public.tsb_passenger.passenger_id;


--
-- Name: tsb_paymant_gateway; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_paymant_gateway (
    paymant_gateway_id integer NOT NULL,
    payfort_gateway_merchant_id character varying,
    payfort_gateway_type character varying,
    payment_gateway_merchant_id character varying,
    payment_gateway_publickey character varying,
    payment_gateway_privatekey character varying,
    payment_gateway_accountid character varying,
    payment_gateway_type character varying
);


ALTER TABLE public.tsb_paymant_gateway OWNER TO tsbdbadmin;

--
-- Name: tsb_payment; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_payment (
    payment_id integer NOT NULL,
    payment_datetime timestamp without time zone,
    payment_type public.payment_type,
    payment_mode public.payment_mode,
    payment_identification_number character varying(200),
    payment_description text,
    payment_date date,
    payment_status public.payment_status DEFAULT 'active'::public.payment_status,
    payment_amount numeric DEFAULT 0.0,
    payment_invoice_no integer
);


ALTER TABLE public.tsb_payment OWNER TO tsbdbadmin;

--
-- Name: tsb_planner_routing; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_planner_routing (
    routing_id integer NOT NULL,
    routing_student_id integer,
    routing_vehicle_id integer,
    routing_route_id integer,
    routing_pickuppoint_name character varying(200),
    routing_pickuppoint_latitude numeric,
    routing_pickuppoint_longitude numeric,
    routing_triptype character varying(50),
    routing_customer_id integer,
    routing_route_name character varying(500),
    routing_pickuppoint_priority integer
);


ALTER TABLE public.tsb_planner_routing OWNER TO tsbdbadmin;

--
-- Name: tsb_planner_routing_routing_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_planner_routing_routing_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_planner_routing_routing_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_planner_routing_routing_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_planner_routing_routing_id_seq OWNED BY public.tsb_planner_routing.routing_id;


--
-- Name: tsb_push_notification; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_push_notification (
    push_notification_id integer NOT NULL,
    push_notification_user_id integer NOT NULL,
    push_notification_message text,
    push_notification_type character varying(10),
    push_notification_date date,
    push_notification_time time without time zone,
    push_notification_status character varying(10),
    push_notification_url character varying(200),
    push_notification_android_link character varying(200),
    push_notification_ios_link character varying(200)
);


ALTER TABLE public.tsb_push_notification OWNER TO tsbdbadmin;

--
-- Name: tsb_push_notification_push_notification_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_push_notification_push_notification_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_push_notification_push_notification_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_push_notification_push_notification_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_push_notification_push_notification_id_seq OWNED BY public.tsb_push_notification.push_notification_id;


--
-- Name: tsb_rash_drive_speed_limit; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_rash_drive_speed_limit (
    speed_limit_id integer NOT NULL,
    speed_limit_vehicle_id integer,
    speed_limit_driver_id integer,
    speed_limit_date date,
    speed_limit_time character varying,
    speed_limit_latitude numeric,
    speed_limit_longitude numeric,
    speed_limit_area integer,
    speed_limt_speed_break integer,
    speed_limit_speed integer
);


ALTER TABLE public.tsb_rash_drive_speed_limit OWNER TO tsbdbadmin;

--
-- Name: tsb_rash_drive_speed_limit_speed_limit_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_rash_drive_speed_limit_speed_limit_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_rash_drive_speed_limit_speed_limit_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_rash_drive_speed_limit_speed_limit_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_rash_drive_speed_limit_speed_limit_id_seq OWNED BY public.tsb_rash_drive_speed_limit.speed_limit_id;


--
-- Name: tsb_reports_access_log; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_reports_access_log (
    reports_access_log_id integer NOT NULL,
    reports_access_log_url character varying,
    reports_access_log_count integer,
    reports_access_log_time character varying
);


ALTER TABLE public.tsb_reports_access_log OWNER TO tsbdbadmin;

--
-- Name: tsb_reports_access_log_reports_access_log_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_reports_access_log_reports_access_log_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_reports_access_log_reports_access_log_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_reports_access_log_reports_access_log_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_reports_access_log_reports_access_log_id_seq OWNED BY public.tsb_reports_access_log.reports_access_log_id;


--
-- Name: tsb_routing; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_routing (
    routing_id integer NOT NULL,
    routing_student_id integer,
    routing_latitude numeric,
    routing_longitude numeric,
    routing_triptype character varying(50),
    routing_method character varying(50),
    routing_pickpoint character varying(100)
);


ALTER TABLE public.tsb_routing OWNER TO tsbdbadmin;

--
-- Name: tsb_routing_routing_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_routing_routing_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_routing_routing_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_routing_routing_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_routing_routing_id_seq OWNED BY public.tsb_routing.routing_id;


--
-- Name: tsb_settings; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_settings (
    settings_customer_id bigint NOT NULL,
    settings_bus_label smallint DEFAULT 1,
    settings_untrack_duration smallint DEFAULT 240,
    settings_online_payment smallint,
    settings_cctv_ip character varying(40),
    settings_cctv_port character varying(40),
    settings_cctv_username character varying(40),
    settings_cctv_password character varying(40),
    settings_cctv_sdk character varying(40),
    settings_cctv_apache_port smallint DEFAULT 80,
    settings_busassistant_role smallint DEFAULT 1,
    settings_historical_data smallint DEFAULT 1,
    settings_vehicle_expense smallint DEFAULT 1,
    settings_duration_allowed_totrip_start smallint DEFAULT 45,
    settings_halt_duration smallint DEFAULT 30,
    settings_trip_card integer DEFAULT 1,
    settings_employee_attendance smallint DEFAULT 0,
    settings_fleetmanager_role smallint DEFAULT 0,
    settings_parked_temperature smallint DEFAULT 50,
    settings_running_temperature smallint DEFAULT 25,
    settings_acceleration numeric,
    settings_deacceleration numeric,
    settings_payment_gateway character varying,
    settings_sms_gateway_status smallint DEFAULT 0,
    settings_sms_gateway_id integer,
    settings_sms_gateway_username character varying(100),
    settings_sms_gateway_password character varying(200),
    settings_sms_gateway_sender_id character varying(100),
    settings_intercom_support smallint DEFAULT 0,
    settings_intercom_app_id character varying(25),
    settings_intercom_app_key character varying(100),
    settings_cashless smallint DEFAULT 0,
    settings_maximum_balance_limit integer DEFAULT 1000,
    settings_minimum_balance_limit integer DEFAULT 50,
    settings_max_transactions integer DEFAULT 0,
    settings_max_spend integer DEFAULT 0,
    settings_odoo_domain character varying(100),
    settings_odoo_username character varying(40),
    settings_odoo_password character varying(200),
    settings_odoo_apikey character varying(100),
    settings_odoo_status smallint DEFAULT 0,
    settings_vehicle_parking_time time without time zone DEFAULT '02:00:00'::time without time zone,
    settings_parkingslot_minimum_vehiclecount smallint DEFAULT '4'::smallint,
    settings_parkingslot_anomalycount smallint DEFAULT '3'::smallint,
    settings_parkingslot_maximum_radius integer,
    settings_data_collection smallint DEFAULT '0'::smallint,
    settings_data_update smallint DEFAULT '0'::smallint,
    settings_data_optimise smallint DEFAULT '0'::smallint,
    settings_allowed_idle_time integer DEFAULT 3,
    settings_running_vehicle_timeout integer DEFAULT 5,
    settings_vehicle_expiry_duration integer DEFAULT 12,
    settings_address_visibility smallint DEFAULT '0'::smallint,
    settings_dashboard_map smallint DEFAULT 0
);


ALTER TABLE public.tsb_settings OWNER TO tsbdbadmin;

--
-- Name: tsb_shift; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_shift (
    shift_name character varying(40),
    shift_start_time time without time zone,
    shift_end_time time without time zone,
    shift_status character varying(40) DEFAULT 'active'::character varying,
    shift_id integer NOT NULL
);


ALTER TABLE public.tsb_shift OWNER TO tsbdbadmin;

--
-- Name: tsb_shift_shift_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_shift_shift_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_shift_shift_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_shift_shift_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_shift_shift_id_seq OWNED BY public.tsb_shift.shift_id;


--
-- Name: tsb_sms_gateway; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_sms_gateway (
    sms_gateway_id bigint NOT NULL,
    sms_gateway_name character varying(150),
    sms_gateway_url character varying(150),
    sms_gateway_request_format text,
    sms_gateway_signup_url character varying(200),
    sms_gateway_recharge_url character varying(200)
);


ALTER TABLE public.tsb_sms_gateway OWNER TO tsbdbadmin;

--
-- Name: tsb_snap; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_snap (
    snap_id integer NOT NULL,
    snap_imei character varying(40) NOT NULL,
    snap_key character varying(8) NOT NULL,
    snap_date date NOT NULL,
    snap_time time without time zone NOT NULL,
    snap_size integer,
    snap_progress integer,
    snap_trip_id integer,
    snap_status character varying(10) DEFAULT 'pending'::character varying
);


ALTER TABLE public.tsb_snap OWNER TO tsbdbadmin;

--
-- Name: tsb_snap_log; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_snap_log (
    snap_log_id integer NOT NULL,
    snap_log_vehicle_id integer,
    snap_log_user_id integer,
    snap_log_device_type character varying(20),
    snap_log_date date,
    snap_log_time time without time zone,
    snap_log_trip_id integer
);


ALTER TABLE public.tsb_snap_log OWNER TO tsbdbadmin;

--
-- Name: tsb_snap_log_snap_log_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_snap_log_snap_log_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_snap_log_snap_log_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_snap_log_snap_log_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_snap_log_snap_log_id_seq OWNED BY public.tsb_snap_log.snap_log_id;


--
-- Name: tsb_snap_snap_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_snap_snap_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_snap_snap_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_snap_snap_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_snap_snap_id_seq OWNED BY public.tsb_snap.snap_id;


--
-- Name: tsb_team; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_team (
    team_id integer NOT NULL,
    team_name character varying(40),
    team_status character varying(40) DEFAULT 'active'::character varying
);


ALTER TABLE public.tsb_team OWNER TO tsbdbadmin;

--
-- Name: tsb_team_team_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_team_team_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_team_team_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_team_team_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_team_team_id_seq OWNED BY public.tsb_team.team_id;


--
-- Name: tsb_temp_autorouting; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_temp_autorouting (
    temp_routing_id integer NOT NULL,
    temp_shift_id numeric,
    temp_vehicle_id numeric,
    temp_route_id numeric,
    temp_pickuppoint_latitude numeric,
    temp_pickuppoint_longitude numeric,
    temp_student_id numeric,
    temp_triptype character varying(10),
    temp_pickuppoint_name character varying,
    temp_routing_type character varying
);


ALTER TABLE public.tsb_temp_autorouting OWNER TO tsbdbadmin;

--
-- Name: tsb_temp_autorouting_temp_routing_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_temp_autorouting_temp_routing_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_temp_autorouting_temp_routing_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_temp_autorouting_temp_routing_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_temp_autorouting_temp_routing_id_seq OWNED BY public.tsb_temp_autorouting.temp_routing_id;


--
-- Name: tsb_temp_route; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_temp_route (
    temp_route_id integer NOT NULL,
    temp_route_distance numeric,
    temp_route_duration numeric
);


ALTER TABLE public.tsb_temp_route OWNER TO tsbdbadmin;

--
-- Name: tsb_trip; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_trip (
    trip_id integer NOT NULL,
    trip_vehicle_id integer NOT NULL,
    trip_route_id integer,
    trip_type character varying(20),
    trip_shift integer,
    trip_status character varying(40) DEFAULT 'active'::character varying,
    trip_time integer,
    trip_start_time time without time zone,
    trip_running_days character varying(40) DEFAULT 'working days'::character varying,
    trip_driver_id integer,
    trip_helper_id integer,
    trip_card_id character varying(50),
    trip_end_time time without time zone,
    trip_category character varying,
    trip_green_card character varying(20),
    trip_end_point character varying,
    trip_start_latitude numeric,
    trip_start_longitude numeric,
    trip_end_latitude numeric,
    trip_route_area character varying,
    trip_team_id bigint,
    trip_date date,
    trip_repeat smallint,
    trip_start_point character varying,
    trip_name character varying,
    trip_end_date date,
    trip_end_longitude numeric
);


ALTER TABLE public.tsb_trip OWNER TO tsbdbadmin;

--
-- Name: tsb_trip_days; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_trip_days (
    trip_days_id bigint NOT NULL,
    trip_days_sun smallint,
    trip_days_mon smallint,
    trip_days_tue smallint,
    trip_days_wed smallint,
    trip_days_thu smallint,
    trip_days_fri smallint,
    trip_days_sat smallint
);


ALTER TABLE public.tsb_trip_days OWNER TO tsbdbadmin;

--
-- Name: tsb_trip_geofence; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_trip_geofence (
    geofence_id integer NOT NULL,
    geofence_draw_point character varying(200),
    geofence_details character varying(15),
    geofence_draw_type character varying(15),
    geofence_trip_id integer
);


ALTER TABLE public.tsb_trip_geofence OWNER TO tsbdbadmin;

--
-- Name: tsb_trip_geofence_geofence_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_trip_geofence_geofence_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_trip_geofence_geofence_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_trip_geofence_geofence_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_trip_geofence_geofence_id_seq OWNED BY public.tsb_trip_geofence.geofence_id;


--
-- Name: tsb_trip_repeatdays; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_trip_repeatdays (
    trip_repeat_id integer NOT NULL,
    trip_repeat_trip_id integer,
    trip_repeat_day character varying,
    trip_repeat_start_time time without time zone,
    trip_repeat_end_time time without time zone,
    trip_repeat_status character varying
);


ALTER TABLE public.tsb_trip_repeatdays OWNER TO tsbdbadmin;

--
-- Name: tsb_trip_repeatdays_trip_repeat_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_trip_repeatdays_trip_repeat_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_trip_repeatdays_trip_repeat_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_trip_repeatdays_trip_repeat_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_trip_repeatdays_trip_repeat_id_seq OWNED BY public.tsb_trip_repeatdays.trip_repeat_id;


--
-- Name: tsb_user; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_user (
    user_id integer NOT NULL,
    user_customer_id bigint,
    user_name character varying(40),
    user_email character varying(150),
    user_mobile character varying(40),
    user_role character varying(40) DEFAULT 'transport-manager'::character varying,
    user_status character varying DEFAULT 'active'::character varying,
    user_last_name character varying(40),
    user_dob date,
    user_gender character(1),
    user_address character varying(500),
    user_city character varying(40),
    user_profile_pic character varying(350),
    user_internal_no character varying(40),
    user_joining_date date DEFAULT now(),
    user_nationality character varying(40),
    user_email_verification character varying(50) DEFAULT 'no'::character varying,
    user_last_access timestamp without time zone,
    user_access_mode character varying(15),
    user_last_login timestamp without time zone,
    user_last_login_mode character varying(15)
);


ALTER TABLE public.tsb_user OWNER TO tsbdbadmin;

--
-- Name: tsb_user_apps; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_user_apps (
    user_apps_id integer NOT NULL,
    user_apps_user_id integer,
    user_apps_device_token character varying(250),
    user_apps_device_id character varying(50),
    user_apps_device_os character varying(10),
    user_apps_type character varying(20),
    user_apps_key character varying(150) DEFAULT md5((random())::text),
    user_apps_version character varying(20) DEFAULT '0.0'::character varying
);


ALTER TABLE public.tsb_user_apps OWNER TO tsbdbadmin;

--
-- Name: tsb_user_card; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_user_card (
    card_id integer NOT NULL,
    card_user_id integer,
    card_user_mifarecard_id character varying
);


ALTER TABLE public.tsb_user_card OWNER TO tsbdbadmin;

--
-- Name: tsb_user_card_card_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_user_card_card_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_user_card_card_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_user_card_card_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_user_card_card_id_seq OWNED BY public.tsb_user_card.card_id;


--
-- Name: tsb_vacation; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_vacation (
    vacation_id integer NOT NULL,
    vacation_name character varying(50),
    vacation_start_date date,
    vacation_end_date date,
    vacation_desc character varying(200) NOT NULL,
    vacation_status character varying(10) DEFAULT 'active'::character varying
);


ALTER TABLE public.tsb_vacation OWNER TO tsbdbadmin;

--
-- Name: tsb_vacation_vacation_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_vacation_vacation_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_vacation_vacation_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_vacation_vacation_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_vacation_vacation_id_seq OWNED BY public.tsb_vacation.vacation_id;


--
-- Name: tsb_vehicle; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_vehicle (
    vehicle_id integer NOT NULL,
    vehicle_imei character varying(20),
    vehicle_type integer,
    vehicle_number character varying(200),
    vehicle_reg_no character varying(40),
    vehicle_chaise_no character varying(40),
    vehicle_engine_no character varying(40),
    vehicle_model_no character varying(40),
    vehicle_model_make character varying(40),
    vehicle_seat_capacity integer,
    vehicle_tax_start_date date,
    vehicle_mode character varying(20),
    vehicle_fuel_type character varying(30),
    vehicle_insurance_start_date date,
    vehicle_insurance_end_date date,
    vehicle_permit_start_date date,
    vehicle_permit_end_date date,
    vehicle_tax_end_date date,
    vehicle_status character varying(40) DEFAULT 'active'::character varying NOT NULL,
    vehicle_device_type integer,
    vehicle_simcard_no character varying(40),
    vehicle_sim_telephone_no character varying(40),
    vehicle_odometer character varying(50),
    vehicle_next_inspection_date date,
    vehicle_manager_id integer,
    vehicle_driver_id integer,
    vehicle_order_type character varying,
    vehicle_expiry_date character varying,
    vehicle_created_at date DEFAULT now(),
    vehicle_group character varying
);


ALTER TABLE public.tsb_vehicle OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_accessory; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_vehicle_accessory (
    accessory_id integer NOT NULL,
    accessory_item character varying(50),
    accessory_quantity bigint,
    accessory_price numeric,
    accessory_purchase_from character varying(50),
    accessory_invoice_no character varying(200),
    accessory_purchase_date date,
    accessory_vehicle_id integer
);


ALTER TABLE public.tsb_vehicle_accessory OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_vehicle_activity (
    vehicle_activity_id integer NOT NULL,
    vehicle_activity_vehicle_id integer,
    vehicle_activity_driver_id integer,
    vehicle_activity_date date,
    vehicle_activity_status character varying(10),
    vehicle_activity_start_time time without time zone,
    vehicle_activity_start_latitude numeric,
    vehicle_activity_start_latitude_direction character(1),
    vehicle_activity_start_longitude numeric,
    vehicle_activity_start_longitude_direction character(1),
    vehicle_activity_end_time time without time zone,
    vehicle_activity_end_latitude numeric,
    vehicle_activity_end_latitude_direction character(1),
    vehicle_activity_end_longitude numeric,
    vehicle_activity_end_longitude_direction character(1),
    vehicle_activity_duration character varying(50),
    vehicle_activity_distance numeric,
    vehicle_activity_coordinates text,
    vehicle_activity_avgspeed numeric,
    vehicle_activity_maxspeed numeric,
    vehicle_activity_calculator character varying,
    vehicle_activity_calculator_list_id integer,
    vehicle_activity_start_mileage numeric,
    vehicle_activity_end_mileage numeric,
    vehicle_activity_daily_mileage numeric
);


ALTER TABLE public.tsb_vehicle_activity OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_vehicle_activity_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_vehicle_activity_vehicle_activity_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_vehicle_activity_vehicle_activity_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_vehicle_activity_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_vehicle_activity_vehicle_activity_id_seq OWNED BY public.tsb_vehicle_activity.vehicle_activity_id;


--
-- Name: tsb_vehicle_assignment; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_vehicle_assignment (
    vehicle_assignment_id integer NOT NULL,
    vehicle_assignment_driver_id integer,
    vehicle_assignment_helper_id integer,
    vehicle_assignment_date date,
    vehicle_assignment_vehicle_id integer,
    vehicle_assignment_status character varying(10) DEFAULT 'active'::character varying,
    vehicle_assignment_trip_id integer
);


ALTER TABLE public.tsb_vehicle_assignment OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_assignment_history; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_vehicle_assignment_history (
    vehicle_history_id bigint NOT NULL,
    vehicle_history_driver_id integer,
    vehicle_history_helper_id integer,
    vehicle_history_vehicle_id integer,
    vehicle_history_assignment_date date,
    vehicle_history_end_date date,
    vehicle_history_status character varying(10) DEFAULT 'active'::character varying,
    vehicle_history_trip_id integer,
    vehicle_history_trip_type character varying(20)
);


ALTER TABLE public.tsb_vehicle_assignment_history OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_calculator_assign; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_vehicle_calculator_assign (
    vehicle_calculator_assign_id integer NOT NULL,
    vehicle_calculator_assign_calculator_id integer NOT NULL,
    vehicle_calculator_assign_vehicle_id integer NOT NULL,
    vehicle_calculator_assign_status character varying,
    vehicle_calculator_assign_date date
);


ALTER TABLE public.tsb_vehicle_calculator_assign OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_calculator_assign_vehicle_calculator_assign_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_vehicle_calculator_assign_vehicle_calculator_assign_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_vehicle_calculator_assign_vehicle_calculator_assign_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_calculator_assign_vehicle_calculator_assign_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_vehicle_calculator_assign_vehicle_calculator_assign_id_seq OWNED BY public.tsb_vehicle_calculator_assign.vehicle_calculator_assign_id;


--
-- Name: tsb_vehicle_data_syncrequest; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_vehicle_data_syncrequest (
    syncrequest_id integer NOT NULL,
    syncrequest_vehicle_id integer,
    syncrequest_requested_datetime timestamp without time zone,
    syncrequest_sync_datetime character varying,
    syncrequest_sync_period text,
    syncrequest_sync_status character varying
);


ALTER TABLE public.tsb_vehicle_data_syncrequest OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_data_syncrequest_syncrequest_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_vehicle_data_syncrequest_syncrequest_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_vehicle_data_syncrequest_syncrequest_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_data_syncrequest_syncrequest_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_vehicle_data_syncrequest_syncrequest_id_seq OWNED BY public.tsb_vehicle_data_syncrequest.syncrequest_id;


--
-- Name: tsb_vehicle_data_usage; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_vehicle_data_usage (
    data_usage_id integer NOT NULL,
    data_usage_date character varying,
    data_usage_size integer,
    data_usage_vehicle_id integer
);


ALTER TABLE public.tsb_vehicle_data_usage OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_data_usage_data_usage_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_vehicle_data_usage_data_usage_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_vehicle_data_usage_data_usage_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_data_usage_data_usage_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_vehicle_data_usage_data_usage_id_seq OWNED BY public.tsb_vehicle_data_usage.data_usage_id;


--
-- Name: tsb_vehicle_fine; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_vehicle_fine (
    fine_id integer NOT NULL,
    fine_reason character varying(50),
    fine_date date,
    fine_status character varying(10),
    fine_vehicle_id integer,
    fine_amount numeric,
    fine_invoice_no character varying(200)
);


ALTER TABLE public.tsb_vehicle_fine OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_user_assign; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_vehicle_user_assign (
    vehicle_user_assign_id integer NOT NULL,
    vehicle_user_assign_user_id integer NOT NULL,
    vehicle_user_assign_vehicle_id integer NOT NULL,
    vehicle_user_assign_status character varying,
    vehicle_user_assign_date date
);


ALTER TABLE public.tsb_vehicle_user_assign OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_fleet_manager_ass_vehicle_user_assign__seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_vehicle_fleet_manager_ass_vehicle_user_assign__seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_vehicle_fleet_manager_ass_vehicle_user_assign__seq OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_fleet_manager_ass_vehicle_user_assign__seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_vehicle_fleet_manager_ass_vehicle_user_assign__seq OWNED BY public.tsb_vehicle_user_assign.vehicle_user_assign_id;


--
-- Name: tsb_vehicle_fuel; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_vehicle_fuel (
    vehicle_fuel_id integer NOT NULL,
    vehicle_fuel_current_odometer character varying(50),
    vehicle_fuel_quantity character varying(50),
    vehicle_fuel_amount numeric,
    vehicle_fuel_date date,
    vehicle_fuel_vehicle_id integer,
    fuel_invoice_no character varying(200)
);


ALTER TABLE public.tsb_vehicle_fuel OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_fuel_vehicle_fuel_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_vehicle_fuel_vehicle_fuel_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_vehicle_fuel_vehicle_fuel_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_fuel_vehicle_fuel_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_vehicle_fuel_vehicle_fuel_id_seq OWNED BY public.tsb_vehicle_fuel.vehicle_fuel_id;


--
-- Name: tsb_vehicle_geofence; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_vehicle_geofence (
    geofence_id integer NOT NULL,
    geofence_draw_point character varying(200),
    geofence_details character varying(15),
    geofence_draw_type character varying(15),
    geofence_vehicle_id integer
);


ALTER TABLE public.tsb_vehicle_geofence OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_geofence_geofence_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_vehicle_geofence_geofence_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_vehicle_geofence_geofence_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_geofence_geofence_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_vehicle_geofence_geofence_id_seq OWNED BY public.tsb_vehicle_geofence.geofence_id;


--
-- Name: tsb_vehicle_group; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_vehicle_group (
    vehicle_group_id integer NOT NULL,
    vehicle_group_name character varying
);


ALTER TABLE public.tsb_vehicle_group OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_group_vehicle; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_vehicle_group_vehicle (
    group_vehicle_id integer NOT NULL,
    group_vehicle_group_id integer,
    group_vehicle_vehicle_id character varying,
    group_vehicle_update_status character varying
);


ALTER TABLE public.tsb_vehicle_group_vehicle OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_group_vehicle_group_vehicle_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_vehicle_group_vehicle_group_vehicle_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_vehicle_group_vehicle_group_vehicle_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_group_vehicle_group_vehicle_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_vehicle_group_vehicle_group_vehicle_id_seq OWNED BY public.tsb_vehicle_group_vehicle.group_vehicle_id;


--
-- Name: tsb_vehicle_ignition_data; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_vehicle_ignition_data (
    ignition_id integer NOT NULL,
    ignition_vehicle_id integer,
    ignition_driver_id integer,
    ignition_received_date date,
    ignition_first_received_time time without time zone,
    ignition_last_received_time time without time zone,
    ignition_available_time integer
);


ALTER TABLE public.tsb_vehicle_ignition_data OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_incident; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_vehicle_incident (
    incident_id integer NOT NULL,
    incident_location character varying(50),
    incident_description character varying(60),
    incident_date date,
    incident_route_id integer,
    incident_vehicle_id integer,
    incident_expense numeric,
    incident_invoice_no character varying(200),
    incident_driver_id integer
);


ALTER TABLE public.tsb_vehicle_incident OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_parking; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_vehicle_parking (
    parking_id integer NOT NULL,
    parking_vehicle_id integer,
    checkin_time time without time zone,
    checkin_date date,
    checkout_time time without time zone,
    checkout_date date,
    latitude numeric,
    latitude_direction character(1),
    longitude numeric,
    longitude_direction character(1),
    parking_slot_id integer
);


ALTER TABLE public.tsb_vehicle_parking OWNER TO tsbdbadmin;

--
-- Name: TABLE tsb_vehicle_parking; Type: COMMENT; Schema: public; Owner: tsbdbadmin
--

COMMENT ON TABLE public.tsb_vehicle_parking IS 'Table to store  day wise parking slots of vehicles';


--
-- Name: tsb_vehicle_parking_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_vehicle_parking_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_vehicle_parking_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_parking_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_vehicle_parking_seq OWNED BY public.tsb_vehicle_parking.parking_id;


--
-- Name: tsb_vehicle_readers; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_vehicle_readers (
    vehicle_readers_vehicle_id integer,
    vehicle_readers_reader_id character varying(40),
    vehicle_readers_reader_id2 character varying(40)
);


ALTER TABLE public.tsb_vehicle_readers OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_run_summary; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_vehicle_run_summary (
    vehicle_run_summary_id integer NOT NULL,
    vehicle_run_summary_vehicle_id integer,
    vehicle_run_summary_distance numeric,
    vehicle_run_summary_duty_time character varying,
    vehicle_run_summary_avg_speed numeric,
    vehicle_run_summary_max_speed numeric,
    vehicle_run_summary_run_time character varying,
    vehicle_run_summary_idle_time character varying,
    vehicle_run_summary_date character varying
);


ALTER TABLE public.tsb_vehicle_run_summary OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_run_summary_vehicle_run_summary_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.tsb_vehicle_run_summary_vehicle_run_summary_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tsb_vehicle_run_summary_vehicle_run_summary_id_seq OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_run_summary_vehicle_run_summary_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.tsb_vehicle_run_summary_vehicle_run_summary_id_seq OWNED BY public.tsb_vehicle_run_summary.vehicle_run_summary_id;


--
-- Name: tsb_vehicle_spareparts; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_vehicle_spareparts (
    spareparts_id integer NOT NULL,
    spareparts_vehicle_id integer,
    spareparts_name character varying(40),
    spareparts_warranty character varying(20),
    spareparts_expiry_date date,
    spareparts_quantity bigint,
    spareparts_amount numeric,
    spareparts_purchase_date date,
    spareparts_invoice_no character varying(100)
);


ALTER TABLE public.tsb_vehicle_spareparts OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_type; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_vehicle_type (
    vehicle_type_id integer NOT NULL,
    vehicle_type_code character varying(20),
    vehicle_type_description character varying(40),
    vehicle_type_status character varying(10) DEFAULT 'active'::character varying
);


ALTER TABLE public.tsb_vehicle_type OWNER TO tsbdbadmin;

--
-- Name: tsb_webservice_log; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_webservice_log (
    webservice_log_id integer NOT NULL,
    webservice_log_method_name character varying(250),
    webservice_log_input_parameters text,
    webservice_log_request_status text,
    webservice_log_request_date timestamp without time zone,
    webservice_log_user_id integer
);


ALTER TABLE public.tsb_webservice_log OWNER TO tsbdbadmin;

--
-- Name: usage_statistics; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.usage_statistics (
    statistics_id integer NOT NULL,
    statistics_customer_id integer,
    statistics_date date,
    statistics_email character varying(500),
    statistics_google_directions integer DEFAULT 0,
    statistics_google_distance_matrix integer DEFAULT 0,
    statistics_google_geocoding integer DEFAULT 0,
    statistics_google_maps_elevation integer DEFAULT 0,
    statistics_google_maps_embed integer DEFAULT 0,
    statistics_google_maps_javascript integer DEFAULT 0,
    statistics_google_maps_sdk_android integer DEFAULT 0,
    statistics_google_maps_sdk_ios integer DEFAULT 0,
    statistics_google_maps_static integer DEFAULT 0,
    statistics_google_place integer DEFAULT 0,
    statistics_google_roads integer DEFAULT 0,
    statistics_google_street_view_static integer DEFAULT 0,
    statistics_google_timezone integer DEFAULT 0
);


ALTER TABLE public.usage_statistics OWNER TO tsbdbadmin;

--
-- Name: usage_statistics_statistics_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.usage_statistics_statistics_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.usage_statistics_statistics_id_seq OWNER TO tsbdbadmin;

--
-- Name: usage_statistics_statistics_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.usage_statistics_statistics_id_seq OWNED BY public.usage_statistics.statistics_id;


--
-- Name: user_apps_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.user_apps_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.user_apps_id_seq OWNER TO tsbdbadmin;

--
-- Name: user_apps_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.user_apps_id_seq OWNED BY public.tsb_user_apps.user_apps_id;


--
-- Name: user_attendance_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.user_attendance_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.user_attendance_id_seq OWNER TO tsbdbadmin;

--
-- Name: user_attendance_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.user_attendance_id_seq OWNED BY public.tsb_attendance_user.attendance_id;


--
-- Name: user_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.user_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.user_id_seq OWNER TO tsbdbadmin;

--
-- Name: user_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.user_id_seq OWNED BY public.tsb_user.user_id;


--
-- Name: vehicle_accessory_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.vehicle_accessory_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.vehicle_accessory_id_seq OWNER TO tsbdbadmin;

--
-- Name: vehicle_accessory_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.vehicle_accessory_id_seq OWNED BY public.tsb_vehicle_accessory.accessory_id;


--
-- Name: vehicle_assignment_history_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.vehicle_assignment_history_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.vehicle_assignment_history_id_seq OWNER TO tsbdbadmin;

--
-- Name: vehicle_assignment_history_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.vehicle_assignment_history_id_seq OWNED BY public.tsb_vehicle_assignment_history.vehicle_history_id;


--
-- Name: vehicle_assignment_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.vehicle_assignment_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.vehicle_assignment_id_seq OWNER TO tsbdbadmin;

--
-- Name: vehicle_assignment_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.vehicle_assignment_id_seq OWNED BY public.tsb_vehicle_assignment.vehicle_assignment_id;


--
-- Name: vehicle_fine_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.vehicle_fine_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.vehicle_fine_id_seq OWNER TO tsbdbadmin;

--
-- Name: vehicle_fine_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.vehicle_fine_id_seq OWNED BY public.tsb_vehicle_fine.fine_id;


--
-- Name: vehicle_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.vehicle_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.vehicle_id_seq OWNER TO tsbdbadmin;

--
-- Name: vehicle_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.vehicle_id_seq OWNED BY public.tsb_vehicle.vehicle_id;


--
-- Name: vehicle_ignition_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.vehicle_ignition_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.vehicle_ignition_id_seq OWNER TO tsbdbadmin;

--
-- Name: vehicle_ignition_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.vehicle_ignition_id_seq OWNED BY public.tsb_vehicle_ignition_data.ignition_id;


--
-- Name: vehicle_incident_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.vehicle_incident_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.vehicle_incident_id_seq OWNER TO tsbdbadmin;

--
-- Name: vehicle_incident_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.vehicle_incident_id_seq OWNED BY public.tsb_vehicle_incident.incident_id;


--
-- Name: vehicle_information_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.vehicle_information_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.vehicle_information_id_seq OWNER TO tsbdbadmin;

--
-- Name: vehicle_information_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.vehicle_information_id_seq OWNED BY public.gnx_vehicle.gnx_vehicle_id;


--
-- Name: vehicle_route_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.vehicle_route_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.vehicle_route_id_seq OWNER TO tsbdbadmin;

--
-- Name: vehicle_route_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.vehicle_route_id_seq OWNED BY public.tsb_trip.trip_id;


--
-- Name: vehicle_spareparts_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.vehicle_spareparts_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.vehicle_spareparts_id_seq OWNER TO tsbdbadmin;

--
-- Name: vehicle_spareparts_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.vehicle_spareparts_id_seq OWNED BY public.tsb_vehicle_spareparts.spareparts_id;


--
-- Name: vehicle_type_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.vehicle_type_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.vehicle_type_id_seq OWNER TO tsbdbadmin;

--
-- Name: vehicle_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.vehicle_type_id_seq OWNED BY public.tsb_vehicle_type.vehicle_type_id;


--
-- Name: webservice_log_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

CREATE SEQUENCE public.webservice_log_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.webservice_log_id_seq OWNER TO tsbdbadmin;

--
-- Name: webservice_log_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: tsbdbadmin
--

ALTER SEQUENCE public.webservice_log_id_seq OWNED BY public.tsb_webservice_log.webservice_log_id;


--
-- Name: gnx_alert_2022_07_04; Type: TABLE; Schema: tp_gnx_alert; Owner: tsbdbadmin
--

CREATE TABLE tp_gnx_alert.gnx_alert_2022_07_04 (
    CONSTRAINT gnx_alert_2022_07_04_logged_date_check CHECK ((logged_date = '2022-07-04'::date))
)
INHERITS (public.gnx_alert);


ALTER TABLE tp_gnx_alert.gnx_alert_2022_07_04 OWNER TO tsbdbadmin;

--
-- Name: gnx_alert_2022_07_05; Type: TABLE; Schema: tp_gnx_alert; Owner: tsbdbadmin
--

CREATE TABLE tp_gnx_alert.gnx_alert_2022_07_05 (
    CONSTRAINT gnx_alert_2022_07_05_logged_date_check CHECK ((logged_date = '2022-07-05'::date))
)
INHERITS (public.gnx_alert);


ALTER TABLE tp_gnx_alert.gnx_alert_2022_07_05 OWNER TO tsbdbadmin;

--
-- Name: gnx_alert_2022_07_06; Type: TABLE; Schema: tp_gnx_alert; Owner: tsbdbadmin
--

CREATE TABLE tp_gnx_alert.gnx_alert_2022_07_06 (
    CONSTRAINT gnx_alert_2022_07_06_logged_date_check CHECK ((logged_date = '2022-07-06'::date))
)
INHERITS (public.gnx_alert);


ALTER TABLE tp_gnx_alert.gnx_alert_2022_07_06 OWNER TO tsbdbadmin;

--
-- Name: gnx_alert_2022_07_11; Type: TABLE; Schema: tp_gnx_alert; Owner: tsbdbadmin
--

CREATE TABLE tp_gnx_alert.gnx_alert_2022_07_11 (
    CONSTRAINT gnx_alert_2022_07_11_logged_date_check CHECK ((logged_date = '2022-07-11'::date))
)
INHERITS (public.gnx_alert);


ALTER TABLE tp_gnx_alert.gnx_alert_2022_07_11 OWNER TO tsbdbadmin;

--
-- Name: gnx_alert_2022_07_12; Type: TABLE; Schema: tp_gnx_alert; Owner: tsbdbadmin
--

CREATE TABLE tp_gnx_alert.gnx_alert_2022_07_12 (
    CONSTRAINT gnx_alert_2022_07_12_logged_date_check CHECK ((logged_date = '2022-07-12'::date))
)
INHERITS (public.gnx_alert);


ALTER TABLE tp_gnx_alert.gnx_alert_2022_07_12 OWNER TO tsbdbadmin;

--
-- Name: gnx_alert_2022_07_13; Type: TABLE; Schema: tp_gnx_alert; Owner: tsbdbadmin
--

CREATE TABLE tp_gnx_alert.gnx_alert_2022_07_13 (
    CONSTRAINT gnx_alert_2022_07_13_logged_date_check CHECK ((logged_date = '2022-07-13'::date))
)
INHERITS (public.gnx_alert);


ALTER TABLE tp_gnx_alert.gnx_alert_2022_07_13 OWNER TO tsbdbadmin;

--
-- Name: gnx_alert_2022_07_19; Type: TABLE; Schema: tp_gnx_alert; Owner: tsbdbadmin
--

CREATE TABLE tp_gnx_alert.gnx_alert_2022_07_19 (
    CONSTRAINT gnx_alert_2022_07_19_logged_date_check CHECK ((logged_date = '2022-07-19'::date))
)
INHERITS (public.gnx_alert);


ALTER TABLE tp_gnx_alert.gnx_alert_2022_07_19 OWNER TO tsbdbadmin;

--
-- Name: gnx_alert_2022_07_21; Type: TABLE; Schema: tp_gnx_alert; Owner: tsbdbadmin
--

CREATE TABLE tp_gnx_alert.gnx_alert_2022_07_21 (
    CONSTRAINT gnx_alert_2022_07_21_logged_date_check CHECK ((logged_date = '2022-07-21'::date))
)
INHERITS (public.gnx_alert);


ALTER TABLE tp_gnx_alert.gnx_alert_2022_07_21 OWNER TO tsbdbadmin;

--
-- Name: gnx_alert_2022_07_26; Type: TABLE; Schema: tp_gnx_alert; Owner: tsbdbadmin
--

CREATE TABLE tp_gnx_alert.gnx_alert_2022_07_26 (
    CONSTRAINT gnx_alert_2022_07_26_logged_date_check CHECK ((logged_date = '2022-07-26'::date))
)
INHERITS (public.gnx_alert);


ALTER TABLE tp_gnx_alert.gnx_alert_2022_07_26 OWNER TO tsbdbadmin;

--
-- Name: gnx_alert_2022_08_02; Type: TABLE; Schema: tp_gnx_alert; Owner: tsbdbadmin
--

CREATE TABLE tp_gnx_alert.gnx_alert_2022_08_02 (
    CONSTRAINT gnx_alert_2022_08_02_logged_date_check CHECK ((logged_date = '2022-08-02'::date))
)
INHERITS (public.gnx_alert);


ALTER TABLE tp_gnx_alert.gnx_alert_2022_08_02 OWNER TO tsbdbadmin;

--
-- Name: gnx_alert_2022_08_03; Type: TABLE; Schema: tp_gnx_alert; Owner: tsbdbadmin
--

CREATE TABLE tp_gnx_alert.gnx_alert_2022_08_03 (
    CONSTRAINT gnx_alert_2022_08_03_logged_date_check CHECK ((logged_date = '2022-08-03'::date))
)
INHERITS (public.gnx_alert);


ALTER TABLE tp_gnx_alert.gnx_alert_2022_08_03 OWNER TO tsbdbadmin;

--
-- Name: gnx_alert_2022_09_13; Type: TABLE; Schema: tp_gnx_alert; Owner: tsbdbadmin
--

CREATE TABLE tp_gnx_alert.gnx_alert_2022_09_13 (
    CONSTRAINT gnx_alert_2022_09_13_logged_date_check CHECK ((logged_date = '2022-09-13'::date))
)
INHERITS (public.gnx_alert);


ALTER TABLE tp_gnx_alert.gnx_alert_2022_09_13 OWNER TO tsbdbadmin;

--
-- Name: gnx_alert_2023_02_06; Type: TABLE; Schema: tp_gnx_alert; Owner: tsbdbadmin
--

CREATE TABLE tp_gnx_alert.gnx_alert_2023_02_06 (
    CONSTRAINT gnx_alert_2023_02_06_logged_date_check CHECK ((logged_date = '2023-02-06'::date))
)
INHERITS (public.gnx_alert);


ALTER TABLE tp_gnx_alert.gnx_alert_2023_02_06 OWNER TO tsbdbadmin;

--
-- Name: gnx_alert_2023_02_07; Type: TABLE; Schema: tp_gnx_alert; Owner: tsbdbadmin
--

CREATE TABLE tp_gnx_alert.gnx_alert_2023_02_07 (
    CONSTRAINT gnx_alert_2023_02_07_logged_date_check CHECK ((logged_date = '2023-02-07'::date))
)
INHERITS (public.gnx_alert);


ALTER TABLE tp_gnx_alert.gnx_alert_2023_02_07 OWNER TO tsbdbadmin;

--
-- Name: gnx_alert_2023_02_10; Type: TABLE; Schema: tp_gnx_alert; Owner: tsbdbadmin
--

CREATE TABLE tp_gnx_alert.gnx_alert_2023_02_10 (
    CONSTRAINT gnx_alert_2023_02_10_logged_date_check CHECK ((logged_date = '2023-02-10'::date))
)
INHERITS (public.gnx_alert);


ALTER TABLE tp_gnx_alert.gnx_alert_2023_02_10 OWNER TO tsbdbadmin;

--
-- Name: gnx_alert_2023_02_11; Type: TABLE; Schema: tp_gnx_alert; Owner: tsbdbadmin
--

CREATE TABLE tp_gnx_alert.gnx_alert_2023_02_11 (
    CONSTRAINT gnx_alert_2023_02_11_logged_date_check CHECK ((logged_date = '2023-02-11'::date))
)
INHERITS (public.gnx_alert);


ALTER TABLE tp_gnx_alert.gnx_alert_2023_02_11 OWNER TO tsbdbadmin;

--
-- Name: gnx_alert_2023_02_12; Type: TABLE; Schema: tp_gnx_alert; Owner: tsbdbadmin
--

CREATE TABLE tp_gnx_alert.gnx_alert_2023_02_12 (
    CONSTRAINT gnx_alert_2023_02_12_logged_date_check CHECK ((logged_date = '2023-02-12'::date))
)
INHERITS (public.gnx_alert);


ALTER TABLE tp_gnx_alert.gnx_alert_2023_02_12 OWNER TO tsbdbadmin;

--
-- Name: gnx_alert_2023_02_13; Type: TABLE; Schema: tp_gnx_alert; Owner: tsbdbadmin
--

CREATE TABLE tp_gnx_alert.gnx_alert_2023_02_13 (
    CONSTRAINT gnx_alert_2023_02_13_logged_date_check CHECK ((logged_date = '2023-02-13'::date))
)
INHERITS (public.gnx_alert);


ALTER TABLE tp_gnx_alert.gnx_alert_2023_02_13 OWNER TO tsbdbadmin;

--
-- Name: gnx_alert_2023_02_14; Type: TABLE; Schema: tp_gnx_alert; Owner: tsbdbadmin
--

CREATE TABLE tp_gnx_alert.gnx_alert_2023_02_14 (
    CONSTRAINT gnx_alert_2023_02_14_logged_date_check CHECK ((logged_date = '2023-02-14'::date))
)
INHERITS (public.gnx_alert);


ALTER TABLE tp_gnx_alert.gnx_alert_2023_02_14 OWNER TO tsbdbadmin;

--
-- Name: gnx_alert_2023_02_15; Type: TABLE; Schema: tp_gnx_alert; Owner: tsbdbadmin
--

CREATE TABLE tp_gnx_alert.gnx_alert_2023_02_15 (
    CONSTRAINT gnx_alert_2023_02_15_logged_date_check CHECK ((logged_date = '2023-02-15'::date))
)
INHERITS (public.gnx_alert);


ALTER TABLE tp_gnx_alert.gnx_alert_2023_02_15 OWNER TO tsbdbadmin;

--
-- Name: gnx_alert_2023_02_16; Type: TABLE; Schema: tp_gnx_alert; Owner: tsbdbadmin
--

CREATE TABLE tp_gnx_alert.gnx_alert_2023_02_16 (
    CONSTRAINT gnx_alert_2023_02_16_logged_date_check CHECK ((logged_date = '2023-02-16'::date))
)
INHERITS (public.gnx_alert);


ALTER TABLE tp_gnx_alert.gnx_alert_2023_02_16 OWNER TO tsbdbadmin;

--
-- Name: gnx_alert_2023_02_17; Type: TABLE; Schema: tp_gnx_alert; Owner: tsbdbadmin
--

CREATE TABLE tp_gnx_alert.gnx_alert_2023_02_17 (
    CONSTRAINT gnx_alert_2023_02_17_logged_date_check CHECK ((logged_date = '2023-02-17'::date))
)
INHERITS (public.gnx_alert);


ALTER TABLE tp_gnx_alert.gnx_alert_2023_02_17 OWNER TO tsbdbadmin;

--
-- Name: gnx_alert_2023_02_18; Type: TABLE; Schema: tp_gnx_alert; Owner: tsbdbadmin
--

CREATE TABLE tp_gnx_alert.gnx_alert_2023_02_18 (
    CONSTRAINT gnx_alert_2023_02_18_logged_date_check CHECK ((logged_date = '2023-02-18'::date))
)
INHERITS (public.gnx_alert);


ALTER TABLE tp_gnx_alert.gnx_alert_2023_02_18 OWNER TO tsbdbadmin;

--
-- Name: gnx_alert_2023_02_19; Type: TABLE; Schema: tp_gnx_alert; Owner: tsbdbadmin
--

CREATE TABLE tp_gnx_alert.gnx_alert_2023_02_19 (
    CONSTRAINT gnx_alert_2023_02_19_logged_date_check CHECK ((logged_date = '2023-02-19'::date))
)
INHERITS (public.gnx_alert);


ALTER TABLE tp_gnx_alert.gnx_alert_2023_02_19 OWNER TO tsbdbadmin;

--
-- Name: gnx_alert_2023_02_20; Type: TABLE; Schema: tp_gnx_alert; Owner: tsbdbadmin
--

CREATE TABLE tp_gnx_alert.gnx_alert_2023_02_20 (
    CONSTRAINT gnx_alert_2023_02_20_logged_date_check CHECK ((logged_date = '2023-02-20'::date))
)
INHERITS (public.gnx_alert);


ALTER TABLE tp_gnx_alert.gnx_alert_2023_02_20 OWNER TO tsbdbadmin;

--
-- Name: gnx_alert_2023_02_21; Type: TABLE; Schema: tp_gnx_alert; Owner: tsbdbadmin
--

CREATE TABLE tp_gnx_alert.gnx_alert_2023_02_21 (
    CONSTRAINT gnx_alert_2023_02_21_logged_date_check CHECK ((logged_date = '2023-02-21'::date))
)
INHERITS (public.gnx_alert);


ALTER TABLE tp_gnx_alert.gnx_alert_2023_02_21 OWNER TO tsbdbadmin;

--
-- Name: gnx_location_2021_11_13; Type: TABLE; Schema: tp_location; Owner: tsbdbadmin
--

CREATE TABLE tp_location.gnx_location_2021_11_13 (
    CONSTRAINT gnx_location_2021_11_13_logged_date_check CHECK ((logged_date = '2021-11-13'::date))
)
INHERITS (public.gnx_location);


ALTER TABLE tp_location.gnx_location_2021_11_13 OWNER TO tsbdbadmin;

--
-- Name: gnx_location_2022_03_23; Type: TABLE; Schema: tp_location; Owner: tsbdbadmin
--

CREATE TABLE tp_location.gnx_location_2022_03_23 (
    CONSTRAINT gnx_location_2022_03_23_logged_date_check CHECK ((logged_date = '2022-03-23'::date))
)
INHERITS (public.gnx_location);


ALTER TABLE tp_location.gnx_location_2022_03_23 OWNER TO tsbdbadmin;

--
-- Name: gnx_location_2022_04_07; Type: TABLE; Schema: tp_location; Owner: tsbdbadmin
--

CREATE TABLE tp_location.gnx_location_2022_04_07 (
    CONSTRAINT gnx_location_2022_04_07_logged_date_check CHECK ((logged_date = '2022-04-07'::date))
)
INHERITS (public.gnx_location);


ALTER TABLE tp_location.gnx_location_2022_04_07 OWNER TO tsbdbadmin;

--
-- Name: gnx_location_2022_05_02; Type: TABLE; Schema: tp_location; Owner: tsbdbadmin
--

CREATE TABLE tp_location.gnx_location_2022_05_02 (
    CONSTRAINT gnx_location_2022_05_02_logged_date_check CHECK ((logged_date = '2022-05-02'::date))
)
INHERITS (public.gnx_location);


ALTER TABLE tp_location.gnx_location_2022_05_02 OWNER TO tsbdbadmin;

--
-- Name: gnx_location_2022_05_09; Type: TABLE; Schema: tp_location; Owner: tsbdbadmin
--

CREATE TABLE tp_location.gnx_location_2022_05_09 (
    CONSTRAINT gnx_location_2022_05_09_logged_date_check CHECK ((logged_date = '2022-05-09'::date))
)
INHERITS (public.gnx_location);


ALTER TABLE tp_location.gnx_location_2022_05_09 OWNER TO tsbdbadmin;

--
-- Name: gnx_location_2022_05_10; Type: TABLE; Schema: tp_location; Owner: tsbdbadmin
--

CREATE TABLE tp_location.gnx_location_2022_05_10 (
    CONSTRAINT gnx_location_2022_05_10_logged_date_check CHECK ((logged_date = '2022-05-10'::date))
)
INHERITS (public.gnx_location);


ALTER TABLE tp_location.gnx_location_2022_05_10 OWNER TO tsbdbadmin;

--
-- Name: gnx_location_2022_05_11; Type: TABLE; Schema: tp_location; Owner: tsbdbadmin
--

CREATE TABLE tp_location.gnx_location_2022_05_11 (
    CONSTRAINT gnx_location_2022_05_11_logged_date_check CHECK ((logged_date = '2022-05-11'::date))
)
INHERITS (public.gnx_location);


ALTER TABLE tp_location.gnx_location_2022_05_11 OWNER TO tsbdbadmin;

--
-- Name: gnx_location_2022_05_17; Type: TABLE; Schema: tp_location; Owner: tsbdbadmin
--

CREATE TABLE tp_location.gnx_location_2022_05_17 (
    CONSTRAINT gnx_location_2022_05_17_logged_date_check CHECK ((logged_date = '2022-05-17'::date))
)
INHERITS (public.gnx_location);


ALTER TABLE tp_location.gnx_location_2022_05_17 OWNER TO tsbdbadmin;

--
-- Name: gnx_location_2022_05_18; Type: TABLE; Schema: tp_location; Owner: tsbdbadmin
--

CREATE TABLE tp_location.gnx_location_2022_05_18 (
    CONSTRAINT gnx_location_2022_05_18_logged_date_check CHECK ((logged_date = '2022-05-18'::date))
)
INHERITS (public.gnx_location);


ALTER TABLE tp_location.gnx_location_2022_05_18 OWNER TO tsbdbadmin;

--
-- Name: gnx_location_2022_05_19; Type: TABLE; Schema: tp_location; Owner: tsbdbadmin
--

CREATE TABLE tp_location.gnx_location_2022_05_19 (
    CONSTRAINT gnx_location_2022_05_19_logged_date_check CHECK ((logged_date = '2022-05-19'::date))
)
INHERITS (public.gnx_location);


ALTER TABLE tp_location.gnx_location_2022_05_19 OWNER TO tsbdbadmin;

--
-- Name: gnx_location_2022_05_22; Type: TABLE; Schema: tp_location; Owner: tsbdbadmin
--

CREATE TABLE tp_location.gnx_location_2022_05_22 (
    CONSTRAINT gnx_location_2022_05_22_logged_date_check CHECK ((logged_date = '2022-05-22'::date))
)
INHERITS (public.gnx_location);


ALTER TABLE tp_location.gnx_location_2022_05_22 OWNER TO tsbdbadmin;

--
-- Name: gnx_location_2022_05_23; Type: TABLE; Schema: tp_location; Owner: tsbdbadmin
--

CREATE TABLE tp_location.gnx_location_2022_05_23 (
    CONSTRAINT gnx_location_2022_05_23_logged_date_check CHECK ((logged_date = '2022-05-23'::date))
)
INHERITS (public.gnx_location);


ALTER TABLE tp_location.gnx_location_2022_05_23 OWNER TO tsbdbadmin;

--
-- Name: tsb_notification_56; Type: TABLE; Schema: tp_notification; Owner: tsbdbadmin
--

CREATE TABLE tp_notification.tsb_notification_56 (
    CONSTRAINT tsb_notification_56_notification_user_id_check CHECK ((notification_user_id = 56))
)
INHERITS (public.tsb_notification);


ALTER TABLE tp_notification.tsb_notification_56 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_05_21; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_05_21 (
    CONSTRAINT tsb_vehicle_activity_2021_05_21_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-05-21'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_05_21 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_05_22; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_05_22 (
    CONSTRAINT tsb_vehicle_activity_2021_05_22_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-05-22'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_05_22 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_05_23; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_05_23 (
    CONSTRAINT tsb_vehicle_activity_2021_05_23_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-05-23'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_05_23 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_05_24; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_05_24 (
    CONSTRAINT tsb_vehicle_activity_2021_05_24_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-05-24'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_05_24 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_05_25; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_05_25 (
    CONSTRAINT tsb_vehicle_activity_2021_05_25_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-05-25'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_05_25 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_05_26; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_05_26 (
    CONSTRAINT tsb_vehicle_activity_2021_05_26_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-05-26'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_05_26 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_05_27; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_05_27 (
    CONSTRAINT tsb_vehicle_activity_2021_05_27_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-05-27'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_05_27 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_05_28; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_05_28 (
    CONSTRAINT tsb_vehicle_activity_2021_05_28_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-05-28'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_05_28 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_05_29; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_05_29 (
    CONSTRAINT tsb_vehicle_activity_2021_05_29_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-05-29'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_05_29 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_05_30; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_05_30 (
    CONSTRAINT tsb_vehicle_activity_2021_05_30_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-05-30'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_05_30 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_05_31; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_05_31 (
    CONSTRAINT tsb_vehicle_activity_2021_05_31_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-05-31'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_05_31 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_01; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_01 (
    CONSTRAINT tsb_vehicle_activity_2021_06_01_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-01'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_01 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_02; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_02 (
    CONSTRAINT tsb_vehicle_activity_2021_06_02_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-02'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_02 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_03; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_03 (
    CONSTRAINT tsb_vehicle_activity_2021_06_03_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-03'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_03 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_04; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_04 (
    CONSTRAINT tsb_vehicle_activity_2021_06_04_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-04'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_04 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_05; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_05 (
    CONSTRAINT tsb_vehicle_activity_2021_06_05_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-05'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_05 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_06; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_06 (
    CONSTRAINT tsb_vehicle_activity_2021_06_06_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-06'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_06 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_07; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_07 (
    CONSTRAINT tsb_vehicle_activity_2021_06_07_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-07'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_07 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_08; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_08 (
    CONSTRAINT tsb_vehicle_activity_2021_06_08_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-08'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_08 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_09; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_09 (
    CONSTRAINT tsb_vehicle_activity_2021_06_09_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-09'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_09 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_10; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_10 (
    CONSTRAINT tsb_vehicle_activity_2021_06_10_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-10'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_10 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_11; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_11 (
    CONSTRAINT tsb_vehicle_activity_2021_06_11_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-11'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_11 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_12; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_12 (
    CONSTRAINT tsb_vehicle_activity_2021_06_12_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-12'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_12 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_13; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_13 (
    CONSTRAINT tsb_vehicle_activity_2021_06_13_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-13'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_13 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_14; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_14 (
    CONSTRAINT tsb_vehicle_activity_2021_06_14_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-14'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_14 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_15; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_15 (
    CONSTRAINT tsb_vehicle_activity_2021_06_15_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-15'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_15 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_16; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_16 (
    CONSTRAINT tsb_vehicle_activity_2021_06_16_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-16'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_16 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_17; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_17 (
    CONSTRAINT tsb_vehicle_activity_2021_06_17_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-17'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_17 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_18; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_18 (
    CONSTRAINT tsb_vehicle_activity_2021_06_18_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-18'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_18 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_19; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_19 (
    CONSTRAINT tsb_vehicle_activity_2021_06_19_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-19'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_19 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_20; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_20 (
    CONSTRAINT tsb_vehicle_activity_2021_06_20_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-20'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_20 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_21; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_21 (
    CONSTRAINT tsb_vehicle_activity_2021_06_21_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-21'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_21 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_22; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_22 (
    CONSTRAINT tsb_vehicle_activity_2021_06_22_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-22'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_22 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_23; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_23 (
    CONSTRAINT tsb_vehicle_activity_2021_06_23_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-23'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_23 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_24; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_24 (
    CONSTRAINT tsb_vehicle_activity_2021_06_24_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-24'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_24 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_25; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_25 (
    CONSTRAINT tsb_vehicle_activity_2021_06_25_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-25'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_25 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_26; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_26 (
    CONSTRAINT tsb_vehicle_activity_2021_06_26_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-26'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_26 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_27; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_27 (
    CONSTRAINT tsb_vehicle_activity_2021_06_27_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-27'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_27 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_28; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_28 (
    CONSTRAINT tsb_vehicle_activity_2021_06_28_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-28'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_28 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_29; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_29 (
    CONSTRAINT tsb_vehicle_activity_2021_06_29_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-29'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_29 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_06_30; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_30 (
    CONSTRAINT tsb_vehicle_activity_2021_06_30_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-06-30'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_06_30 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_01; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_01 (
    CONSTRAINT tsb_vehicle_activity_2021_07_01_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-01'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_01 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_02; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_02 (
    CONSTRAINT tsb_vehicle_activity_2021_07_02_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-02'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_02 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_03; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_03 (
    CONSTRAINT tsb_vehicle_activity_2021_07_03_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-03'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_03 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_04; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_04 (
    CONSTRAINT tsb_vehicle_activity_2021_07_04_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-04'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_04 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_05; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_05 (
    CONSTRAINT tsb_vehicle_activity_2021_07_05_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-05'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_05 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_06; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_06 (
    CONSTRAINT tsb_vehicle_activity_2021_07_06_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-06'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_06 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_07; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_07 (
    CONSTRAINT tsb_vehicle_activity_2021_07_07_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-07'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_07 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_08; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_08 (
    CONSTRAINT tsb_vehicle_activity_2021_07_08_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-08'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_08 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_09; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_09 (
    CONSTRAINT tsb_vehicle_activity_2021_07_09_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-09'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_09 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_10; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_10 (
    CONSTRAINT tsb_vehicle_activity_2021_07_10_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-10'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_10 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_11; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_11 (
    CONSTRAINT tsb_vehicle_activity_2021_07_11_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-11'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_11 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_12; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_12 (
    CONSTRAINT tsb_vehicle_activity_2021_07_12_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-12'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_12 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_13; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_13 (
    CONSTRAINT tsb_vehicle_activity_2021_07_13_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-13'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_13 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_14; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_14 (
    CONSTRAINT tsb_vehicle_activity_2021_07_14_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-14'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_14 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_15; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_15 (
    CONSTRAINT tsb_vehicle_activity_2021_07_15_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-15'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_15 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_16; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_16 (
    CONSTRAINT tsb_vehicle_activity_2021_07_16_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-16'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_16 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_17; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_17 (
    CONSTRAINT tsb_vehicle_activity_2021_07_17_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-17'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_17 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_18; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_18 (
    CONSTRAINT tsb_vehicle_activity_2021_07_18_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-18'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_18 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_19; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_19 (
    CONSTRAINT tsb_vehicle_activity_2021_07_19_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-19'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_19 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_20; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_20 (
    CONSTRAINT tsb_vehicle_activity_2021_07_20_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-20'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_20 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_21; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_21 (
    CONSTRAINT tsb_vehicle_activity_2021_07_21_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-21'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_21 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_22; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_22 (
    CONSTRAINT tsb_vehicle_activity_2021_07_22_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-22'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_22 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_23; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_23 (
    CONSTRAINT tsb_vehicle_activity_2021_07_23_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-23'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_23 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_24; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_24 (
    CONSTRAINT tsb_vehicle_activity_2021_07_24_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-24'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_24 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_25; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_25 (
    CONSTRAINT tsb_vehicle_activity_2021_07_25_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-25'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_25 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_26; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_26 (
    CONSTRAINT tsb_vehicle_activity_2021_07_26_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-26'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_26 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_27; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_27 (
    CONSTRAINT tsb_vehicle_activity_2021_07_27_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-27'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_27 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_28; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_28 (
    CONSTRAINT tsb_vehicle_activity_2021_07_28_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-28'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_28 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_29; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_29 (
    CONSTRAINT tsb_vehicle_activity_2021_07_29_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-29'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_29 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_30; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_30 (
    CONSTRAINT tsb_vehicle_activity_2021_07_30_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-30'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_30 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_07_31; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_31 (
    CONSTRAINT tsb_vehicle_activity_2021_07_31_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-07-31'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_07_31 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_08_01; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_08_01 (
    CONSTRAINT tsb_vehicle_activity_2021_08_01_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-08-01'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_08_01 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_08_02; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_08_02 (
    CONSTRAINT tsb_vehicle_activity_2021_08_02_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-08-02'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_08_02 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_08_03; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_08_03 (
    CONSTRAINT tsb_vehicle_activity_2021_08_03_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-08-03'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_08_03 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_08_04; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_08_04 (
    CONSTRAINT tsb_vehicle_activity_2021_08_04_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-08-04'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_08_04 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_08_05; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_08_05 (
    CONSTRAINT tsb_vehicle_activity_2021_08_05_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-08-05'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_08_05 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_08_06; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_08_06 (
    CONSTRAINT tsb_vehicle_activity_2021_08_06_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-08-06'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_08_06 OWNER TO tsbdbadmin;

--
-- Name: tsb_vehicle_activity_2021_08_07; Type: TABLE; Schema: tp_vehicle_activity; Owner: tsbdbadmin
--

CREATE TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_08_07 (
    CONSTRAINT tsb_vehicle_activity_2021_08_07_vehicle_activity_date_check CHECK ((vehicle_activity_date = '2021-08-07'::date))
)
INHERITS (public.tsb_vehicle_activity);


ALTER TABLE tp_vehicle_activity.tsb_vehicle_activity_2021_08_07 OWNER TO tsbdbadmin;

--
