--
--


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

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

-- CREATE SCHEMA public;


ALTER SCHEMA public OWNER TO tsbdbadmin;

--
-- Name: SCHEMA public; Type: COMMENT; Schema: -; Owner: tsbdbadmin
--

COMMENT ON SCHEMA public IS 'standard public schema';


--
-- 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)
                        VALUES ($1,'||'$2'||',$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15)') 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;

    


    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   
    _parent_table_name text;
    _parent_schema_name text;
    _table_name text;
    _schema_name text;
    _primary_column text;
    _check_column text;
    _new_check_column text;
    _current_date text;
    _current_vehicle_id INTEGER;
    _current_driver_id INTEGER;
    _current_running_status character varying;
    _db_user_name text;
    _live_location_id INTEGER;
    _live_location_date date;
    _live_location_time time;
    _location_id INTEGER;
    _ivms_addon INTEGER;
    _latitude numeric;
    _longitude numeric;
    BEGIN
        --specify parameter for table partition
        _parent_table_name:='gnx_location';
        _parent_schema_name:='public';
        _schema_name:='tp_location';
        _primary_column:='id';
        _check_column:='logged_date';
        _new_check_column:=NEW.logged_date;
        _db_user_name:='tsbdbadmin'; 
        _current_date := translate(_new_check_column::text,'-','_');
        _table_name := _parent_table_name||'_'||_current_date;
        SELECT INTO _current_vehicle_id,_current_driver_id  vehicle_id,vehicle_driver_id  FROM tsb_vehicle where vehicle_imei=NEW.imei;
        IF(_current_vehicle_id > 0) THEN
            -- 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 = _table_name
            AND    n.nspname = _schema_name;
        
            -- 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 '|| _schema_name || '.' || _table_name || ' (check ('||_check_column||' = ''' ||_new_check_column || ''')) INHERITS ('||_parent_schema_name||'.'|| _parent_table_name ||')'; 
                -- 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 '|| _schema_name || '.' || quote_ident(_table_name) || ' OWNER TO ' || _db_user_name;
                EXECUTE 'GRANT ALL ON '|| _schema_name||'.' || quote_ident(_table_name) || ' TO ' || _db_user_name;
                -- Indexes are defined per child, so we assign a default index that uses the partition columns
                EXECUTE 'CREATE INDEX ' || quote_ident(_table_name||'_indx1') || ' ON '|| _schema_name||'.' || quote_ident(_table_name) || ' ('|| _primary_column ||')';
                EXECUTE 'ALTER TABLE ONLY '|| _schema_name||'.' || quote_ident(_table_name) || ' ADD CONSTRAINT location_pkey'||'_'||_current_date ||' PRIMARY KEY ('|| _primary_column ||')';
            END IF;
   
            -- check same signal exist or not         
            EXECUTE 'SELECT  id FROM '|| _schema_name||'.' || quote_ident(_table_name) || ' 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 _location_id
            USING NEW.logged_date, NEW.logged_time, NEW.latitude,NEW.longitude,NEW.imei,NEW.metering_status,NEW.gps_data_valid ;
 
            IF(_location_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 '|| _schema_name||'.' || quote_ident(_table_name) || ' VALUES ($1.*)' USING NEW;

            IF (TG_OP = 'INSERT') THEN
                _latitude = NEW.latitude;
                _longitude = NEW.longitude;
                if(NEW.latitude_direction ='S') THEN 
                    _latitude = _latitude * -1;
                END IF;
                if(NEW.longitude_direction ='W') THEN 
                    _longitude = _longitude * -1;
                END IF;
                -- 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|| ',' || NEW.temperature || ',' || NEW.temperature2 || ',' || NEW.temperature3 || ',' || NEW.temperature4);
                IF((NEW.latitude!=0)) THEN
                    SELECT INTO _live_location_id,_live_location_date,_live_location_time id,logged_date,logged_time FROM public.gnx_live_location where imei=NEW.imei;
                    IF(_live_location_id>0) THEN
                        IF(NEW.logged_date>_live_location_date OR (NEW.logged_date>=_live_location_date AND NEW.logged_time>_live_location_time)) THEN
                            UPDATE public.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, temperature=NEW.temperature, temperature2=NEW.temperature2, temperature3=NEW.temperature3, temperature4=NEW.temperature4, seat_belt=New.seat_belt where id=_live_location_id;
                        END IF;
                    ELSE
                        EXECUTE 'INSERT INTO '|| _parent_schema_name||'.gnx_live_location' || ' VALUES ($1.*)' USING NEW;  
                    END IF;
                    IF (NEW.metering_status='A') THEN
                        _current_running_status='Parked';
                        ELSE IF (NEW.metering_status='B') THEN
                                _current_running_status='Running';
                            ELSE IF (NEW.metering_status='d') THEN
                                    _current_running_status='Idle';
                                ELSE
                                    _current_running_status='Towing';
                                END IF;
                            END IF;
                    END IF;
                    SELECT INTO _ivms_addon addon_ivms FROM public.tsb_addon ;
                    IF(_ivms_addon = 1) THEN 
                        PERFORM update_vehicle_activity(NEW.latitude,NEW.latitude_direction,NEW.longitude,NEW.longitude_direction,NEW.logged_date,NEW.logged_time,NEW.speed, _current_running_status, _current_driver_id, _current_vehicle_id);
                    END IF;
                    PERFORM update_overspeed_activity(NEW.latitude,NEW.latitude_direction,NEW.longitude,NEW.longitude_direction,NEW.logged_date,NEW.logged_time,NEW.speed, _current_running_status, _current_driver_id, _current_vehicle_id);
                    PERFORM update_seatbelt_activity(NEW.latitude,NEW.latitude_direction,NEW.longitude,NEW.longitude_direction,NEW.logged_date,NEW.logged_time,NEW.speed, _current_running_status, _current_driver_id, _current_vehicle_id,NEW.seat_belt);
                   
                END IF;        
            END IF;
        END IF;
    RETURN NULL;
    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   
    _parent_table_name text;
    _parent_schema_name text;
    _table_name text;
    _schema_name text;
    _primary_column text;
    _check_column text;
    _new_check_column text;
    _current_date text;
    _db_user_name text;
    _current_user_id INTEGER;
    _current_vehcile_id INTEGER;
    _last_inserted_id INTEGER;
    _last_mifare_card_id text;
    _last_logged_time time without time zone;
    

BEGIN
    SELECT INTO _current_user_id tsb_user_card.card_user_id FROM tsb_user_card WHERE tsb_user_card.card_user_mifarecard_id = NEW.mifare_card_id;
    SELECT INTO _current_vehcile_id vehicle_id FROM tsb_vehicle WHERE vehicle_imei = NEW.imei;
          --specify parameter for table partition
        IF (_current_user_id <= 0 OR _current_user_id IS NULL OR _current_vehcile_id <=0  OR  _current_vehcile_id IS NULL) THEN
            RETURN NULL;
        END IF;
        _parent_table_name:='gnx_mifare_card_user';
        _parent_schema_name:='public';
        _schema_name:='tp_mifare_card_user';
        _primary_column:='id';
        _check_column:='logged_date';
        _new_check_column:=NEW.logged_date;
        _db_user_name:='tsbdbadmin'; 
        _current_date := translate(_new_check_column::text,'-','_');
        _table_name := _parent_table_name||'_'||_current_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 = _table_name
        AND    n.nspname = _schema_name;
        
        -- 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 '|| _schema_name || '.' || _table_name || ' (check ('||_check_column||' = ''' ||_new_check_column || ''')) INHERITS ('||_parent_schema_name||'.'|| _parent_table_name ||')'; 
            -- 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 '|| _schema_name || '.' || quote_ident(_table_name) || ' OWNER TO ' || _db_user_name;
            EXECUTE 'GRANT ALL ON '|| _schema_name||'.' || quote_ident(_table_name) || ' TO ' || _db_user_name;
            -- Indexes are defined per child, so we assign a default index that uses the partition columns
            EXECUTE 'CREATE INDEX ' || quote_ident(_table_name||'_indx1') || ' ON '|| _schema_name||'.' || quote_ident(_table_name) || ' ('|| _primary_column ||')';
            EXECUTE 'ALTER TABLE ONLY '|| _schema_name||'.' || quote_ident(_table_name) || ' ADD CONSTRAINT mifare_user_pkey'||'_'||_current_date ||' PRIMARY KEY ('|| _primary_column ||')';
        END IF;
   
        -- check same attendance exist or not         
        EXECUTE 'SELECT id,mifare_card_id,logged_time FROM ' || _schema_name ||'.' || quote_ident(_table_name) || ' WHERE logged_date = $1 AND imei = $2 order by logged_time desc limit 1'

        INTO _last_inserted_id, _last_mifare_card_id, _last_logged_time

        USING NEW.logged_date, NEW.imei;

        IF (_last_inserted_id > 0 AND _last_mifare_card_id = NEW.mifare_card_id AND _last_logged_time > NEW.logged_time) THEN
            RETURN NULL;
        END IF;
        -- Insert the current record into the correct partition, which we are sure will now exist.
        EXECUTE 'INSERT INTO '|| _schema_name||'.' || quote_ident(_table_name) || ' VALUES ($1.*)' USING NEW;

        IF (TG_OP = 'INSERT') THEN
            EXECUTE 'UPDATE '|| _parent_schema_name||'.tsb_vehicle SET vehicle_driver_id='|| _current_user_id|| 'WHERE vehicle_id='||_current_vehcile_id ;
              _parent_table_name:='tsb_vehicle_activity';
        _schema_name:='tp_vehicle_activity';
        _primary_column:='vehicle_activity_id';
        _new_check_column:=NEW.logged_date;
        _current_date := translate(_new_check_column::text,'-','_');
        _table_name := _parent_table_name||'_'||_current_date;
        -- Check if the partition table  exists or not
        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 = _table_name
        AND    n.nspname = _schema_name;
        IF FOUND THEN
            EXECUTE 'UPDATE '|| _schema_name||'.' || quote_ident(_table_name) || '  SET vehicle_activity_driver_id=$1 WHERE vehicle_activity_vehicle_id=$2 and vehicle_activity_end_time IS NULL' 
            USING _current_user_id,_current_vehcile_id;
        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 NEW;

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_priority_log(); Type: FUNCTION; Schema: public; Owner: tsbdbadmin
--

CREATE FUNCTION public.partition_function_notification_priority_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_priority_log';
_schemaname:='tp_notification_priority_log';
_primary_column:='notification_priority_log_id';
_check_column:='notification_priority_log_date';
_newcheck_column=NEW.notification_priority_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';
EXECUTE 'ALTER TABLE '|| _schemaname||'.' || quote_ident(_tablename) || ' ADD PRIMARY KEY ('|| _primary_column||')';
-- Indexes are defined per child, so we assign a default index that uses the partition columns
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_priority_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_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 'ALTER TABLE ' || _schemaname || '.' || quote_ident(_tablename) || ' ADD PRIMARY KEY (vehicle_activity_id)';

 
        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_overspeed_activity(numeric, character, numeric, character, date, time without time zone, integer, character varying, integer, integer); Type: FUNCTION; Schema: public; Owner: tsbdbadmin
--

CREATE FUNCTION public.update_overspeed_activity(latitude numeric, latitude_direction character, longitude numeric, longitude_direction character, logged_date date, logged_time time without time zone, speed integer, running_status character varying, driver_id integer, vehicle_id integer) RETURNS void
    LANGUAGE plpgsql
    AS $_$DECLARE

_activity_start_time time;
_activity_id INTEGER;
_duration INTEGER;
_distance INTEGER; 
_activity_status VARCHAR;
_new_date text;
_schema_name text;
_table_name text;
_current_speed_limit INTEGER;
_current_recorded_speed INTEGER;
_lat_without_dir numeric;
_long_without_dir numeric;
location_point point;
_user_record record;
_vehicle_number text;
_message text;
_vehicle_id INTEGER;
_parent_schema_name text;
_parent_table_name text;
_primary_column text;
_new_check_column text;
_check_column text;
_db_user_name text;

BEGIN
 _new_date := translate(logged_date::text,'-','_'); 
 _table_name := 'tsb_vehicle_activity_'||_new_date;
 _schema_name := 'tp_vehicle_activity';
 _parent_schema_name:='public';
 _new_check_column:=logged_date;
 _parent_table_name:='tsb_vehicle_activity';
 _primary_column:='vehicle_activity_id';
_check_column:='vehicle_activity_date';
 _db_user_name:='tsbdbadmin'; 
 _lat_without_dir = latitude;
 _long_without_dir = longitude;
if(latitude_direction ='S') THEN 
    _lat_without_dir = latitude * -1;
END IF;
if(longitude_direction ='W') THEN 
    _long_without_dir = longitude * -1;
END IF;
location_point = _lat_without_dir||','||_long_without_dir;
SELECT INTO _current_speed_limit  customer_speed_limit	FROM tsb_customer limit 1;
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 = _table_name
    AND    n.nspname = _schema_name;
    IF NOT FOUND THEN
        EXECUTE 'CREATE TABLE '|| _schema_name || '.' || _table_name || ' (check ('||_check_column||' = ''' ||_new_check_column || ''')) INHERITS ('||_parent_schema_name||'.'|| _parent_table_name ||')'; 
        -- 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 '|| _schema_name || '.' || quote_ident(_table_name) || ' OWNER TO ' || _db_user_name;
        EXECUTE 'GRANT ALL ON '|| _schema_name||'.' || quote_ident(_table_name) || ' TO ' || _db_user_name;
        -- Indexes are defined per child, so we assign a default index that uses the partition columns
        EXECUTE 'CREATE INDEX ' || quote_ident(_table_name||'_indx1') || ' ON '|| _schema_name||'.' || quote_ident(_table_name) || ' ('|| _primary_column ||')';
        EXECUTE 'ALTER TABLE ONLY '|| _schema_name||'.' || quote_ident(_table_name) || ' ADD CONSTRAINT vehicle_activity_pkey_'||'_'||_new_date ||' PRIMARY KEY ('|| _primary_column ||')';
        
    IF(_current_speed_limit < speed) THEN
        INSERT INTO tsb_vehicle_activity (vehicle_activity_vehicle_id,vehicle_activity_date,vehicle_activity_start_time,vehicle_activity_start_latitude,vehicle_activity_start_latitude_direction,vehicle_activity_start_longitude,vehicle_activity_start_longitude_direction,vehicle_activity_status,vehicle_activity_driver_id,vehicle_activity_maxspeed,vehicle_activity_avgspeed,vehicle_activity_start_point) VALUES (vehicle_id ,logged_date , logged_time , latitude, latitude_direction, longitude ,longitude_direction,'Overspeed',driver_id ,speed,speed,location_point);
    END IF;
ELSE 
    EXECUTE 'SELECT vehicle_activity_start_time,vehicle_activity_id,vehicle_activity_status, EXTRACT(EPOCH FROM ($1 - vehicle_activity_start_time)) , vehicle_activity_maxspeed  from '|| _schema_name || '.' || quote_ident(_table_name) || '  where  vehicle_activity_vehicle_id= $2 and vehicle_activity_date=$3 and vehicle_activity_end_time is NULL and vehicle_activity_status=$4  order by vehicle_activity_id desc limit 1'
    INTO _activity_start_time,_activity_id,_activity_status,_duration,_current_recorded_speed
    USING logged_time,vehicle_id,logged_date,'Overspeed';

    SELECT INTO _current_speed_limit  customer_speed_limit	FROM tsb_customer limit 1;
    IF(_activity_id > 0) THEN
        IF(_current_speed_limit > speed AND _activity_start_time < logged_time) THEN
            EXECUTE ' UPDATE '|| _schema_name || '.' || quote_ident(_table_name) || ' set vehicle_activity_end_time=$1,vehicle_activity_end_latitude=$2,vehicle_activity_end_latitude_direction=$3,vehicle_activity_end_longitude =$4,vehicle_activity_end_longitude_direction=$5, vehicle_activity_duration=$6, vehicle_activity_distance=$7, vehicle_activity_maxspeed=$8,vehicle_activity_driver_id=$9,vehicle_activity_end_point=$11 where  vehicle_activity_id=$10'
            USING logged_time,latitude,latitude_direction,longitude,longitude_direction,_duration,_distance,_current_recorded_speed,driver_id,_activity_id,location_point;
            _vehicle_id =vehicle_id;
            SELECT INTO _vehicle_number  vehicle_number FROM tsb_vehicle where tsb_vehicle.vehicle_id = _vehicle_id limit 1;
            _message = _vehicle_number ||' hit a speed bump on '|| logged_date || ' at '|| logged_time ||' reaching a maximum speed of '|| _current_recorded_speed || ' in '|| _duration || ' seconds';
            for _user_record in SELECT user_id from tsb_user  where user_status = 'active' and user_role in ('customer','transport-manager')  order by user_id
            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,push_notification_settings_field) VALUES (_user_record.user_id, _message, 'emergency' , logged_date, logged_time, 'pending' ,'#','','','notification_settings_speed_break');
            end loop;
        ELSE IF (_current_recorded_speed < speed AND _activity_start_time < logged_time) THEN
            EXECUTE ' UPDATE '|| _schema_name || '.' || quote_ident(_table_name) || ' set  vehicle_activity_maxspeed=$1,vehicle_activity_driver_id=$2 where  vehicle_activity_id=$3'
            USING speed,driver_id,_activity_id;
            END IF;
        END IF;
    ELSE IF(_current_speed_limit < speed) THEN
        INSERT INTO tsb_vehicle_activity (vehicle_activity_vehicle_id,vehicle_activity_date,vehicle_activity_start_time,vehicle_activity_start_latitude,vehicle_activity_start_latitude_direction,vehicle_activity_start_longitude,vehicle_activity_start_longitude_direction,vehicle_activity_status,vehicle_activity_driver_id,vehicle_activity_maxspeed,vehicle_activity_avgspeed,vehicle_activity_start_point) VALUES (vehicle_id ,logged_date , logged_time , latitude, latitude_direction, longitude ,longitude_direction,'Overspeed',driver_id ,speed,speed,location_point);
        END IF;
    END IF; 
END IF; 

    RETURN;
END;
$_$;


ALTER FUNCTION public.update_overspeed_activity(latitude numeric, latitude_direction character, longitude numeric, longitude_direction character, logged_date date, logged_time time without time zone, speed integer, running_status character varying, driver_id integer, vehicle_id integer) OWNER TO tsbdbadmin;

--
-- Name: update_seatbelt_activity(numeric, character, numeric, character, date, time without time zone, integer, character varying, integer, integer, smallint); Type: FUNCTION; Schema: public; Owner: tsbdbadmin
--

CREATE FUNCTION public.update_seatbelt_activity(latitude numeric, latitude_direction character, longitude numeric, longitude_direction character, logged_date date, logged_time time without time zone, speed integer, running_status character varying, driver_id integer, vehicle_id integer, seat_belt_value smallint) RETURNS void
    LANGUAGE plpgsql
    AS $_$DECLARE

_activity_start_time time;
_activity_id INTEGER;
_duration INTEGER;
_distance INTEGER; 
_activity_status VARCHAR;
_new_date text;
_schema_name text;
_table_name text;
_current_speed_limit INTEGER;
_current_recorded_speed INTEGER;
_lat_without_dir numeric;
_long_without_dir numeric;
location_point point;
_parent_schema_name text;
_parent_table_name text;
_primary_column text;
_new_check_column text;
_check_column text;
_db_user_name text;

BEGIN

 _new_date := translate(logged_date::text,'-','_'); 
 _table_name := 'tsb_vehicle_activity_'||_new_date;
 _schema_name := 'tp_vehicle_activity';
 _parent_schema_name:='public';
 _new_check_column:=logged_date;
 _parent_table_name:='tsb_vehicle_activity';
 _primary_column:='vehicle_activity_id';
_check_column:='vehicle_activity_date';
 _db_user_name:='tsbdbadmin'; 
_lat_without_dir = latitude;
_long_without_dir = longitude;
if(latitude_direction = 'S') THEN 
    _lat_without_dir = latitude * -1;
END IF;
if(longitude_direction = 'W') THEN 
    _long_without_dir = longitude * -1;
END IF;
location_point = _lat_without_dir||','||_long_without_dir;
        -- 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 = _table_name
        AND    n.nspname = _schema_name;
        
        -- 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 '|| _schema_name || '.' || _table_name || ' (check ('||_check_column||' = ''' ||_new_check_column || ''')) INHERITS ('||_parent_schema_name||'.'|| _parent_table_name ||')'; 
            -- 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 '|| _schema_name || '.' || quote_ident(_table_name) || ' OWNER TO ' || _db_user_name;
            EXECUTE 'GRANT ALL ON '|| _schema_name||'.' || quote_ident(_table_name) || ' TO ' || _db_user_name;
            -- Indexes are defined per child, so we assign a default index that uses the partition columns
            EXECUTE 'CREATE INDEX ' || quote_ident(_table_name||'_indx1') || ' ON '|| _schema_name||'.' || quote_ident(_table_name) || ' ('|| _primary_column ||')';
            EXECUTE 'ALTER TABLE ONLY '|| _schema_name||'.' || quote_ident(_table_name) || ' ADD CONSTRAINT vehicle_activity_pkey_'||'_'||_new_date ||' PRIMARY KEY ('|| _primary_column ||')';
        END IF;
EXECUTE 'SELECT vehicle_activity_start_time,vehicle_activity_id,vehicle_activity_status, EXTRACT(EPOCH FROM ($1 - vehicle_activity_start_time))  from '|| _schema_name || '.' || quote_ident(_table_name) || '  where  vehicle_activity_vehicle_id = $2 and vehicle_activity_date = $3 and vehicle_activity_end_time is null and vehicle_activity_status = $4  order by vehicle_activity_id desc limit 1'
INTO _activity_start_time,_activity_id,_activity_status,_duration
USING logged_time,vehicle_id,logged_date,'Seatbelt';
IF(_activity_id > 0) THEN
    IF(((running_status = 'Running' OR running_status = 'IDLE') AND seat_belt_value = 1 AND _activity_start_time < logged_time) OR (running_status = 'Parked' AND _activity_start_time < logged_time)) THEN
        UPDATE tsb_vehicle_activity set vehicle_activity_end_time=logged_time,vehicle_activity_end_latitude=latitude,vehicle_activity_end_latitude_direction=latitude_direction,vehicle_activity_end_longitude = longitude,vehicle_activity_end_longitude_direction = longitude_direction, vehicle_activity_duration = _duration, vehicle_activity_distance = _distance,vehicle_activity_end_point = location_point where  vehicle_activity_vehicle_id = vehicle_id and vehicle_activity_status = 'Seatbelt' and vehicle_activity_end_time is null;
    END IF;
ELSE IF(running_status = 'Running' AND seat_belt_value = 0) THEN
        INSERT INTO tsb_vehicle_activity (vehicle_activity_vehicle_id,vehicle_activity_date,vehicle_activity_start_time,vehicle_activity_start_latitude,vehicle_activity_start_latitude_direction,vehicle_activity_start_longitude,vehicle_activity_start_longitude_direction,vehicle_activity_status,vehicle_activity_driver_id,vehicle_activity_maxspeed,vehicle_activity_start_point) VALUES (vehicle_id ,logged_date , logged_time , latitude, latitude_direction, longitude ,longitude_direction,'Seatbelt',driver_id ,speed,location_point);
     END IF;
END IF; 

RETURN;
END;
$_$;


ALTER FUNCTION public.update_seatbelt_activity(latitude numeric, latitude_direction character, longitude numeric, longitude_direction character, logged_date date, logged_time time without time zone, speed integer, running_status character varying, driver_id integer, vehicle_id integer, seat_belt_value smallint) OWNER TO tsbdbadmin;

--
-- Name: update_vehicle_activity(numeric, character, numeric, character, date, time without time zone, integer, character varying, integer, integer); Type: FUNCTION; Schema: public; Owner: tsbdbadmin
--

CREATE FUNCTION public.update_vehicle_activity(latitude numeric, latitude_direction character, longitude numeric, longitude_direction character, logged_date date, logged_time time without time zone, speed integer, running_status character varying, driver_id integer, vehicle_id integer) RETURNS void
    LANGUAGE plpgsql
    AS $_$DECLARE
_activity_start_time time;
_activity_id INTEGER;
_activity_id2 INTEGER;
_duration INTEGER;
_duration2 INTEGER;
_distance INTEGER; 
_activity_status VARCHAR;
_activity_status2 VARCHAR;
_new_date text;
_schema_name text;
_table_name text;
_current_speed_limit INTEGER;
_current_recorded_speed INTEGER;
_current_recorded_speed2 INTEGER;
_parent_table_name text;
 _parent_schema_name text;
 _primary_column text;
_check_column text;
_new_check_column text;
_db_user_name text;
_allowed_idle_time integer;
_activity_merge boolean;
_lat_without_dir numeric;
_long_without_dir numeric;
location_point point;
BEGIN
 _parent_table_name:='tsb_vehicle_activity';
 _parent_schema_name:='public';
_new_date := translate(logged_date::text,'-','_'); 
_table_name := 'tsb_vehicle_activity_'||_new_date;
_schema_name := 'tp_vehicle_activity';
 _primary_column:='vehicle_activity_id';
_check_column:='vehicle_activity_date';
 _db_user_name:='tsbdbadmin'; 
_new_check_column:=logged_date;
_activity_merge=false;
 _lat_without_dir = latitude;
_long_without_dir = longitude;
if(latitude_direction ='S') THEN 
    _lat_without_dir = latitude * -1;
END IF;
if(longitude_direction ='W') THEN 
    _long_without_dir = longitude * -1;
END IF;
location_point = _lat_without_dir||','||_long_without_dir;

        -- 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 = _table_name
        AND    n.nspname = _schema_name;
        
        -- 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 '|| _schema_name || '.' || _table_name || ' (check ('||_check_column||' = ''' ||_new_check_column || ''')) INHERITS ('||_parent_schema_name||'.'|| _parent_table_name ||')'; 
            -- 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 '|| _schema_name || '.' || quote_ident(_table_name) || ' OWNER TO ' || _db_user_name;
            EXECUTE 'GRANT ALL ON '|| _schema_name||'.' || quote_ident(_table_name) || ' TO ' || _db_user_name;
            -- Indexes are defined per child, so we assign a default index that uses the partition columns
            EXECUTE 'CREATE INDEX ' || quote_ident(_table_name||'_indx1') || ' ON '|| _schema_name||'.' || quote_ident(_table_name) || ' ('|| _primary_column ||')';
            EXECUTE 'ALTER TABLE ONLY '|| _schema_name||'.' || quote_ident(_table_name) || ' ADD CONSTRAINT vehicle_activity_pkey_'||'_'||_new_date ||' PRIMARY KEY ('|| _primary_column ||')';
        END IF;
EXECUTE 'SELECT  vehicle_activity_start_time,vehicle_activity_id,vehicle_activity_status,vehicle_activity_maxspeed, EXTRACT(EPOCH FROM ($1 - vehicle_activity_start_time))  from '|| _schema_name || '.' || quote_ident(_table_name) || ' where  vehicle_activity_vehicle_id= $2 and vehicle_activity_end_time is null and (vehicle_activity_status=$3 OR vehicle_activity_status=$4 OR vehicle_activity_status=$5) order by vehicle_activity_id desc limit 1'
INTO _activity_start_time,_activity_id,_activity_status,_current_recorded_speed,_duration
USING logged_time,vehicle_id,'Running','Parked','Idle';
IF(_activity_id > 0) THEN
    IF(_activity_status <> running_status AND _activity_start_time < logged_time ) THEN
        IF (_activity_status='Idle') THEN
            EXECUTE 'SELECT settings_allowed_idle_time FROM public.tsb_settings limit 1'
            INTO _allowed_idle_time;
            IF(_allowed_idle_time <= 0 OR _allowed_idle_time IS NULL) THEN
                _allowed_idle_time=180;
            ELSE
                _allowed_idle_time=_allowed_idle_time*60;
            END IF;
            IF (_duration <= _allowed_idle_time) THEN
                EXECUTE 'SELECT  vehicle_activity_id,vehicle_activity_status,vehicle_activity_maxspeed, EXTRACT(EPOCH FROM (vehicle_activity_end_time - vehicle_activity_start_time)) from '|| _schema_name || '.' || quote_ident(_table_name) || ' where  vehicle_activity_vehicle_id= $1 AND vehicle_activity_id < $2 AND (vehicle_activity_status=$3 OR vehicle_activity_status=$4)  order by vehicle_activity_id desc limit 1'
                INTO _activity_id2,_activity_status2,_current_recorded_speed2,_duration2
                USING vehicle_id,_activity_id,'Running','Parked';
                IF(_activity_id2 > 0  AND (_activity_status2='Running' OR _activity_status2='Parked')) THEN
                    IF (_current_recorded_speed < _current_recorded_speed2 ) THEN
                        _current_recorded_speed=_current_recorded_speed2;
                    END IF;
                    _activity_merge=true;
                    IF(((_activity_status2='Running' AND running_status='Running') OR (_activity_status2='Parked' AND running_status='Parked'))) THEN
                        logged_time=NULL;
                        latitude=NULL;
                        latitude_direction=NULL;
                        longitude=NULL;
                        longitude_direction=NULL;
                        _duration=NULL;
                        _distance=NULL;
                    ELSE
                        _duration=_duration+_duration2;
                    END IF;
                ELSE
                    _distance=0;
                    _current_recorded_speed=0;
                END IF;
            ELSE
             _distance=0;
            _current_recorded_speed=0;
            
            END IF;
        ELSE IF (_activity_status='Parked') THEN
                _distance=0;
                _current_recorded_speed=0;
            ELSE IF (_activity_status = running_status AND _activity_start_time < logged_time AND _current_recorded_speed < speed ) THEN
                _current_recorded_speed=speed;
                _distance=NULL;
                END IF;
            END IF;
        END IF;
        IF (_activity_merge=true)  THEN
            EXECUTE ' UPDATE '|| _schema_name || '.' || quote_ident(_table_name) || ' set vehicle_activity_end_time=$1,vehicle_activity_end_latitude=$2,vehicle_activity_end_latitude_direction=$3,vehicle_activity_end_longitude =$4,vehicle_activity_end_longitude_direction=$5, vehicle_activity_duration=$6, vehicle_activity_distance=$7, vehicle_activity_maxspeed=$8,vehicle_activity_driver_id=$9, vehicle_activity_start_location=NULL, vehicle_activity_end_location=NULL,vehicle_activity_end_point=$11  where  vehicle_activity_id=$10'
            USING logged_time,latitude,latitude_direction,longitude,longitude_direction,_duration,_distance,_current_recorded_speed,driver_id,_activity_id2,location_point;
            EXECUTE ' DELETE FROM '|| _schema_name || '.' || quote_ident(_table_name) || ' where  vehicle_activity_id=$1'
            USING _activity_id;
        ELSE
            EXECUTE ' UPDATE '|| _schema_name || '.' || quote_ident(_table_name) || ' set vehicle_activity_end_time=$1,vehicle_activity_end_latitude=$2,vehicle_activity_end_latitude_direction=$3,vehicle_activity_end_longitude =$4,vehicle_activity_end_longitude_direction=$5, vehicle_activity_duration=$6, vehicle_activity_distance=$7, vehicle_activity_maxspeed=$8,vehicle_activity_driver_id=$9,vehicle_activity_end_point=$11 where  vehicle_activity_id=$10'
            USING logged_time,latitude,latitude_direction,longitude,longitude_direction,_duration,_distance,_current_recorded_speed,driver_id,_activity_id,location_point;
            INSERT INTO tsb_vehicle_activity (vehicle_activity_vehicle_id,vehicle_activity_date,vehicle_activity_start_time,vehicle_activity_start_latitude,vehicle_activity_start_latitude_direction,vehicle_activity_start_longitude,vehicle_activity_start_longitude_direction,vehicle_activity_status,vehicle_activity_driver_id,vehicle_activity_maxspeed,vehicle_activity_avgspeed,vehicle_activity_start_point) VALUES (vehicle_id ,logged_date , logged_time , latitude, latitude_direction, longitude ,longitude_direction,running_status,driver_id ,_current_recorded_speed,_current_recorded_speed,location_point);

        END IF;
    ELSE IF(_activity_status = 'Running' AND speed > _current_recorded_speed AND _activity_start_time < logged_time) THEN

            EXECUTE ' UPDATE '|| _schema_name || '.' || quote_ident(_table_name) || ' set  vehicle_activity_maxspeed=$1,vehicle_activity_driver_id=$2 where  vehicle_activity_id=$3'
            USING _current_recorded_speed,driver_id,driver_id,_activity_id;
        END IF;
    END IF;
ELSE
     INSERT INTO tsb_vehicle_activity (vehicle_activity_vehicle_id,vehicle_activity_date,vehicle_activity_start_time,vehicle_activity_start_latitude,vehicle_activity_start_latitude_direction,vehicle_activity_start_longitude,vehicle_activity_start_longitude_direction,vehicle_activity_status,vehicle_activity_driver_id,vehicle_activity_maxspeed,vehicle_activity_avgspeed,vehicle_activity_start_point) VALUES (vehicle_id ,logged_date , logged_time , latitude, latitude_direction, longitude ,longitude_direction,running_status,driver_id ,speed,speed,location_point);
END IF;
RETURN;
END;
$_$;


ALTER FUNCTION public.update_vehicle_activity(latitude numeric, latitude_direction character, longitude numeric, longitude_direction character, logged_date date, logged_time time without time zone, speed integer, running_status character varying, driver_id integer, vehicle_id integer) 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)
);


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 SEQUENCE 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 SEQUENCE 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 SEQUENCE 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: 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
    MAXVALUE 999999999999
    CACHE 1;


ALTER SEQUENCE public.gnx_digital_input_output_pid OWNER TO tsbdbadmin;

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

CREATE TABLE public.gnx_digital_input_output (
    id integer DEFAULT nextval('public.gnx_digital_input_output_pid'::regclass) 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: device_digital_input_output_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

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


ALTER SEQUENCE public.device_digital_input_output_id_seq OWNER TO tsbdbadmin;

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

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


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

CREATE TABLE public.dispatch_order_items (
    item_id integer NOT NULL,
    item_code text,
    item_type text,
    item_description text,
    item_pono text,
    item_rate text,
    item_quantity text,
    item_detailed_id integer,
    item_um text
);


ALTER TABLE public.dispatch_order_items OWNER TO tsbdbadmin;

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

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


ALTER SEQUENCE public.dispatch_order_items_item_id_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.dispatch_order_items_item_id_seq OWNED BY public.dispatch_order_items.item_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),
    driver_manager_id integer
);


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 SEQUENCE 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(500),
    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 SEQUENCE 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 SEQUENCE 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 SEQUENCE 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 SEQUENCE 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 SEQUENCE 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_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 SEQUENCE 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 SEQUENCE 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 SEQUENCE 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: 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 SEQUENCE public.live_location_id_seq OWNER TO tsbdbadmin;

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

CREATE TABLE public.gnx_live_location (
    id integer DEFAULT nextval('public.live_location_id_seq'::regclass) 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),
    temperature numeric,
    temperature2 numeric,
    temperature3 numeric,
    temperature4 numeric,
    seat_belt smallint
);


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),
    temperature numeric,
    temperature2 numeric,
    temperature3 numeric,
    temperature4 numeric,
    seat_belt smallint
);


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 SEQUENCE 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 SEQUENCE 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 SEQUENCE 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 SEQUENCE 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: hrd_customer_features_list; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.hrd_customer_features_list (
    customer_features_list_id integer NOT NULL,
    customer_id integer NOT NULL,
    feature_id integer NOT NULL,
    is_active boolean DEFAULT true NOT NULL
);


ALTER TABLE public.hrd_customer_features_list OWNER TO tsbdbadmin;

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

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


ALTER SEQUENCE public.hrd_customer_features_list_customer_features_list_id_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.hrd_customer_features_list_customer_features_list_id_seq OWNED BY public.hrd_customer_features_list.customer_features_list_id;


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

CREATE TABLE public.hrd_features (
    feature_id bigint NOT NULL,
    feature character varying,
    is_active boolean,
    is_default boolean DEFAULT false NOT NULL,
    addon_info_id integer
);


ALTER TABLE public.hrd_features OWNER TO tsbdbadmin;

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

CREATE TABLE public.hrd_hardware_feature_set (
    hardware_feature_set_id bigint NOT NULL,
    hardware_id bigint,
    feature_id bigint
);


ALTER TABLE public.hrd_hardware_feature_set OWNER TO tsbdbadmin;

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

CREATE TABLE public.hrd_vehicle_features_list (
    vehicle_features_list_id integer NOT NULL,
    vehicle_id integer NOT NULL,
    feature_id integer NOT NULL,
    feature_set_value character varying(500),
    is_active boolean DEFAULT false NOT NULL
);


ALTER TABLE public.hrd_vehicle_features_list OWNER TO tsbdbadmin;

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

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


ALTER SEQUENCE public.hrd_vehicle_features_list_vehicle_features_list_id_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.hrd_vehicle_features_list_vehicle_features_list_id_seq OWNED BY public.hrd_vehicle_features_list.vehicle_features_list_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 SEQUENCE 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: 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 SEQUENCE 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 SEQUENCE 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_alert_type_alert_type_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

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


ALTER SEQUENCE public.master_alert_type_alert_type_id_seq OWNER TO tsbdbadmin;

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

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


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

CREATE TABLE public.master_alert_type (
    alert_type_id integer DEFAULT nextval('public.master_alert_type_alert_type_id_seq'::regclass) NOT NULL,
    alert_type_alert_name character varying(250),
    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.master_alert_type OWNER TO tsbdbadmin;

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

CREATE TABLE public.master_container_type (
    container_type_id integer NOT NULL,
    container_type_name character varying
);


ALTER TABLE public.master_container_type OWNER TO tsbdbadmin;

--
-- 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
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE 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: 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 SEQUENCE public.master_parking_slot_slot_id_seq 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 SEQUENCE public.message_id_seq OWNER TO tsbdbadmin;

--
-- 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 SEQUENCE 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 SEQUENCE 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 SEQUENCE 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 SEQUENCE 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: 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 SEQUENCE public.parkingslot_geofence_id_seq 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
    MAXVALUE 117
    CACHE 1;


ALTER SEQUENCE public.pickup_change_id_seq OWNER TO tsbdbadmin;

--
-- 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 SEQUENCE 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(500),
    pickup_point_code character varying(500),
    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,
    pickup_point_eta_date date,
    pickup_point_waiting_duration integer DEFAULT 0
);


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 SEQUENCE 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 SEQUENCE 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: private_chat; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.private_chat (
    private_chat_id integer NOT NULL,
    private_chat_from integer,
    private_chat_to integer,
    private_chat_room character varying(500),
    private_chat_created_at timestamp with time zone,
    private_chat_status character varying(50),
    private_chat_from_status character varying(50),
    private_chat_to_status character varying(50),
    private_chat_last_updated timestamp with time zone
);


ALTER TABLE public.private_chat OWNER TO tsbdbadmin;

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

CREATE TABLE public.private_chat_conversation (
    conversation_id integer NOT NULL,
    conversation_from integer,
    conversation_message text,
    conversation_datetime timestamp with time zone,
    conversation_status character varying(50),
    conversation_read_status character varying(50),
    conversation_to integer,
    conversation_chat_id integer,
    replied_conversation_id bigint
);


ALTER TABLE public.private_chat_conversation OWNER TO tsbdbadmin;

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

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


ALTER SEQUENCE public.private_chat_conversation_conversation_id_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.private_chat_conversation_conversation_id_seq OWNED BY public.private_chat_conversation.conversation_id;


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

CREATE TABLE public.private_chat_files (
    file_id integer NOT NULL,
    file_path character varying(700),
    file_real_name character varying(700),
    file_created_at timestamp with time zone,
    file_status character varying(100),
    file_conversation_id integer,
    file_type character varying(300),
    file_chat_id integer
);


ALTER TABLE public.private_chat_files OWNER TO tsbdbadmin;

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

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


ALTER SEQUENCE public.private_chat_files_file_id_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.private_chat_files_file_id_seq OWNED BY public.private_chat_files.file_id;


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

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


ALTER SEQUENCE public.private_chat_private_chat_id_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.private_chat_private_chat_id_seq OWNED BY public.private_chat.private_chat_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 SEQUENCE 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_route_geofence; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

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


ALTER TABLE public.tsb_route_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 SEQUENCE 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_route_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 SEQUENCE 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),
    signal_server_imei character varying(20)
);


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 SEQUENCE 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 SEQUENCE 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 SEQUENCE 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: team_channel; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.team_channel (
    channel_id integer NOT NULL,
    channel_name character varying(500),
    channel_description text,
    channel_created_by integer,
    channel_created_at timestamp without time zone,
    channel_updated_by integer,
    is_default boolean DEFAULT false
);


ALTER TABLE public.team_channel OWNER TO tsbdbadmin;

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

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


ALTER SEQUENCE public.team_channel_channel_id_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.team_channel_channel_id_seq OWNED BY public.team_channel.channel_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 SEQUENCE 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: trips_history_trips_history_status_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

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


ALTER SEQUENCE public.trips_history_trips_history_status_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.trips_history_trips_history_status_seq OWNED BY public.tsb_trips_history.trips_history_status;


--
-- 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,
    addon_image_surveillance smallint DEFAULT 0,
    addon_video_surveillance smallint DEFAULT 0,
    addon_busassistant_role smallint DEFAULT 0,
    addon_vehicle_expense smallint DEFAULT 0,
    addon_historical_data smallint DEFAULT 0,
    addon_fleetmanager_role smallint DEFAULT 0,
    addon_temperature_sensor smallint DEFAULT 0,
    addon_ivms smallint DEFAULT 0,
    addon_tracking smallint DEFAULT 1,
    addon_over_speed smallint DEFAULT 1,
    addon_fuel_sensor smallint DEFAULT 0,
    addon_i_button smallint DEFAULT 0,
    addon_seat_belt_sensor smallint DEFAULT 0,
    addon_echo_driving smallint DEFAULT 0,
    addon_card_reader smallint DEFAULT 0,
    addon_crash_detection smallint DEFAULT 0,
    addon_excessive_idling smallint DEFAULT 0,
    addon_towing_detection smallint DEFAULT 0,
    addon_unplug_detection smallint DEFAULT 0,
    addon_immobilization smallint DEFAULT 0,
    addon_offline_map smallint DEFAULT 0,
    addon_lv_can smallint DEFAULT 0,
    addon_vehicle_inspection smallint DEFAULT 0,
    addon_vehicle_marketplace smallint DEFAULT 0,
    addon_rebranding smallint DEFAULT 0,
    addon_mobile_app_rebranding smallint DEFAULT 0,
    addon_tm_mobile_app smallint DEFAULT 1,
    addon_fm_mobile_app smallint DEFAULT 0,
    addon_dc_mobile_app smallint DEFAULT 0,
    addon_driver_mobile_app smallint DEFAULT 0,
    addon_tagvendor_mobile_app smallint DEFAULT 0,
    addon_driver_assessment smallint DEFAULT 0,
    addon_document_dispatch smallint DEFAULT 0,
    addon_module_custom_name smallint DEFAULT 0,
    addon_ghatke smallint DEFAULT 0
);


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 SEQUENCE 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),
    announcement_path character varying(300),
    format character varying(50)
);


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 SEQUENCE 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 SEQUENCE 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
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE 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 character varying(20) 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
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE 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: COLUMN tsb_attendance_anomalies.attendance_anomalies_id; Type: COMMENT; Schema: public; Owner: tsbdbadmin
--

COMMENT ON COLUMN public.tsb_attendance_anomalies.attendance_anomalies_id IS 'attendance id';


--
-- Name: COLUMN tsb_attendance_anomalies.attendance_anomalies_type; Type: COMMENT; Schema: public; Owner: tsbdbadmin
--

COMMENT ON COLUMN public.tsb_attendance_anomalies.attendance_anomalies_type IS '1-wrong location, 2-wrong vehicle, 3-wrong location and wrong vehicle';


--
-- 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_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(30),
    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),
    customer_inactive_date date,
    customer_country_code character varying(50),
    customer_distance_unit character varying(20),
    customer_fuel_unit character varying(20),
    customer_temperature_unit character varying(20)
);


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 SEQUENCE 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 SEQUENCE 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(500),
    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 SEQUENCE 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 SEQUENCE 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,
    fleat_maintenance_last_maintained_date date,
    fleat_maintenance_last_maintained_km numeric
);


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 SEQUENCE 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_desc_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

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


ALTER SEQUENCE public.tsb_holiday_holiday_desc_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.tsb_holiday_holiday_desc_seq OWNED BY public.tsb_holiday.holiday_desc;


--
-- 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 SEQUENCE 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_pickup_instant_pickup_longitude_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

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


ALTER SEQUENCE public.tsb_instant_pickup_instant_pickup_longitude_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.tsb_instant_pickup_instant_pickup_longitude_seq OWNED BY public.tsb_instant_pickup.instant_pickup_longitude;


--
-- 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_invoice_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

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


ALTER SEQUENCE public.tsb_invoice_invoice_id_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.tsb_invoice_invoice_id_seq OWNED BY public.tsb_invoice.invoice_id;


--
-- 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_invoice_item_invoice_item_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

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


ALTER SEQUENCE public.tsb_invoice_item_invoice_item_id_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.tsb_invoice_item_invoice_item_id_seq OWNED BY public.tsb_invoice_item.invoice_item_id;


--
-- 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 SEQUENCE 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; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_message (
    message_id integer DEFAULT nextval('public.message_id_seq'::regclass) 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),
    modified_on timestamp without time zone,
    is_edit boolean
);


ALTER TABLE public.tsb_message OWNER TO tsbdbadmin;

--
-- 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,
    is_active boolean DEFAULT true,
    channel_id integer
);


ALTER TABLE public.tsb_message_thread OWNER TO tsbdbadmin;

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

CREATE TABLE public.tsb_message_thread_users (
    tsb_message_thread_user_id integer NOT NULL,
    tsb_message_thread_id integer,
    user_id integer,
    last_message_read integer DEFAULT 0,
    status character varying(255) DEFAULT 'active'::character varying,
    pin_status boolean DEFAULT false,
    is_active boolean DEFAULT true
);


ALTER TABLE public.tsb_message_thread_users OWNER TO tsbdbadmin;

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

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


ALTER SEQUENCE public.tsb_message_thread_users_tsb_message_thread_user_id_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.tsb_message_thread_users_tsb_message_thread_user_id_seq OWNED BY public.tsb_message_thread_users.tsb_message_thread_user_id;


--
-- 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 SEQUENCE 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 SEQUENCE 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 SEQUENCE 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_priority_log; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_notification_priority_log (
    notification_priority_log_id integer NOT NULL,
    notification_priority_log_trip_id integer NOT NULL,
    notification_priority_log_pickuppoint_id integer NOT NULL,
    notification_priority_log_date date DEFAULT now(),
    notification_priority_log_time time without time zone
);


ALTER TABLE public.tsb_notification_priority_log OWNER TO tsbdbadmin;

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

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


ALTER SEQUENCE public.tsb_notification_priority_log_notification_priority_log_id_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.tsb_notification_priority_log_notification_priority_log_id_seq OWNED BY public.tsb_notification_priority_log.notification_priority_log_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_parking_slots smallint DEFAULT 0,
    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_buscoming smallint DEFAULT 0,
    notification_settings_geofence_entry smallint DEFAULT 0,
    notification_settings_order smallint DEFAULT 1,
    notification_settings_master_setting smallint DEFAULT 1,
    notification_settings_vehicle smallint DEFAULT 1,
    notification_settings_order_status smallint DEFAULT 1,
    notification_settings_trip_managment smallint DEFAULT 1
);


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,
    notification_settings_geofence_entry smallint DEFAULT 0,
    notification_settings_order smallint DEFAULT 1,
    notification_settings_master_setting smallint DEFAULT 1,
    notification_settings_vehicle smallint DEFAULT 1,
    notification_settings_order_status smallint DEFAULT 1,
    notification_settings_trip_managment smallint DEFAULT 1
);


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 SEQUENCE 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 SEQUENCE 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,
    notification_settings_geofence_entry smallint DEFAULT 0,
    notification_settings_order smallint DEFAULT 1,
    notification_settings_master_setting smallint DEFAULT 0,
    notification_settings_vehicle smallint DEFAULT 0,
    notification_settings_order_status smallint DEFAULT 0,
    notification_settings_trip_managment 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 SEQUENCE 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,
    notification_settings_geofence_entry smallint DEFAULT 0,
    notification_settings_order smallint DEFAULT 1,
    notification_settings_master_setting smallint DEFAULT 1,
    notification_settings_vehicle smallint DEFAULT 1,
    notification_settings_order_status smallint DEFAULT 1,
    notification_settings_trip_managment smallint DEFAULT 1
);


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 SEQUENCE 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,
    notification_role character varying
);


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 SEQUENCE 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_parking_slot; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_parking_slot (
    slot_id integer DEFAULT nextval('public.master_parking_slot_slot_id_seq'::regclass) 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),
    parking_capacity integer
);


ALTER TABLE public.tsb_parking_slot OWNER TO tsbdbadmin;

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

CREATE TABLE public.tsb_parking_vehicles (
    vehicle_id integer NOT NULL,
    parking_slot_id integer NOT NULL,
    parking_vehicle_id integer NOT NULL
);


ALTER TABLE public.tsb_parking_vehicles OWNER TO tsbdbadmin;

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

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


ALTER SEQUENCE public.tsb_parking_vehicles_parking_vehicle_id_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.tsb_parking_vehicles_parking_vehicle_id_seq OWNED BY public.tsb_parking_vehicles.parking_vehicle_id;


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

CREATE TABLE public.tsb_parkingslot_geofence (
    geofence_id integer DEFAULT nextval('public.parkingslot_geofence_id_seq'::regclass) NOT NULL,
    geofence_parkingslot_id integer,
    geofence_draw_point character varying(1000),
    geofence_details character varying(15),
    geofence_draw_type character varying(15)
);


ALTER TABLE public.tsb_parkingslot_geofence OWNER TO tsbdbadmin;

--
-- 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 SEQUENCE 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_paymant_gateway_options_paymant_gateway_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

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


ALTER SEQUENCE public.tsb_paymant_gateway_options_paymant_gateway_id_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.tsb_paymant_gateway_options_paymant_gateway_id_seq OWNED BY public.tsb_paymant_gateway.paymant_gateway_id;


--
-- 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_pickup_change; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_pickup_change (
    pickup_change_id integer DEFAULT nextval('public.pickup_change_id_seq'::regclass) 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: tsb_pickuppoints_details; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_pickuppoints_details (
    pickuppoints_details_id integer NOT NULL,
    pickup_point_id integer,
    dispatch_executive_id integer,
    vehicle_id integer,
    pickuppoints_details_route character varying(500),
    pickuppoints_details_start_kilometer_milk_run character varying(255),
    pickuppoints_details_po_no character varying(255),
    pickuppoints_details_invoice_no character varying(255),
    pickuppoints_details_item_code character varying(50),
    pickuppoints_details_quantity integer,
    pickuppoints_details_basic_value character varying(255),
    pickuppoints_details_value_with_taxes character varying(255),
    pickuppoints_details_img_item text,
    pickuppoints_details_invoice_img text,
    pickuppoints_details_get_pass_img text,
    pickuppoints_details_start_kilometer_supplier character varying(255),
    pickuppoints_details_end_kilometer_supplier character varying(255),
    pickuppoints_details_in_time_supplier text,
    pickuppoints_details_out_time_supplier text,
    pickuppoints_details_check_in_dcustomer text,
    pickuppoints_details_check_out_dcustomer text,
    pickuppoints_details_end_kilometer_based_location character varying(255),
    pickuppoints_details_kilometer_reading character varying(255),
    pickuppoints_details_received_by character varying(100),
    pickuppoints_details_vehicle_utilization character varying(255),
    pickuppoints_details_item_desc text,
    pickuppoints_details_item_remark text,
    pickuppoints_details_trip_id integer,
    dispatch_id integer,
    pickuppoints_details_vehicle_weight_img text,
    pickuppoints_details_gate_entry text,
    tsb_pickuppoints_start_odometer text,
    tsb_pickuppoints_start_odometer_img text,
    tsb_pickuppoints_end_odometer_img text,
    tsb_pickuppoints_end_odometer text,
    tsb_pickuppoints_material_collection_date text
);


ALTER TABLE public.tsb_pickuppoints_details 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
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE 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),
    push_notification_settings_field character varying(50)
);


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 SEQUENCE 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
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE 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
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE 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 SEQUENCE 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,
    settings_data_lifetime smallint DEFAULT 120,
    settings_buscoming_notification smallint DEFAULT 0,
    settings_idle_duration smallint DEFAULT 3,
    settings_historical_movement_map character varying,
    settings_historical_movement_trip_minutes numeric,
    settings_dispatch_status_auto_update boolean DEFAULT false NOT NULL,
    settings_week_start_day character varying(6) DEFAULT 'Sunday'::text,
    settings_default_loading_time_duration numeric DEFAULT 5,
    settings_default_unloading_time_duration numeric DEFAULT 5,
    settings_time_format character varying(2) DEFAULT '24'::text,
    settings_help smallint DEFAULT 0,
    settings_erp_status smallint DEFAULT 0,
    settings_erp_apikey text,
    settings_erp_url text
);


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 SEQUENCE 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 SEQUENCE 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 SEQUENCE 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 SEQUENCE 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 SEQUENCE 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_transportation_geofence; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_transportation_geofence (
    geofence_id integer NOT NULL,
    geofence_draw_point character varying(200),
    geofence_details character varying(50),
    geofence_draw_type character varying(50)
);


ALTER TABLE public.tsb_transportation_geofence OWNER TO tsbdbadmin;

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

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


ALTER SEQUENCE public.tsb_transportation_geofence_geofence_id_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.tsb_transportation_geofence_geofence_id_seq OWNED BY public.tsb_transportation_geofence.geofence_id;


--
-- 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,
    trip_user_id integer
);


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 SEQUENCE 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 SEQUENCE 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),
    user_language character varying(3) DEFAULT 'en'::character varying,
    user_theme character varying(8) DEFAULT 'light'::character varying
);


ALTER TABLE public.tsb_user OWNER TO tsbdbadmin;

--
-- 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 SEQUENCE public.user_apps_id_seq OWNER TO tsbdbadmin;

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

CREATE TABLE public.tsb_user_apps (
    user_apps_id integer DEFAULT nextval('public.user_apps_id_seq'::regclass) 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 SEQUENCE 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_desc_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

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


ALTER SEQUENCE public.tsb_vacation_vacation_desc_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.tsb_vacation_vacation_desc_seq OWNED BY public.tsb_vacation.vacation_desc;


--
-- 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 SEQUENCE 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(40),
    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 numeric DEFAULT 0,
    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_remove_date date,
    vehicle_geofence smallint DEFAULT 0,
    vehicle_group_geofence smallint DEFAULT 0,
    vehicle_transportation_geofence smallint DEFAULT 0,
    vehicle_trip_geofence smallint DEFAULT 0,
    municipality_permission_enddate date,
    municipality_permission_startdate date,
    registration_certificate character varying(350),
    insurance_copy character varying(350),
    pollution_certificate character varying(350),
    pollution_start_date date,
    pollution_end_date date,
    vehicle_image_path character varying(350),
    vehicle_assistant_id integer,
    vehicle_transportation_type integer
);


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(50),
    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 numeric,
    vehicle_activity_distance numeric,
    vehicle_activity_start_location character varying(500),
    vehicle_activity_end_location character varying(500),
    vehicle_activity_avgspeed numeric,
    vehicle_activity_maxspeed numeric,
    vehicle_activity_start_point point,
    vehicle_activity_end_point point
);


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
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE 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: 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 SEQUENCE public.vehicle_assignment_history_id_seq 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 DEFAULT nextval('public.vehicle_assignment_history_id_seq'::regclass) 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_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
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE 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
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE 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_expense_file; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_vehicle_expense_file (
    expense_file_id integer NOT NULL,
    expense_file_expense_id integer,
    expense_file_expense_type character varying(50),
    expense_file_path text
);


ALTER TABLE public.tsb_vehicle_expense_file OWNER TO tsbdbadmin;

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

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


ALTER SEQUENCE public.tsb_vehicle_expense_file_expense_file_id_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.tsb_vehicle_expense_file_expense_file_id_seq OWNED BY public.tsb_vehicle_expense_file.expense_file_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_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 SEQUENCE 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 SEQUENCE 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,
    vehicle_group_manager_id integer,
    vehicle_group_status character varying,
    vehicle_group_createat character varying
);


ALTER TABLE public.tsb_vehicle_group OWNER TO tsbdbadmin;

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

CREATE TABLE public.tsb_vehicle_group_geofence (
    vehiclegroup_geofece_id integer NOT NULL,
    vehiclegroup_geofece_group_id integer,
    vehiclegroup_geofence_draw_point character varying(200),
    vehiclegroup_geofece_details character varying(15),
    vehiclegroup_geofence_draw_type character varying(15),
    vehiclegroup_geofence_manager_id integer
);


ALTER TABLE public.tsb_vehicle_group_geofence OWNER TO tsbdbadmin;

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

CREATE TABLE public.tsb_vehicle_group_member (
    vehicle_group_member_id integer NOT NULL,
    vehicle_group_id integer,
    vehicle_group_user_id integer
);


ALTER TABLE public.tsb_vehicle_group_member OWNER TO tsbdbadmin;

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

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


ALTER SEQUENCE public.tsb_vehicle_group_member_vehicle_group_member_id_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.tsb_vehicle_group_member_vehicle_group_member_id_seq OWNED BY public.tsb_vehicle_group_member.vehicle_group_member_id;


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

CREATE TABLE public.tsb_vehicle_group_vehicle (
    vehicle_group_vehicle_id integer NOT NULL,
    vehicle_group_vehicle_group_id integer,
    vehicle_group_vehicle_manager_id integer,
    vehicle_group_vehicle_vehicle_id integer,
    vehicle_group_vehicle_status character varying
);


ALTER TABLE public.tsb_vehicle_group_vehicle OWNER TO tsbdbadmin;

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

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


ALTER SEQUENCE public.tsb_vehicle_group_vehicle_group_id_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.tsb_vehicle_group_vehicle_group_id_seq OWNED BY public.tsb_vehicle_group.vehicle_group_id;


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

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


ALTER SEQUENCE public.tsb_vehicle_group_vehicle_vehicle_group_vehicle_id_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.tsb_vehicle_group_vehicle_vehicle_group_vehicle_id_seq OWNED BY public.tsb_vehicle_group_vehicle.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_maintainance; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_vehicle_maintainance (
    maintainance_id integer NOT NULL,
    maintainance_vehicle_id integer,
    maintainance_task character varying(100),
    maintainance_kilometers_driven integer,
    maintainance_completion_date timestamp with time zone,
    maintainance_next_service_kilometers integer,
    maintainance_next_service_duration integer,
    maintainance_expense integer,
    maintainance_invoice character varying(200),
    maintainance_service_status character varying(10),
    maintainance_service_completion_type character varying(10),
    maintainance_service_mode character varying(10),
    maintainance_send_service_notification boolean,
    maintainance_service_notification_duration integer,
    maintainance_number_of_service_notification integer,
    maintainance_service_date timestamp with time zone,
    maintainance_next_service_date timestamp with time zone
);


ALTER TABLE public.tsb_vehicle_maintainance OWNER TO tsbdbadmin;

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

COMMENT ON TABLE public.tsb_vehicle_maintainance IS 'table for Vheicle maintainance sub module';


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

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


ALTER SEQUENCE public.tsb_vehicle_maintainance_maintainance_id_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.tsb_vehicle_maintainance_maintainance_id_seq OWNED BY public.tsb_vehicle_maintainance.maintainance_id;


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

CREATE TABLE public.tsb_vehicle_maintainance_settings (
    maintainance_setting_id integer NOT NULL,
    maintainanace_vehicle_id integer,
    maintainanace_service_mode character varying(10),
    maintainanace_send_service_notification boolean
);


ALTER TABLE public.tsb_vehicle_maintainance_settings OWNER TO tsbdbadmin;

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

COMMENT ON TABLE public.tsb_vehicle_maintainance_settings IS 'table for vehicle maintainance settings';


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

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


ALTER SEQUENCE public.tsb_vehicle_maintainance_settings_maintainance_setting_id_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.tsb_vehicle_maintainance_settings_maintainance_setting_id_seq OWNED BY public.tsb_vehicle_maintainance_settings.maintainance_setting_id;


--
-- 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 SEQUENCE 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
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE 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_settings; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_vehicle_settings (
    vehicle_settings_id integer NOT NULL,
    vehicle_settings_vehicle_id integer,
    vehicle_settings_vehicle_type character varying(250),
    vehicle_settings_value boolean
);


ALTER TABLE public.tsb_vehicle_settings OWNER TO tsbdbadmin;

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

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


ALTER SEQUENCE public.tsb_vehicle_settings_vehicle_settings_id_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.tsb_vehicle_settings_vehicle_settings_id_seq OWNED BY public.tsb_vehicle_settings.vehicle_settings_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_temperature_sensor; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.tsb_vehicle_temperature_sensor (
    vehicle_temperature_sensor_id integer NOT NULL,
    vehicle_temperature_sensor_vehicle_id integer,
    vehicle_temperature_sensor_minimum_running_temperature smallint,
    vehicle_temperature_sensor_maximum_running_temperature smallint,
    vehicle_temperature_sensor_minimum_parking_temperature smallint,
    vehicle_temperature_sensor_maximum_parking_temperature smallint,
    vehicle_temperature_sensor_status character varying,
    vehicle_temperature_sensor_name character varying,
    vehicle_temperature_sensor_priority smallint
);


ALTER TABLE public.tsb_vehicle_temperature_sensor OWNER TO tsbdbadmin;

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

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


ALTER SEQUENCE public.tsb_vehicle_temprature_sensor_vehicle_temperature_sensor_id_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.tsb_vehicle_temprature_sensor_vehicle_temperature_sensor_id_seq OWNED BY public.tsb_vehicle_temperature_sensor.vehicle_temperature_sensor_id;


--
-- 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(200),
    vehicle_type_description character varying(200),
    vehicle_type_status character varying(10) DEFAULT 'active'::character varying,
    vehicle_type_avg_maintenance_cost character varying(10),
    vehicle_type_avg_mileage character varying(10),
    vehicle_type_capacity character varying(50),
    vehicle_type_fuel character varying(200),
    vehicle_type_icon character varying(250),
    vehicle_type_image_path character varying(100),
    vehicle_type_total_distance_travelled character varying(10)
);


ALTER TABLE public.tsb_vehicle_type OWNER TO tsbdbadmin;

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

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


ALTER SEQUENCE public.tsb_vehiclegroup_geofence_vehiclegroup_geofece_id_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.tsb_vehiclegroup_geofence_vehiclegroup_geofece_id_seq OWNED BY public.tsb_vehicle_group_geofence.vehiclegroup_geofece_id;


--
-- 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,
    webservice_log_user_platform character varying(150)
);


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_customer_google_key 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
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE 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_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 SEQUENCE 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 SEQUENCE 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 SEQUENCE 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_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 SEQUENCE 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_expense_file_expense_file_id_seq; Type: SEQUENCE; Schema: public; Owner: tsbdbadmin
--

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


ALTER SEQUENCE public.vehicle_expense_file_expense_file_id_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.vehicle_expense_file_expense_file_id_seq OWNED BY public.tsb_vehicle_expense_file.expense_file_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 SEQUENCE 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 SEQUENCE 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 SEQUENCE 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 SEQUENCE 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 SEQUENCE 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 SEQUENCE 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 SEQUENCE 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 SEQUENCE 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: vi_inspection_category_types; Type: TABLE; Schema: public; Owner: tsbdbadmin
--

CREATE TABLE public.vi_inspection_category_types (
    inspection_category_type_id integer NOT NULL,
    inspection_category_type character varying(500) NOT NULL,
    is_active boolean DEFAULT true NOT NULL
);


ALTER TABLE public.vi_inspection_category_types OWNER TO tsbdbadmin;

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

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


ALTER SEQUENCE public.vi_inspection_category_types_inspection_category_type_id_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.vi_inspection_category_types_inspection_category_type_id_seq OWNED BY public.vi_inspection_category_types.inspection_category_type_id;


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

CREATE TABLE public.vi_vehicle_inspection_configurations (
    vehicle_inspection_configuration_id integer NOT NULL,
    vehicle_parts_category_id integer NOT NULL,
    vehicle_part character varying(500) NOT NULL,
    is_active boolean DEFAULT true NOT NULL
);


ALTER TABLE public.vi_vehicle_inspection_configurations OWNER TO tsbdbadmin;

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

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


ALTER SEQUENCE public.vi_vehicle_inspection_configu_vehicle_inspection_configurat_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.vi_vehicle_inspection_configu_vehicle_inspection_configurat_seq OWNED BY public.vi_vehicle_inspection_configurations.vehicle_inspection_configuration_id;


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

CREATE TABLE public.vi_vehicle_inspection_settings (
    vehicle_inspection_setting_id integer NOT NULL,
    vehicle_category_id integer NOT NULL,
    inspection_category_type_id integer NOT NULL,
    is_active boolean DEFAULT true NOT NULL
);


ALTER TABLE public.vi_vehicle_inspection_settings OWNER TO tsbdbadmin;

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

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


ALTER SEQUENCE public.vi_vehicle_inspection_setting_vehicle_inspection_setting_id_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.vi_vehicle_inspection_setting_vehicle_inspection_setting_id_seq OWNED BY public.vi_vehicle_inspection_settings.vehicle_inspection_setting_id;


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

CREATE TABLE public.vi_vehicle_parts_categories (
    vehicle_parts_category_id integer NOT NULL,
    vehicle_parts_category character varying(500) NOT NULL,
    vehicle_inspection_setting_id integer NOT NULL,
    is_active boolean DEFAULT true NOT NULL
);


ALTER TABLE public.vi_vehicle_parts_categories OWNER TO tsbdbadmin;

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

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


ALTER SEQUENCE public.vi_vehicle_parts_categories_vehicle_parts_category_id_seq OWNER TO tsbdbadmin;

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

ALTER SEQUENCE public.vi_vehicle_parts_categories_vehicle_parts_category_id_seq OWNED BY public.vi_vehicle_parts_categories.vehicle_parts_category_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 SEQUENCE 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: dispatch_order_items item_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.dispatch_order_items ALTER COLUMN item_id SET DEFAULT nextval('public.dispatch_order_items_item_id_seq'::regclass);


--
-- Name: gnx_alert id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_alert ALTER COLUMN id SET DEFAULT nextval('public.alert_id_seq'::regclass);


--
-- Name: gnx_alert_type alert_type_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_alert_type ALTER COLUMN alert_type_id SET DEFAULT nextval('public.gnx_alert_type_alert_type_id_seq'::regclass);


--
-- Name: gnx_can_configuration can_cfg_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_can_configuration ALTER COLUMN can_cfg_id SET DEFAULT nextval('public.gnx_can_configuration_can_cfg_id_seq'::regclass);


--
-- Name: gnx_class_mifare class_mifare_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_class_mifare ALTER COLUMN class_mifare_id SET DEFAULT nextval('public.gnx_class_mifare_gnx_mifare_id_seq'::regclass);


--
-- Name: gnx_device gnx_device_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_device ALTER COLUMN gnx_device_id SET DEFAULT nextval('public.gnx_device_gnx_device_id_seq'::regclass);


--
-- Name: gnx_ejerk ejerk_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_ejerk ALTER COLUMN ejerk_id SET DEFAULT nextval('public.gnx_ejerk_ejerk_id_seq'::regclass);


--
-- Name: gnx_frequency id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_frequency ALTER COLUMN id SET DEFAULT nextval('public.data_config_from_server_id_seq'::regclass);


--
-- Name: gnx_gprs id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_gprs ALTER COLUMN id SET DEFAULT nextval('public.sms_data_config_id_seq'::regclass);


--
-- Name: gnx_health id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_health ALTER COLUMN id SET DEFAULT nextval('public.healthstatus_id_seq'::regclass);


--
-- Name: gnx_j1939 gnx_j1939_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_j1939 ALTER COLUMN gnx_j1939_id SET DEFAULT nextval('public.gnx_j1939_gnx_j1939_id_seq'::regclass);


--
-- Name: gnx_j1939_configuration j1939_cfg_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_j1939_configuration ALTER COLUMN j1939_cfg_id SET DEFAULT nextval('public.gnx_j1939_configuration_j1939_cfg_id_seq'::regclass);


--
-- Name: gnx_java_exception exception_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_java_exception ALTER COLUMN exception_id SET DEFAULT nextval('public.java_exception_id_seq'::regclass);


--
-- Name: gnx_location id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_location ALTER COLUMN id SET DEFAULT nextval('public.location_id_seq'::regclass);


--
-- Name: gnx_mifare_card id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_mifare_card ALTER COLUMN id SET DEFAULT nextval('public.mifare_card_id_seq'::regclass);


--
-- Name: gnx_mifare_card_trip id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_mifare_card_trip ALTER COLUMN id SET DEFAULT nextval('public.mifare_card_trip_id_seq'::regclass);


--
-- Name: gnx_mifare_card_user id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_mifare_card_user ALTER COLUMN id SET DEFAULT nextval('public.mifare_card_user_id_seq'::regclass);


--
-- Name: gnx_pid gnx_pid_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_pid ALTER COLUMN gnx_pid_id SET DEFAULT nextval('public.gnx_pid_gnx_pid_id_seq'::regclass);


--
-- Name: gnx_pjerk pjerk_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_pjerk ALTER COLUMN pjerk_id SET DEFAULT nextval('public.gnx_pjerk_pjerk_id_seq'::regclass);


--
-- Name: gnx_vehicle gnx_vehicle_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_vehicle ALTER COLUMN gnx_vehicle_id SET DEFAULT nextval('public.vehicle_information_id_seq'::regclass);


--
-- Name: gnx_vls vls_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_vls ALTER COLUMN vls_id SET DEFAULT nextval('public.gnx_vls_vls_id_seq'::regclass);


--
-- Name: hrd_customer_features_list customer_features_list_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.hrd_customer_features_list ALTER COLUMN customer_features_list_id SET DEFAULT nextval('public.hrd_customer_features_list_customer_features_list_id_seq'::regclass);


--
-- Name: hrd_vehicle_features_list vehicle_features_list_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.hrd_vehicle_features_list ALTER COLUMN vehicle_features_list_id SET DEFAULT nextval('public.hrd_vehicle_features_list_vehicle_features_list_id_seq'::regclass);


--
-- Name: master_location location_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.master_location ALTER COLUMN location_id SET DEFAULT nextval('public.master_location_location_id_seq'::regclass);


--
-- Name: private_chat private_chat_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.private_chat ALTER COLUMN private_chat_id SET DEFAULT nextval('public.private_chat_private_chat_id_seq'::regclass);


--
-- Name: private_chat_conversation conversation_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.private_chat_conversation ALTER COLUMN conversation_id SET DEFAULT nextval('public.private_chat_conversation_conversation_id_seq'::regclass);


--
-- Name: private_chat_files file_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.private_chat_files ALTER COLUMN file_id SET DEFAULT nextval('public.private_chat_files_file_id_seq'::regclass);


--
-- Name: team_channel channel_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.team_channel ALTER COLUMN channel_id SET DEFAULT nextval('public.team_channel_channel_id_seq'::regclass);


--
-- Name: tsb_alert_comments alert_comments_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_alert_comments ALTER COLUMN alert_comments_id SET DEFAULT nextval('public.tsb_alert_comments_alert_comments_id_seq'::regclass);


--
-- Name: tsb_announcement announcement_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_announcement ALTER COLUMN announcement_id SET DEFAULT nextval('public.tsb_announcement_announcement_id_seq'::regclass);


--
-- Name: tsb_apps apps_customer_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_apps ALTER COLUMN apps_customer_id SET DEFAULT nextval('public.tsb_apps_apps_customer_d_seq'::regclass);


--
-- Name: tsb_area area_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_area ALTER COLUMN area_id SET DEFAULT nextval('public.tsb_area_area_id_seq'::regclass);


--
-- Name: tsb_area_geofence geofence_area_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_area_geofence ALTER COLUMN geofence_area_id SET DEFAULT nextval('public.tsb_area_geofence_geofence_area_id_seq'::regclass);


--
-- Name: tsb_attendance_user attendance_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_attendance_user ALTER COLUMN attendance_id SET DEFAULT nextval('public.user_attendance_id_seq'::regclass);


--
-- Name: tsb_audio audio_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_audio ALTER COLUMN audio_id SET DEFAULT nextval('public.audio_management_id_seq'::regclass);


--
-- Name: tsb_customer customer_timezone_utc_offset; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_customer ALTER COLUMN customer_timezone_utc_offset SET DEFAULT nextval('public.tsb_customer_customer_timezone_utc_offset_seq'::regclass);


--
-- Name: tsb_customer_geofence geofence_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_customer_geofence ALTER COLUMN geofence_id SET DEFAULT nextval('public.tsb_customer_geofence_geofence_id_seq'::regclass);


--
-- Name: tsb_driver driver_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_driver ALTER COLUMN driver_id SET DEFAULT nextval('public.driver_id_seq'::regclass);


--
-- Name: tsb_email_driver email_driver_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_email_driver ALTER COLUMN email_driver_id SET DEFAULT nextval('public.email_driver_email_driver_id_seq'::regclass);


--
-- Name: tsb_email_helper email_helper_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_email_helper ALTER COLUMN email_helper_id SET DEFAULT nextval('public.tsb_email_helper_email_helper_id_seq'::regclass);


--
-- Name: tsb_email_staff email_staff_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_email_staff ALTER COLUMN email_staff_id SET DEFAULT nextval('public.tsb_email_staff_email_staff_id_seq'::regclass);


--
-- Name: tsb_fleat_maintenance fleat_maintenance_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_fleat_maintenance ALTER COLUMN fleat_maintenance_id SET DEFAULT nextval('public.tsb_fleat_maintenance_fleat_maintenance_id_seq'::regclass);


--
-- Name: tsb_holiday holiday_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_holiday ALTER COLUMN holiday_id SET DEFAULT nextval('public.tsb_holiday_holiday_id_seq'::regclass);


--
-- Name: tsb_instant_pickup instant_pickup_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_instant_pickup ALTER COLUMN instant_pickup_id SET DEFAULT nextval('public.pickup_unasigned_id_seq'::regclass);


--
-- Name: tsb_logo logo_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_logo ALTER COLUMN logo_id SET DEFAULT nextval('public.logo_id_seq'::regclass);


--
-- Name: tsb_mailqueue mailqueue_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_mailqueue ALTER COLUMN mailqueue_id SET DEFAULT nextval('public.tsb_mailqueue_mailqueue_id_seq'::regclass);


--
-- Name: tsb_message_thread message_thread_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_message_thread ALTER COLUMN message_thread_id SET DEFAULT nextval('public.tsb_message_tread_message_thread_id_seq'::regclass);


--
-- Name: tsb_message_thread_users tsb_message_thread_user_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_message_thread_users ALTER COLUMN tsb_message_thread_user_id SET DEFAULT nextval('public.tsb_message_thread_users_tsb_message_thread_user_id_seq'::regclass);


--
-- Name: tsb_notification notification_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_notification ALTER COLUMN notification_id SET DEFAULT nextval('public.tsb_notification_notification_id_seq'::regclass);


--
-- Name: tsb_notification_driver notification_driver_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_notification_driver ALTER COLUMN notification_driver_id SET DEFAULT nextval('public.tsb_notification_driver_notification_driver_id_seq'::regclass);


--
-- Name: tsb_notification_log notification_log_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_notification_log ALTER COLUMN notification_log_id SET DEFAULT nextval('public.notification_log_id_seq'::regclass);


--
-- Name: tsb_notification_priority_log notification_priority_log_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_notification_priority_log ALTER COLUMN notification_priority_log_id SET DEFAULT nextval('public.tsb_notification_priority_log_notification_priority_log_id_seq'::regclass);


--
-- Name: tsb_notification_settings notification_settings_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_notification_settings ALTER COLUMN notification_settings_id SET DEFAULT nextval('public.tsb_notification_settings_notification_settings_id_seq'::regclass);


--
-- Name: tsb_notification_settings_email notification_settings_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_notification_settings_email ALTER COLUMN notification_settings_id SET DEFAULT nextval('public.tsb_notification_settings_notification_settings_email_id_seq'::regclass);


--
-- Name: tsb_notification_settings_sms notification_settings_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_notification_settings_sms ALTER COLUMN notification_settings_id SET DEFAULT nextval('public.tsb_notification_settings_notification_settings_sms_id_seq'::regclass);


--
-- Name: tsb_notification_settings_whatsapp notification_settings_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_notification_settings_whatsapp ALTER COLUMN notification_settings_id SET DEFAULT nextval('public.tsb_notification_settings_notification_settings_whatsapp_id_seq'::regclass);


--
-- Name: tsb_notification_tm notification_tm_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_notification_tm ALTER COLUMN notification_tm_id SET DEFAULT nextval('public.tsb_notification_tm_notification_tm_id_seq'::regclass);


--
-- Name: tsb_parking_vehicles parking_vehicle_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_parking_vehicles ALTER COLUMN parking_vehicle_id SET DEFAULT nextval('public.tsb_parking_vehicles_parking_vehicle_id_seq'::regclass);


--
-- Name: tsb_passenger passenger_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_passenger ALTER COLUMN passenger_id SET DEFAULT nextval('public.tsb_passenger_passenger_id_seq'::regclass);


--
-- Name: tsb_pickup pickup_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_pickup ALTER COLUMN pickup_id SET DEFAULT nextval('public.pickup_details_id_seq'::regclass);


--
-- Name: tsb_pickup_point pickup_point_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_pickup_point ALTER COLUMN pickup_point_id SET DEFAULT nextval('public.pickup_point_master_id_seq'::regclass);


--
-- Name: tsb_planner_routing routing_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_planner_routing ALTER COLUMN routing_id SET DEFAULT nextval('public.tsb_planner_routing_routing_id_seq'::regclass);


--
-- Name: tsb_push_notification push_notification_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_push_notification ALTER COLUMN push_notification_id SET DEFAULT nextval('public.tsb_push_notification_push_notification_id_seq'::regclass);


--
-- Name: tsb_rash_drive rash_drive_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_rash_drive ALTER COLUMN rash_drive_id SET DEFAULT nextval('public.rash_drive_id_seq'::regclass);


--
-- Name: tsb_rash_drive_speed_limit speed_limit_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_rash_drive_speed_limit ALTER COLUMN speed_limit_id SET DEFAULT nextval('public.tsb_rash_drive_speed_limit_speed_limit_id_seq'::regclass);


--
-- Name: tsb_reports_access_log reports_access_log_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_reports_access_log ALTER COLUMN reports_access_log_id SET DEFAULT nextval('public.tsb_reports_access_log_reports_access_log_id_seq'::regclass);


--
-- Name: tsb_route route_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_route ALTER COLUMN route_id SET DEFAULT nextval('public.route_master_id_seq'::regclass);


--
-- Name: tsb_route_geofence geofence_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_route_geofence ALTER COLUMN geofence_id SET DEFAULT nextval('public.route_map_border_id_seq'::regclass);


--
-- Name: tsb_routing routing_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_routing ALTER COLUMN routing_id SET DEFAULT nextval('public.tsb_routing_routing_id_seq'::regclass);


--
-- Name: tsb_shift shift_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_shift ALTER COLUMN shift_id SET DEFAULT nextval('public.tsb_shift_shift_id_seq'::regclass);


--
-- Name: tsb_signal_server signal_server_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_signal_server ALTER COLUMN signal_server_id SET DEFAULT nextval('public.signal_server_signal_server_id_seq'::regclass);


--
-- Name: tsb_sms_log sms_log_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_sms_log ALTER COLUMN sms_log_id SET DEFAULT nextval('public.sms_log_id_seq'::regclass);


--
-- Name: tsb_snap snap_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_snap ALTER COLUMN snap_id SET DEFAULT nextval('public.tsb_snap_snap_id_seq'::regclass);


--
-- Name: tsb_snap_log snap_log_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_snap_log ALTER COLUMN snap_log_id SET DEFAULT nextval('public.tsb_snap_log_snap_log_id_seq'::regclass);


--
-- Name: tsb_team team_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_team ALTER COLUMN team_id SET DEFAULT nextval('public.tsb_team_team_id_seq'::regclass);


--
-- Name: tsb_temp_autorouting temp_routing_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_temp_autorouting ALTER COLUMN temp_routing_id SET DEFAULT nextval('public.tsb_temp_autorouting_temp_routing_id_seq'::regclass);


--
-- Name: tsb_transportation_geofence geofence_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_transportation_geofence ALTER COLUMN geofence_id SET DEFAULT nextval('public.tsb_transportation_geofence_geofence_id_seq'::regclass);


--
-- Name: tsb_trip trip_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_trip ALTER COLUMN trip_id SET DEFAULT nextval('public.vehicle_route_id_seq'::regclass);


--
-- Name: tsb_trip_geofence geofence_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_trip_geofence ALTER COLUMN geofence_id SET DEFAULT nextval('public.tsb_trip_geofence_geofence_id_seq'::regclass);


--
-- Name: tsb_trip_repeatdays trip_repeat_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_trip_repeatdays ALTER COLUMN trip_repeat_id SET DEFAULT nextval('public.tsb_trip_repeatdays_trip_repeat_id_seq'::regclass);


--
-- Name: tsb_trips_history trips_history_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_trips_history ALTER COLUMN trips_history_id SET DEFAULT nextval('public.trips_history_trips_history_id_seq'::regclass);


--
-- Name: tsb_user user_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_user ALTER COLUMN user_id SET DEFAULT nextval('public.user_id_seq'::regclass);


--
-- Name: tsb_user_card card_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_user_card ALTER COLUMN card_id SET DEFAULT nextval('public.tsb_user_card_card_id_seq'::regclass);


--
-- Name: tsb_vacation vacation_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vacation ALTER COLUMN vacation_id SET DEFAULT nextval('public.tsb_vacation_vacation_id_seq'::regclass);


--
-- Name: tsb_vehicle vehicle_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle ALTER COLUMN vehicle_id SET DEFAULT nextval('public.vehicle_id_seq'::regclass);


--
-- Name: tsb_vehicle_accessory accessory_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_accessory ALTER COLUMN accessory_id SET DEFAULT nextval('public.vehicle_accessory_id_seq'::regclass);


--
-- Name: tsb_vehicle_activity vehicle_activity_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_activity ALTER COLUMN vehicle_activity_id SET DEFAULT nextval('public.tsb_vehicle_activity_vehicle_activity_id_seq'::regclass);


--
-- Name: tsb_vehicle_assignment vehicle_assignment_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_assignment ALTER COLUMN vehicle_assignment_id SET DEFAULT nextval('public.vehicle_assignment_id_seq'::regclass);


--
-- Name: tsb_vehicle_data_syncrequest syncrequest_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_data_syncrequest ALTER COLUMN syncrequest_id SET DEFAULT nextval('public.tsb_vehicle_data_syncrequest_syncrequest_id_seq'::regclass);


--
-- Name: tsb_vehicle_data_usage data_usage_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_data_usage ALTER COLUMN data_usage_id SET DEFAULT nextval('public.tsb_vehicle_data_usage_data_usage_id_seq'::regclass);


--
-- Name: tsb_vehicle_expense_file expense_file_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_expense_file ALTER COLUMN expense_file_id SET DEFAULT nextval('public.vehicle_expense_file_expense_file_id_seq'::regclass);


--
-- Name: tsb_vehicle_fine fine_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_fine ALTER COLUMN fine_id SET DEFAULT nextval('public.vehicle_fine_id_seq'::regclass);


--
-- Name: tsb_vehicle_fuel vehicle_fuel_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_fuel ALTER COLUMN vehicle_fuel_id SET DEFAULT nextval('public.tsb_vehicle_fuel_vehicle_fuel_id_seq'::regclass);


--
-- Name: tsb_vehicle_geofence geofence_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_geofence ALTER COLUMN geofence_id SET DEFAULT nextval('public.tsb_vehicle_geofence_geofence_id_seq'::regclass);


--
-- Name: tsb_vehicle_group vehicle_group_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_group ALTER COLUMN vehicle_group_id SET DEFAULT nextval('public.tsb_vehicle_group_vehicle_group_id_seq'::regclass);


--
-- Name: tsb_vehicle_group_geofence vehiclegroup_geofece_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_group_geofence ALTER COLUMN vehiclegroup_geofece_id SET DEFAULT nextval('public.tsb_vehiclegroup_geofence_vehiclegroup_geofece_id_seq'::regclass);


--
-- Name: tsb_vehicle_group_member vehicle_group_member_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_group_member ALTER COLUMN vehicle_group_member_id SET DEFAULT nextval('public.tsb_vehicle_group_member_vehicle_group_member_id_seq'::regclass);


--
-- Name: tsb_vehicle_group_vehicle vehicle_group_vehicle_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_group_vehicle ALTER COLUMN vehicle_group_vehicle_id SET DEFAULT nextval('public.tsb_vehicle_group_vehicle_vehicle_group_vehicle_id_seq'::regclass);


--
-- Name: tsb_vehicle_ignition_data ignition_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_ignition_data ALTER COLUMN ignition_id SET DEFAULT nextval('public.vehicle_ignition_id_seq'::regclass);


--
-- Name: tsb_vehicle_incident incident_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_incident ALTER COLUMN incident_id SET DEFAULT nextval('public.vehicle_incident_id_seq'::regclass);


--
-- Name: tsb_vehicle_maintainance maintainance_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_maintainance ALTER COLUMN maintainance_id SET DEFAULT nextval('public.tsb_vehicle_maintainance_maintainance_id_seq'::regclass);


--
-- Name: tsb_vehicle_maintainance_settings maintainance_setting_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_maintainance_settings ALTER COLUMN maintainance_setting_id SET DEFAULT nextval('public.tsb_vehicle_maintainance_settings_maintainance_setting_id_seq'::regclass);


--
-- Name: tsb_vehicle_parking parking_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_parking ALTER COLUMN parking_id SET DEFAULT nextval('public.tsb_vehicle_parking_seq'::regclass);


--
-- Name: tsb_vehicle_run_summary vehicle_run_summary_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_run_summary ALTER COLUMN vehicle_run_summary_id SET DEFAULT nextval('public.tsb_vehicle_run_summary_vehicle_run_summary_id_seq'::regclass);


--
-- Name: tsb_vehicle_settings vehicle_settings_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_settings ALTER COLUMN vehicle_settings_id SET DEFAULT nextval('public.tsb_vehicle_settings_vehicle_settings_id_seq'::regclass);


--
-- Name: tsb_vehicle_spareparts spareparts_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_spareparts ALTER COLUMN spareparts_id SET DEFAULT nextval('public.vehicle_spareparts_id_seq'::regclass);


--
-- Name: tsb_vehicle_temperature_sensor vehicle_temperature_sensor_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_temperature_sensor ALTER COLUMN vehicle_temperature_sensor_id SET DEFAULT nextval('public.tsb_vehicle_temprature_sensor_vehicle_temperature_sensor_id_seq'::regclass);


--
-- Name: tsb_vehicle_type vehicle_type_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_type ALTER COLUMN vehicle_type_id SET DEFAULT nextval('public.vehicle_type_id_seq'::regclass);


--
-- Name: tsb_webservice_log webservice_log_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_webservice_log ALTER COLUMN webservice_log_id SET DEFAULT nextval('public.webservice_log_id_seq'::regclass);


--
-- Name: usage_statistics statistics_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.usage_statistics ALTER COLUMN statistics_id SET DEFAULT nextval('public.usage_statistics_statistics_id_seq'::regclass);


--
-- Name: vi_inspection_category_types inspection_category_type_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.vi_inspection_category_types ALTER COLUMN inspection_category_type_id SET DEFAULT nextval('public.vi_inspection_category_types_inspection_category_type_id_seq'::regclass);


--
-- Name: vi_vehicle_inspection_configurations vehicle_inspection_configuration_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.vi_vehicle_inspection_configurations ALTER COLUMN vehicle_inspection_configuration_id SET DEFAULT nextval('public.vi_vehicle_inspection_configu_vehicle_inspection_configurat_seq'::regclass);


--
-- Name: vi_vehicle_inspection_settings vehicle_inspection_setting_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.vi_vehicle_inspection_settings ALTER COLUMN vehicle_inspection_setting_id SET DEFAULT nextval('public.vi_vehicle_inspection_setting_vehicle_inspection_setting_id_seq'::regclass);


--
-- Name: vi_vehicle_parts_categories vehicle_parts_category_id; Type: DEFAULT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.vi_vehicle_parts_categories ALTER COLUMN vehicle_parts_category_id SET DEFAULT nextval('public.vi_vehicle_parts_categories_vehicle_parts_category_id_seq'::regclass);


--
-- Name: gnx_alert alert_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_alert
    ADD CONSTRAINT alert_pkey PRIMARY KEY (id);


--
-- Name: tsb_audio audio_management_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_audio
    ADD CONSTRAINT audio_management_pkey PRIMARY KEY (audio_id);


--
-- Name: hrd_customer_features_list customer_features_list_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.hrd_customer_features_list
    ADD CONSTRAINT customer_features_list_pkey PRIMARY KEY (customer_features_list_id);


--
-- Name: tsb_customer customer_id; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_customer
    ADD CONSTRAINT customer_id UNIQUE (customer_id);


--
-- Name: gnx_frequency data_config_from_server_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_frequency
    ADD CONSTRAINT data_config_from_server_pkey PRIMARY KEY (id);


--
-- Name: gnx_digital_input_output device_digital_input_output_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_digital_input_output
    ADD CONSTRAINT device_digital_input_output_pkey PRIMARY KEY (id);


--
-- Name: dispatch_order_items dispatch_order_items_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.dispatch_order_items
    ADD CONSTRAINT dispatch_order_items_pkey PRIMARY KEY (item_id);


--
-- Name: tsb_driver driver_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_driver
    ADD CONSTRAINT driver_pkey PRIMARY KEY (driver_id);


--
-- Name: tsb_email_driver email_driver_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_email_driver
    ADD CONSTRAINT email_driver_pkey PRIMARY KEY (email_driver_id);


--
-- Name: gnx_alert_type gnx_alert_type_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_alert_type
    ADD CONSTRAINT gnx_alert_type_pkey PRIMARY KEY (alert_type_id);


--
-- Name: gnx_can_configuration gnx_can_configuration_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_can_configuration
    ADD CONSTRAINT gnx_can_configuration_pkey PRIMARY KEY (can_cfg_id);


--
-- Name: gnx_class_mifare gnx_class_mifare_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_class_mifare
    ADD CONSTRAINT gnx_class_mifare_pkey PRIMARY KEY (class_mifare_id);


--
-- Name: gnx_ejerk gnx_ejerk_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_ejerk
    ADD CONSTRAINT gnx_ejerk_pkey PRIMARY KEY (ejerk_id);


--
-- Name: gnx_hardware_type gnx_hardware_type_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_hardware_type
    ADD CONSTRAINT gnx_hardware_type_pkey PRIMARY KEY (hardware_id);


--
-- Name: gnx_j1939_configuration gnx_j1939_configuration_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_j1939_configuration
    ADD CONSTRAINT gnx_j1939_configuration_pkey PRIMARY KEY (j1939_cfg_id);


--
-- Name: gnx_j1939 gnx_j1939_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_j1939
    ADD CONSTRAINT gnx_j1939_pkey PRIMARY KEY (gnx_j1939_id);


--
-- Name: gnx_live_location gnx_live_location_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_live_location
    ADD CONSTRAINT gnx_live_location_pkey PRIMARY KEY (id);


--
-- Name: gnx_pid gnx_pid_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_pid
    ADD CONSTRAINT gnx_pid_pkey PRIMARY KEY (gnx_pid_id);


--
-- Name: gnx_pjerk gnx_pjerk_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_pjerk
    ADD CONSTRAINT gnx_pjerk_pkey PRIMARY KEY (pjerk_id);


--
-- Name: gnx_vls gnx_vls_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_vls
    ADD CONSTRAINT gnx_vls_pkey PRIMARY KEY (vls_id);


--
-- Name: hrd_hardware_feature_set hardware_feature_set_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.hrd_hardware_feature_set
    ADD CONSTRAINT hardware_feature_set_pkey PRIMARY KEY (hardware_feature_set_id);


--
-- Name: gnx_health healthstatus_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_health
    ADD CONSTRAINT healthstatus_pkey PRIMARY KEY (id);


--
-- Name: tsb_vehicle_ignition_data ignition_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_ignition_data
    ADD CONSTRAINT ignition_pkey PRIMARY KEY (ignition_id);


--
-- Name: gnx_java_exception java_exception_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_java_exception
    ADD CONSTRAINT java_exception_pkey PRIMARY KEY (exception_id);


--
-- Name: gnx_location location_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_location
    ADD CONSTRAINT location_pkey PRIMARY KEY (id);


--
-- Name: tsb_logo logo_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_logo
    ADD CONSTRAINT logo_pkey PRIMARY KEY (logo_id);


--
-- Name: master_alert_type master_alert_type_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.master_alert_type
    ADD CONSTRAINT master_alert_type_pkey PRIMARY KEY (alert_type_id);


--
-- Name: master_location master_location_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.master_location
    ADD CONSTRAINT master_location_pkey PRIMARY KEY (location_id);


--
-- Name: tsb_parking_slot master_parking_slot_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_parking_slot
    ADD CONSTRAINT master_parking_slot_pkey PRIMARY KEY (slot_id);


--
-- Name: gnx_mifare_card mifare_card_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_mifare_card
    ADD CONSTRAINT mifare_card_pkey PRIMARY KEY (id);


--
-- Name: gnx_mifare_card_trip mifare_card_trip_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_mifare_card_trip
    ADD CONSTRAINT mifare_card_trip_pkey PRIMARY KEY (id);


--
-- Name: gnx_mifare_card_user mifare_card_user_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_mifare_card_user
    ADD CONSTRAINT mifare_card_user_pkey PRIMARY KEY (id);


--
-- Name: tsb_pickup pickup_details_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_pickup
    ADD CONSTRAINT pickup_details_pkey PRIMARY KEY (pickup_id);


--
-- Name: tsb_pickup_point pickup_point_master_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_pickup_point
    ADD CONSTRAINT pickup_point_master_pkey PRIMARY KEY (pickup_point_id);


--
-- Name: tsb_instant_pickup pickup_unasigned_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_instant_pickup
    ADD CONSTRAINT pickup_unasigned_pkey PRIMARY KEY (instant_pickup_id);


--
-- Name: private_chat_conversation private_chat_conversation_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.private_chat_conversation
    ADD CONSTRAINT private_chat_conversation_pkey PRIMARY KEY (conversation_id);


--
-- Name: private_chat_files private_chat_files_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.private_chat_files
    ADD CONSTRAINT private_chat_files_pkey PRIMARY KEY (file_id);


--
-- Name: private_chat private_chat_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.private_chat
    ADD CONSTRAINT private_chat_pkey PRIMARY KEY (private_chat_id);


--
-- Name: tsb_route_geofence route_map_border_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_route_geofence
    ADD CONSTRAINT route_map_border_pkey PRIMARY KEY (geofence_id);


--
-- Name: tsb_route route_master_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_route
    ADD CONSTRAINT route_master_pkey PRIMARY KEY (route_id);


--
-- Name: tsb_signal_server signal_server_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_signal_server
    ADD CONSTRAINT signal_server_pkey PRIMARY KEY (signal_server_id);


--
-- Name: gnx_gprs sms_data_config_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_gprs
    ADD CONSTRAINT sms_data_config_pkey PRIMARY KEY (id);


--
-- Name: tsb_sms_log sms_log_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_sms_log
    ADD CONSTRAINT sms_log_pkey PRIMARY KEY (sms_log_id);


--
-- Name: team_channel team_channel_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.team_channel
    ADD CONSTRAINT team_channel_pkey PRIMARY KEY (channel_id);


--
-- Name: tsb_trips_history trips_history_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_trips_history
    ADD CONSTRAINT trips_history_pkey PRIMARY KEY (trips_history_id);


--
-- Name: tsb_addon tsb_addon_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_addon
    ADD CONSTRAINT tsb_addon_pkey PRIMARY KEY (addon_customer_id);


--
-- Name: tsb_alert_comments tsb_alert_comments_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_alert_comments
    ADD CONSTRAINT tsb_alert_comments_pkey PRIMARY KEY (alert_comments_id);


--
-- Name: tsb_announcement tsb_announcement_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_announcement
    ADD CONSTRAINT tsb_announcement_pkey PRIMARY KEY (announcement_id);


--
-- Name: tsb_apps tsb_apps_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_apps
    ADD CONSTRAINT tsb_apps_pkey PRIMARY KEY (apps_customer_id);


--
-- Name: tsb_area_geofence tsb_area_geofence_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_area_geofence
    ADD CONSTRAINT tsb_area_geofence_pkey PRIMARY KEY (geofence_area_id);


--
-- Name: tsb_area tsb_area_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_area
    ADD CONSTRAINT tsb_area_pkey PRIMARY KEY (area_id);


--
-- Name: tsb_attendance_anomalies tsb_attendance_anomalies_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_attendance_anomalies
    ADD CONSTRAINT tsb_attendance_anomalies_pkey PRIMARY KEY (attendance_anomalies_id);


--
-- Name: tsb_attendance_user tsb_attendance_user_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_attendance_user
    ADD CONSTRAINT tsb_attendance_user_pkey PRIMARY KEY (attendance_id);


--
-- Name: tsb_cctv tsb_cctv_cctv_imei_key; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_cctv
    ADD CONSTRAINT tsb_cctv_cctv_imei_key UNIQUE (cctv_imei);


--
-- Name: tsb_cctv tsb_cctv_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_cctv
    ADD CONSTRAINT tsb_cctv_pkey PRIMARY KEY (cctv_imei);


--
-- Name: tsb_customer_geofence tsb_customer_geofence_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_customer_geofence
    ADD CONSTRAINT tsb_customer_geofence_pkey PRIMARY KEY (geofence_id);


--
-- Name: tsb_customer tsb_customer_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_customer
    ADD CONSTRAINT tsb_customer_pkey PRIMARY KEY (customer_id);


--
-- Name: tsb_email_helper tsb_email_helper_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_email_helper
    ADD CONSTRAINT tsb_email_helper_pkey PRIMARY KEY (email_helper_id);


--
-- Name: tsb_email_staff tsb_email_staff_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_email_staff
    ADD CONSTRAINT tsb_email_staff_pkey PRIMARY KEY (email_staff_id);


--
-- Name: hrd_features tsb_feature_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.hrd_features
    ADD CONSTRAINT tsb_feature_pkey PRIMARY KEY (feature_id);


--
-- Name: tsb_fleat_maintenance tsb_fleat_maintenance_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_fleat_maintenance
    ADD CONSTRAINT tsb_fleat_maintenance_pkey PRIMARY KEY (fleat_maintenance_id);


--
-- Name: tsb_holiday tsb_holiday_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_holiday
    ADD CONSTRAINT tsb_holiday_pkey PRIMARY KEY (holiday_id);


--
-- Name: tsb_instant_repeat tsb_instant_repeat_instant_repeat_pickup_id_key; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_instant_repeat
    ADD CONSTRAINT tsb_instant_repeat_instant_repeat_pickup_id_key UNIQUE (instant_repeat_pickup_id);


--
-- Name: tsb_instant_repeat tsb_instant_repeat_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_instant_repeat
    ADD CONSTRAINT tsb_instant_repeat_pkey PRIMARY KEY (instant_repeat_pickup_id);


--
-- Name: tsb_invoice_item tsb_invoice_item_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_invoice_item
    ADD CONSTRAINT tsb_invoice_item_pkey PRIMARY KEY (invoice_item_id);


--
-- Name: tsb_invoice tsb_invoice_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_invoice
    ADD CONSTRAINT tsb_invoice_pkey PRIMARY KEY (invoice_id);


--
-- Name: tsb_mailqueue tsb_mailqueue_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_mailqueue
    ADD CONSTRAINT tsb_mailqueue_pkey PRIMARY KEY (mailqueue_id);


--
-- Name: tsb_message tsb_message_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_message
    ADD CONSTRAINT tsb_message_pkey PRIMARY KEY (message_id);


--
-- Name: tsb_message_relation tsb_message_relation_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_message_relation
    ADD CONSTRAINT tsb_message_relation_pkey PRIMARY KEY (message_relation_master_message_id);


--
-- Name: tsb_message_thread_users tsb_message_thread_users_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_message_thread_users
    ADD CONSTRAINT tsb_message_thread_users_pkey PRIMARY KEY (tsb_message_thread_user_id);


--
-- Name: tsb_message_thread tsb_message_tread_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_message_thread
    ADD CONSTRAINT tsb_message_tread_pkey PRIMARY KEY (message_thread_id);


--
-- Name: tsb_notification_driver tsb_notification_driver_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_notification_driver
    ADD CONSTRAINT tsb_notification_driver_pkey PRIMARY KEY (notification_driver_id);


--
-- Name: tsb_notification_log tsb_notification_log_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_notification_log
    ADD CONSTRAINT tsb_notification_log_pkey PRIMARY KEY (notification_log_id);


--
-- Name: tsb_notification tsb_notification_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_notification
    ADD CONSTRAINT tsb_notification_pkey PRIMARY KEY (notification_id);


--
-- Name: tsb_notification_priority_log tsb_notification_priority_log_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_notification_priority_log
    ADD CONSTRAINT tsb_notification_priority_log_pkey PRIMARY KEY (notification_priority_log_id);


--
-- Name: tsb_notification_settings_email tsb_notification_settings_email_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_notification_settings_email
    ADD CONSTRAINT tsb_notification_settings_email_pkey PRIMARY KEY (notification_settings_id);


--
-- Name: tsb_notification_settings tsb_notification_settings_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_notification_settings
    ADD CONSTRAINT tsb_notification_settings_pkey PRIMARY KEY (notification_settings_id);


--
-- Name: tsb_notification_settings_sms tsb_notification_settings_sms_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_notification_settings_sms
    ADD CONSTRAINT tsb_notification_settings_sms_pkey PRIMARY KEY (notification_settings_id);


--
-- Name: tsb_notification_settings_whatsapp tsb_notification_settings_whatsapp_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_notification_settings_whatsapp
    ADD CONSTRAINT tsb_notification_settings_whatsapp_pkey PRIMARY KEY (notification_settings_id);


--
-- Name: tsb_notification_tm tsb_notification_tm_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_notification_tm
    ADD CONSTRAINT tsb_notification_tm_pkey PRIMARY KEY (notification_tm_id);


--
-- Name: tsb_parking_vehicles tsb_parking_vehicles_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_parking_vehicles
    ADD CONSTRAINT tsb_parking_vehicles_pkey PRIMARY KEY (parking_vehicle_id);


--
-- Name: tsb_parkingslot_geofence tsb_parkingslot_geofence_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_parkingslot_geofence
    ADD CONSTRAINT tsb_parkingslot_geofence_pkey PRIMARY KEY (geofence_id);


--
-- Name: tsb_parkingslot_suggestions tsb_parkingslot_suggestions_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_parkingslot_suggestions
    ADD CONSTRAINT tsb_parkingslot_suggestions_pkey PRIMARY KEY (suggested_slot_id);


--
-- Name: tsb_passenger tsb_passenger_passenger_mob_key; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_passenger
    ADD CONSTRAINT tsb_passenger_passenger_mob_key UNIQUE (passenger_mob);


--
-- Name: tsb_passenger tsb_passenger_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_passenger
    ADD CONSTRAINT tsb_passenger_pkey PRIMARY KEY (passenger_id);


--
-- Name: tsb_paymant_gateway tsb_paymant_gateway_options_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_paymant_gateway
    ADD CONSTRAINT tsb_paymant_gateway_options_pkey PRIMARY KEY (paymant_gateway_id);


--
-- Name: tsb_payment tsb_payment_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_payment
    ADD CONSTRAINT tsb_payment_pkey PRIMARY KEY (payment_id);


--
-- Name: tsb_pickup_change tsb_pickup_change_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_pickup_change
    ADD CONSTRAINT tsb_pickup_change_pkey PRIMARY KEY (pickup_change_id);


--
-- Name: tsb_planner_routing tsb_planner_routing_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_planner_routing
    ADD CONSTRAINT tsb_planner_routing_pkey PRIMARY KEY (routing_id);


--
-- Name: tsb_push_notification tsb_push_notification_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_push_notification
    ADD CONSTRAINT tsb_push_notification_pkey PRIMARY KEY (push_notification_id);


--
-- Name: tsb_rash_drive tsb_rash_drive_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_rash_drive
    ADD CONSTRAINT tsb_rash_drive_pkey PRIMARY KEY (rash_drive_id);


--
-- Name: tsb_rash_drive_speed_limit tsb_rash_drive_speed_limit_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_rash_drive_speed_limit
    ADD CONSTRAINT tsb_rash_drive_speed_limit_pkey PRIMARY KEY (speed_limit_id);


--
-- Name: tsb_reports_access_log tsb_reports_access_log_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_reports_access_log
    ADD CONSTRAINT tsb_reports_access_log_pkey PRIMARY KEY (reports_access_log_id);


--
-- Name: tsb_routing tsb_routing_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_routing
    ADD CONSTRAINT tsb_routing_pkey PRIMARY KEY (routing_id);


--
-- Name: tsb_settings tsb_settings_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_settings
    ADD CONSTRAINT tsb_settings_pkey PRIMARY KEY (settings_customer_id);


--
-- Name: tsb_shift tsb_shift_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_shift
    ADD CONSTRAINT tsb_shift_pkey PRIMARY KEY (shift_id);


--
-- Name: tsb_sms_gateway tsb_sms_gateway_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_sms_gateway
    ADD CONSTRAINT tsb_sms_gateway_pkey PRIMARY KEY (sms_gateway_id);


--
-- Name: tsb_snap_log tsb_snap_log_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_snap_log
    ADD CONSTRAINT tsb_snap_log_pkey PRIMARY KEY (snap_log_id);


--
-- Name: tsb_snap tsb_snap_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_snap
    ADD CONSTRAINT tsb_snap_pkey PRIMARY KEY (snap_id);


--
-- Name: tsb_team tsb_team_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_team
    ADD CONSTRAINT tsb_team_pkey PRIMARY KEY (team_id);


--
-- Name: tsb_temp_autorouting tsb_temp_autorouting_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_temp_autorouting
    ADD CONSTRAINT tsb_temp_autorouting_pkey PRIMARY KEY (temp_routing_id);


--
-- Name: tsb_temp_route tsb_temp_route_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_temp_route
    ADD CONSTRAINT tsb_temp_route_pkey PRIMARY KEY (temp_route_id);


--
-- Name: tsb_transportation_geofence tsb_transportation_geofence_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_transportation_geofence
    ADD CONSTRAINT tsb_transportation_geofence_pkey PRIMARY KEY (geofence_id);


--
-- Name: tsb_trip_days tsb_trip_days_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_trip_days
    ADD CONSTRAINT tsb_trip_days_pkey PRIMARY KEY (trip_days_id);


--
-- Name: tsb_trip_geofence tsb_trip_geofence_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_trip_geofence
    ADD CONSTRAINT tsb_trip_geofence_pkey PRIMARY KEY (geofence_id);


--
-- Name: tsb_trip_repeatdays tsb_trip_repeatdays_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_trip_repeatdays
    ADD CONSTRAINT tsb_trip_repeatdays_pkey PRIMARY KEY (trip_repeat_id);


--
-- Name: tsb_user_card tsb_user_card_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_user_card
    ADD CONSTRAINT tsb_user_card_pkey PRIMARY KEY (card_id);


--
-- Name: tsb_vacation tsb_vacation_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vacation
    ADD CONSTRAINT tsb_vacation_pkey PRIMARY KEY (vacation_id);


--
-- Name: tsb_vehicle_activity tsb_vehicle_activity_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_activity
    ADD CONSTRAINT tsb_vehicle_activity_pkey PRIMARY KEY (vehicle_activity_id);


--
-- Name: tsb_vehicle_assignment_history tsb_vehicle_assignment_history_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_assignment_history
    ADD CONSTRAINT tsb_vehicle_assignment_history_pkey PRIMARY KEY (vehicle_history_id);


--
-- Name: tsb_vehicle_data_syncrequest tsb_vehicle_data_syncrequest_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_data_syncrequest
    ADD CONSTRAINT tsb_vehicle_data_syncrequest_pkey PRIMARY KEY (syncrequest_id);


--
-- Name: tsb_vehicle_data_usage tsb_vehicle_data_usage_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_data_usage
    ADD CONSTRAINT tsb_vehicle_data_usage_pkey PRIMARY KEY (data_usage_id);


--
-- Name: tsb_vehicle_expense_file tsb_vehicle_expense_file_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_expense_file
    ADD CONSTRAINT tsb_vehicle_expense_file_pkey PRIMARY KEY (expense_file_id);


--
-- Name: tsb_vehicle_fuel tsb_vehicle_fuel_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_fuel
    ADD CONSTRAINT tsb_vehicle_fuel_pkey PRIMARY KEY (vehicle_fuel_id);


--
-- Name: tsb_vehicle_geofence tsb_vehicle_geofence_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_geofence
    ADD CONSTRAINT tsb_vehicle_geofence_pkey PRIMARY KEY (geofence_id);


--
-- Name: tsb_vehicle_group_member tsb_vehicle_group_member_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_group_member
    ADD CONSTRAINT tsb_vehicle_group_member_pkey PRIMARY KEY (vehicle_group_member_id);


--
-- Name: tsb_vehicle_group tsb_vehicle_group_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_group
    ADD CONSTRAINT tsb_vehicle_group_pkey PRIMARY KEY (vehicle_group_id);


--
-- Name: tsb_vehicle_group_vehicle tsb_vehicle_group_vehicle_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_group_vehicle
    ADD CONSTRAINT tsb_vehicle_group_vehicle_pkey PRIMARY KEY (vehicle_group_vehicle_id);


--
-- Name: tsb_vehicle_maintainance tsb_vehicle_maintainance_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_maintainance
    ADD CONSTRAINT tsb_vehicle_maintainance_pkey PRIMARY KEY (maintainance_id);


--
-- Name: tsb_vehicle_run_summary tsb_vehicle_run_summary_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_run_summary
    ADD CONSTRAINT tsb_vehicle_run_summary_pkey PRIMARY KEY (vehicle_run_summary_id);


--
-- Name: tsb_vehicle_settings tsb_vehicle_settings_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_settings
    ADD CONSTRAINT tsb_vehicle_settings_pkey PRIMARY KEY (vehicle_settings_id);


--
-- Name: tsb_vehicle_temperature_sensor tsb_vehicle_temprature_sensor_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_temperature_sensor
    ADD CONSTRAINT tsb_vehicle_temprature_sensor_pkey PRIMARY KEY (vehicle_temperature_sensor_id);


--
-- Name: tsb_vehicle_group_geofence tsb_vehiclegroup_geofence_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_group_geofence
    ADD CONSTRAINT tsb_vehiclegroup_geofence_pkey PRIMARY KEY (vehiclegroup_geofece_id);


--
-- Name: usage_statistics usage_statistics_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.usage_statistics
    ADD CONSTRAINT usage_statistics_pkey PRIMARY KEY (statistics_id);


--
-- Name: tsb_user user_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_user
    ADD CONSTRAINT user_pkey PRIMARY KEY (user_id);


--
-- Name: tsb_vehicle_accessory vehicle_accessory_id_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_accessory
    ADD CONSTRAINT vehicle_accessory_id_pkey PRIMARY KEY (accessory_id);


--
-- Name: tsb_vehicle_assignment vehicle_assignment_id_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_assignment
    ADD CONSTRAINT vehicle_assignment_id_pkey PRIMARY KEY (vehicle_assignment_id);


--
-- Name: hrd_vehicle_features_list vehicle_features_list_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.hrd_vehicle_features_list
    ADD CONSTRAINT vehicle_features_list_pkey PRIMARY KEY (vehicle_features_list_id);


--
-- Name: tsb_vehicle_fine vehicle_fine_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_fine
    ADD CONSTRAINT vehicle_fine_pkey PRIMARY KEY (fine_id);


--
-- Name: tsb_vehicle_ignition_data vehicle_ignition_id; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_ignition_data
    ADD CONSTRAINT vehicle_ignition_id UNIQUE (ignition_id);


--
-- Name: tsb_vehicle_incident vehicle_incident_id_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_incident
    ADD CONSTRAINT vehicle_incident_id_pkey PRIMARY KEY (incident_id);


--
-- Name: gnx_vehicle vehicle_information_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_vehicle
    ADD CONSTRAINT vehicle_information_pkey PRIMARY KEY (gnx_vehicle_id);


--
-- Name: tsb_vehicle_parking vehicle_parking_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_parking
    ADD CONSTRAINT vehicle_parking_pkey PRIMARY KEY (parking_id);


--
-- Name: tsb_vehicle vehicle_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle
    ADD CONSTRAINT vehicle_pkey PRIMARY KEY (vehicle_id);


--
-- Name: tsb_trip vehicle_route_id_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_trip
    ADD CONSTRAINT vehicle_route_id_pkey PRIMARY KEY (trip_id);


--
-- Name: tsb_vehicle_spareparts vehicle_spareparts_id_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_spareparts
    ADD CONSTRAINT vehicle_spareparts_id_pkey PRIMARY KEY (spareparts_id);


--
-- Name: tsb_vehicle_type vehicle_type_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_type
    ADD CONSTRAINT vehicle_type_pkey PRIMARY KEY (vehicle_type_id);


--
-- Name: vi_inspection_category_types vi_inspection_category_types_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.vi_inspection_category_types
    ADD CONSTRAINT vi_inspection_category_types_pkey PRIMARY KEY (inspection_category_type_id);


--
-- Name: vi_vehicle_inspection_configurations vi_vehicle_inspection_configurations_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.vi_vehicle_inspection_configurations
    ADD CONSTRAINT vi_vehicle_inspection_configurations_pkey PRIMARY KEY (vehicle_inspection_configuration_id);


--
-- Name: vi_vehicle_inspection_settings vi_vehicle_inspection_settings_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.vi_vehicle_inspection_settings
    ADD CONSTRAINT vi_vehicle_inspection_settings_pkey PRIMARY KEY (vehicle_inspection_setting_id);


--
-- Name: vi_vehicle_parts_categories vi_vehicle_parts_categories_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.vi_vehicle_parts_categories
    ADD CONSTRAINT vi_vehicle_parts_categories_pkey PRIMARY KEY (vehicle_parts_category_id);


--
-- Name: tsb_user_apps vt_parentapps_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_user_apps
    ADD CONSTRAINT vt_parentapps_pkey PRIMARY KEY (user_apps_id);


--
-- Name: tsb_webservice_log webservice_log_pkey; Type: CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_webservice_log
    ADD CONSTRAINT webservice_log_pkey PRIMARY KEY (webservice_log_id);


--
-- Name: fki_pickup_details_student_id_fkey; Type: INDEX; Schema: public; Owner: tsbdbadmin
--

CREATE INDEX fki_pickup_details_student_id_fkey ON public.tsb_pickup USING btree (pickup_student_id);


--
-- Name: fki_pickup_point_master_id_fkey; Type: INDEX; Schema: public; Owner: tsbdbadmin
--

CREATE INDEX fki_pickup_point_master_id_fkey ON public.tsb_pickup_point USING btree (pickup_point_route_id);


--
-- Name: fki_user_customer_id_fkey; Type: INDEX; Schema: public; Owner: tsbdbadmin
--

CREATE INDEX fki_user_customer_id_fkey ON public.tsb_user USING btree (user_customer_id);


--
-- Name: fki_vehicle_accessory_vehicle_id_fkey; Type: INDEX; Schema: public; Owner: tsbdbadmin
--

CREATE INDEX fki_vehicle_accessory_vehicle_id_fkey ON public.tsb_vehicle_accessory USING btree (accessory_vehicle_id);


--
-- Name: fki_vehicle_assignment_driver_id_fkey; Type: INDEX; Schema: public; Owner: tsbdbadmin
--

CREATE INDEX fki_vehicle_assignment_driver_id_fkey ON public.tsb_vehicle_assignment USING btree (vehicle_assignment_driver_id);


--
-- Name: fki_vehicle_assignment_helper_id_fkey; Type: INDEX; Schema: public; Owner: tsbdbadmin
--

CREATE INDEX fki_vehicle_assignment_helper_id_fkey ON public.tsb_vehicle_assignment USING btree (vehicle_assignment_helper_id);


--
-- Name: fki_vehicle_assignment_vehicle_id_fkey; Type: INDEX; Schema: public; Owner: tsbdbadmin
--

CREATE INDEX fki_vehicle_assignment_vehicle_id_fkey ON public.tsb_vehicle_assignment USING btree (vehicle_assignment_vehicle_id);


--
-- Name: fki_vehicle_incident_route_id_fkey; Type: INDEX; Schema: public; Owner: tsbdbadmin
--

CREATE INDEX fki_vehicle_incident_route_id_fkey ON public.tsb_vehicle_incident USING btree (incident_route_id);


--
-- Name: fki_vehicle_incident_vehicle_id_fkey; Type: INDEX; Schema: public; Owner: tsbdbadmin
--

CREATE INDEX fki_vehicle_incident_vehicle_id_fkey ON public.tsb_vehicle_incident USING btree (incident_vehicle_id);


--
-- Name: fki_vehicle_route_route_id_fkey; Type: INDEX; Schema: public; Owner: tsbdbadmin
--

CREATE INDEX fki_vehicle_route_route_id_fkey ON public.tsb_trip USING btree (trip_route_id);


--
-- Name: fki_vehicle_spareparts_vehicle_id_fkey; Type: INDEX; Schema: public; Owner: tsbdbadmin
--

CREATE INDEX fki_vehicle_spareparts_vehicle_id_fkey ON public.tsb_vehicle_spareparts USING btree (spareparts_vehicle_id);


--
-- Name: private_chat_conversation_conversation_chat_id_aa35899c; Type: INDEX; Schema: public; Owner: tsbdbadmin
--

CREATE INDEX private_chat_conversation_conversation_chat_id_aa35899c ON public.private_chat_conversation USING btree (conversation_chat_id);


--
-- Name: private_chat_files_file_chat_id_c98a3358; Type: INDEX; Schema: public; Owner: tsbdbadmin
--

CREATE INDEX private_chat_files_file_chat_id_c98a3358 ON public.private_chat_files USING btree (file_chat_id);


--
-- Name: gnx_alert alert_notification_after_insert; Type: TRIGGER; Schema: public; Owner: tsbdbadmin
--

CREATE TRIGGER alert_notification_after_insert AFTER INSERT ON public.gnx_alert FOR EACH ROW EXECUTE FUNCTION public.send_notification_alert();


--
-- Name: gnx_health check_panic_status_on_insert; Type: TRIGGER; Schema: public; Owner: tsbdbadmin
--

CREATE TRIGGER check_panic_status_on_insert AFTER INSERT ON public.gnx_health FOR EACH ROW EXECUTE FUNCTION public.send_notification_panic_alert();

ALTER TABLE public.gnx_health DISABLE TRIGGER check_panic_status_on_insert;


--
-- Name: gnx_location location_partition_trigger; Type: TRIGGER; Schema: public; Owner: tsbdbadmin
--

CREATE TRIGGER location_partition_trigger BEFORE INSERT ON public.gnx_location FOR EACH ROW EXECUTE FUNCTION public.partition_function_location();


--
-- Name: tsb_notification_log notification_log_partition_trigger; Type: TRIGGER; Schema: public; Owner: tsbdbadmin
--

CREATE TRIGGER notification_log_partition_trigger BEFORE INSERT ON public.tsb_notification_log FOR EACH ROW EXECUTE FUNCTION public.partition_function_notification_log();


--
-- Name: tsb_attendance_user partition_function_attendance_user; Type: TRIGGER; Schema: public; Owner: tsbdbadmin
--

CREATE TRIGGER partition_function_attendance_user BEFORE INSERT ON public.tsb_attendance_user FOR EACH ROW EXECUTE FUNCTION public.partition_function_attendance_user();


--
-- Name: gnx_alert partition_function_gnx_alert ; Type: TRIGGER; Schema: public; Owner: tsbdbadmin
--

CREATE TRIGGER "partition_function_gnx_alert " BEFORE INSERT ON public.gnx_alert FOR EACH ROW EXECUTE FUNCTION public.partition_function_gnx_alert();


--
-- Name: gnx_mifare_card_trip partition_trigger_mifare_card_trip; Type: TRIGGER; Schema: public; Owner: tsbdbadmin
--

CREATE TRIGGER partition_trigger_mifare_card_trip BEFORE INSERT ON public.gnx_mifare_card_trip FOR EACH ROW EXECUTE FUNCTION public.partition_function_mifare_card_trip();


--
-- Name: gnx_mifare_card_user partition_trigger_mifare_card_user; Type: TRIGGER; Schema: public; Owner: tsbdbadmin
--

CREATE TRIGGER partition_trigger_mifare_card_user BEFORE INSERT ON public.gnx_mifare_card_user FOR EACH ROW EXECUTE FUNCTION public.partition_function_mifare_card_user();


--
-- Name: tsb_notification partition_trigger_notification; Type: TRIGGER; Schema: public; Owner: tsbdbadmin
--

CREATE TRIGGER partition_trigger_notification BEFORE INSERT ON public.tsb_notification FOR EACH ROW EXECUTE FUNCTION public.partition_function_notification();


--
-- Name: tsb_user partition_trigger_notification_settings_users; Type: TRIGGER; Schema: public; Owner: tsbdbadmin
--

CREATE TRIGGER partition_trigger_notification_settings_users AFTER INSERT ON public.tsb_user FOR EACH ROW EXECUTE FUNCTION public.partition_function_notification_settings_user();


--
-- Name: tsb_notification_priority_log tsb_notification_priority_log_trigger; Type: TRIGGER; Schema: public; Owner: tsbdbadmin
--

CREATE TRIGGER tsb_notification_priority_log_trigger BEFORE INSERT ON public.tsb_notification_priority_log FOR EACH ROW EXECUTE FUNCTION public.partition_function_notification_priority_log();


--
-- Name: tsb_vehicle update_masterstatistics_vehiclecount; Type: TRIGGER; Schema: public; Owner: tsbdbadmin
--

CREATE TRIGGER update_masterstatistics_vehiclecount AFTER INSERT OR DELETE OR UPDATE ON public.tsb_vehicle FOR EACH ROW EXECUTE FUNCTION public.update_vehicle_count_in_statistics();


--
-- Name: tsb_vehicle_activity vehicle_activity_trigger; Type: TRIGGER; Schema: public; Owner: tsbdbadmin
--

CREATE TRIGGER vehicle_activity_trigger BEFORE INSERT ON public.tsb_vehicle_activity FOR EACH ROW EXECUTE FUNCTION public.partition_function_vehicle_activity();


--
-- Name: gnx_alert_type gnx_alert_type_hardware_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.gnx_alert_type
    ADD CONSTRAINT gnx_alert_type_hardware_id_fkey FOREIGN KEY (alert_type_hardware_id) REFERENCES public.gnx_hardware_type(hardware_id);


--
-- Name: tsb_vehicle_ignition_data ignition_driver_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_ignition_data
    ADD CONSTRAINT ignition_driver_id_fkey FOREIGN KEY (ignition_driver_id) REFERENCES public.tsb_user(user_id);


--
-- Name: tsb_vehicle_ignition_data ignition_vehicle_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_ignition_data
    ADD CONSTRAINT ignition_vehicle_id_fkey FOREIGN KEY (ignition_vehicle_id) REFERENCES public.tsb_vehicle(vehicle_id);


--
-- Name: tsb_pickup_point pickup_point_master_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_pickup_point
    ADD CONSTRAINT pickup_point_master_id_fkey FOREIGN KEY (pickup_point_route_id) REFERENCES public.tsb_route(route_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: private_chat_conversation private_chat_convers_conversation_chat_id_aa35899c_fk_private_c; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.private_chat_conversation
    ADD CONSTRAINT private_chat_convers_conversation_chat_id_aa35899c_fk_private_c FOREIGN KEY (conversation_chat_id) REFERENCES public.private_chat(private_chat_id) DEFERRABLE INITIALLY DEFERRED;


--
-- Name: private_chat_conversation private_chat_conversation_replied_conversation_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.private_chat_conversation
    ADD CONSTRAINT private_chat_conversation_replied_conversation_id_fkey FOREIGN KEY (replied_conversation_id) REFERENCES public.private_chat_conversation(conversation_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_alert_comments tsb_alert_comments_alert_comments_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_alert_comments
    ADD CONSTRAINT tsb_alert_comments_alert_comments_user_id_fkey FOREIGN KEY (alert_comments_user_id) REFERENCES public.tsb_user(user_id);


--
-- Name: tsb_customer_geofence tsb_customer_geofence_geofence_customer_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_customer_geofence
    ADD CONSTRAINT tsb_customer_geofence_geofence_customer_id_fkey FOREIGN KEY (geofence_customer_id) REFERENCES public.tsb_customer(customer_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_fleat_maintenance tsb_fleat_maintenance_fleat_maintenance_bus_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_fleat_maintenance
    ADD CONSTRAINT tsb_fleat_maintenance_fleat_maintenance_bus_id_fkey FOREIGN KEY (fleat_maintenance_bus_id) REFERENCES public.tsb_vehicle(vehicle_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_instant_pickup tsb_instant_pickup_instant_pickup_driver_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_instant_pickup
    ADD CONSTRAINT tsb_instant_pickup_instant_pickup_driver_id_fkey FOREIGN KEY (instant_pickup_driver_id) REFERENCES public.tsb_user(user_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_instant_pickup tsb_instant_pickup_instant_pickup_passenger_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_instant_pickup
    ADD CONSTRAINT tsb_instant_pickup_instant_pickup_passenger_id_fkey FOREIGN KEY (instant_pickup_passenger_id) REFERENCES public.tsb_passenger(passenger_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_instant_pickup tsb_instant_pickup_instant_pickup_vehicle_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_instant_pickup
    ADD CONSTRAINT tsb_instant_pickup_instant_pickup_vehicle_id_fkey FOREIGN KEY (instant_pickup_vehicle_id) REFERENCES public.tsb_vehicle(vehicle_id) ON UPDATE CASCADE;


--
-- Name: tsb_instant_repeat tsb_instant_repeat_instant_repeat_pickup_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_instant_repeat
    ADD CONSTRAINT tsb_instant_repeat_instant_repeat_pickup_id_fkey FOREIGN KEY (instant_repeat_pickup_id) REFERENCES public.tsb_instant_pickup(instant_pickup_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_invoice_item tsb_invoice_item_invoice_item_invoice_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_invoice_item
    ADD CONSTRAINT tsb_invoice_item_invoice_item_invoice_id_fkey FOREIGN KEY (invoice_item_invoice_id) REFERENCES public.tsb_invoice(invoice_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_notification tsb_notification_notification_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_notification
    ADD CONSTRAINT tsb_notification_notification_user_id_fkey FOREIGN KEY (notification_user_id) REFERENCES public.tsb_user(user_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_parking_slot tsb_parking_slot_school_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_parking_slot
    ADD CONSTRAINT tsb_parking_slot_school_id_fkey FOREIGN KEY (school_id) REFERENCES public.tsb_customer(customer_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_parking_vehicles tsb_parking_vehicles_parking_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_parking_vehicles
    ADD CONSTRAINT tsb_parking_vehicles_parking_id_fkey FOREIGN KEY (parking_slot_id) REFERENCES public.tsb_parking_slot(slot_id);


--
-- Name: tsb_parking_vehicles tsb_parking_vehicles_vehicle_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_parking_vehicles
    ADD CONSTRAINT tsb_parking_vehicles_vehicle_id_fkey FOREIGN KEY (vehicle_id) REFERENCES public.tsb_vehicle(vehicle_id);


--
-- Name: tsb_parkingslot_geofence tsb_parkingslot_geofence_geofence_parkingslot_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_parkingslot_geofence
    ADD CONSTRAINT tsb_parkingslot_geofence_geofence_parkingslot_id_fkey FOREIGN KEY (geofence_parkingslot_id) REFERENCES public.tsb_parking_slot(slot_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_payment tsb_payment_payment_invoice_no_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_payment
    ADD CONSTRAINT tsb_payment_payment_invoice_no_fkey FOREIGN KEY (payment_invoice_no) REFERENCES public.tsb_invoice(invoice_id);


--
-- Name: tsb_pickup_change tsb_pickup_change_pickup_change_route_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_pickup_change
    ADD CONSTRAINT tsb_pickup_change_pickup_change_route_id_fkey FOREIGN KEY (pickup_change_route_id) REFERENCES public.tsb_route(route_id);


--
-- Name: tsb_rash_drive tsb_rash_drive_rash_drive_driver_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_rash_drive
    ADD CONSTRAINT tsb_rash_drive_rash_drive_driver_id_fkey FOREIGN KEY (rash_drive_driver_id) REFERENCES public.tsb_driver(driver_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_rash_drive tsb_rash_drive_rash_drive_vehicle_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_rash_drive
    ADD CONSTRAINT tsb_rash_drive_rash_drive_vehicle_id_fkey FOREIGN KEY (rash_drive_vehicle_id) REFERENCES public.tsb_vehicle(vehicle_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_route_geofence tsb_route_geofence_geofence_route_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_route_geofence
    ADD CONSTRAINT tsb_route_geofence_geofence_route_id_fkey FOREIGN KEY (geofence_route_id) REFERENCES public.tsb_route(route_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_trips_history tsb_trips_history_trips_history_driver_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_trips_history
    ADD CONSTRAINT tsb_trips_history_trips_history_driver_id_fkey FOREIGN KEY (trips_history_driver_id) REFERENCES public.tsb_user(user_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_trips_history tsb_trips_history_trips_history_trip_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_trips_history
    ADD CONSTRAINT tsb_trips_history_trips_history_trip_id_fkey FOREIGN KEY (trips_history_trip_id) REFERENCES public.tsb_trip(trip_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_user_apps tsb_user_apps_user_apps_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_user_apps
    ADD CONSTRAINT tsb_user_apps_user_apps_user_id_fkey FOREIGN KEY (user_apps_user_id) REFERENCES public.tsb_user(user_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_vehicle_activity tsb_vehicle_activity_vehicle_activity_driver_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_activity
    ADD CONSTRAINT tsb_vehicle_activity_vehicle_activity_driver_id_fkey FOREIGN KEY (vehicle_activity_driver_id) REFERENCES public.tsb_driver(driver_id) MATCH FULL ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_vehicle_activity tsb_vehicle_activity_vehicle_activity_vehicle_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_activity
    ADD CONSTRAINT tsb_vehicle_activity_vehicle_activity_vehicle_id_fkey FOREIGN KEY (vehicle_activity_vehicle_id) REFERENCES public.tsb_vehicle(vehicle_id) MATCH FULL ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_vehicle_assignment_history tsb_vehicle_assignment_history_vehicle_history_driver_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_assignment_history
    ADD CONSTRAINT tsb_vehicle_assignment_history_vehicle_history_driver_id_fkey FOREIGN KEY (vehicle_history_driver_id) REFERENCES public.tsb_driver(driver_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_vehicle_assignment_history tsb_vehicle_assignment_history_vehicle_history_vehicle_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_assignment_history
    ADD CONSTRAINT tsb_vehicle_assignment_history_vehicle_history_vehicle_id_fkey FOREIGN KEY (vehicle_history_vehicle_id) REFERENCES public.tsb_vehicle(vehicle_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_vehicle_assignment tsb_vehicle_assignment_vehicle_assignment_driver_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_assignment
    ADD CONSTRAINT tsb_vehicle_assignment_vehicle_assignment_driver_id_fkey FOREIGN KEY (vehicle_assignment_driver_id) REFERENCES public.tsb_driver(driver_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_vehicle_assignment tsb_vehicle_assignment_vehicle_assignment_trip_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_assignment
    ADD CONSTRAINT tsb_vehicle_assignment_vehicle_assignment_trip_id_fkey FOREIGN KEY (vehicle_assignment_trip_id) REFERENCES public.tsb_trip(trip_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_vehicle_fuel tsb_vehicle_fuel_vehicle_fuel_vehicle_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_fuel
    ADD CONSTRAINT tsb_vehicle_fuel_vehicle_fuel_vehicle_id_fkey FOREIGN KEY (vehicle_fuel_vehicle_id) REFERENCES public.tsb_vehicle(vehicle_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_vehicle_geofence tsb_vehicle_geofence_geofence_vehicle_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_geofence
    ADD CONSTRAINT tsb_vehicle_geofence_geofence_vehicle_id_fkey FOREIGN KEY (geofence_vehicle_id) REFERENCES public.tsb_vehicle(vehicle_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_notification_settings_email tsb_vehicle_notification_settings_email_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_notification_settings_email
    ADD CONSTRAINT tsb_vehicle_notification_settings_email_user_id_fkey FOREIGN KEY (notification_settings_user_id) REFERENCES public.tsb_user(user_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_notification_settings_sms tsb_vehicle_notification_settings_sms_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_notification_settings_sms
    ADD CONSTRAINT tsb_vehicle_notification_settings_sms_user_id_fkey FOREIGN KEY (notification_settings_user_id) REFERENCES public.tsb_user(user_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_notification_settings_whatsapp tsb_vehicle_notification_settings_whatsapp_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_notification_settings_whatsapp
    ADD CONSTRAINT tsb_vehicle_notification_settings_whatsapp_user_id_fkey FOREIGN KEY (notification_settings_user_id) REFERENCES public.tsb_user(user_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_vehicle_readers tsb_vehicle_readers_vehicle_readers_vehicle_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_readers
    ADD CONSTRAINT tsb_vehicle_readers_vehicle_readers_vehicle_id_fkey FOREIGN KEY (vehicle_readers_vehicle_id) REFERENCES public.tsb_vehicle(vehicle_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_vehicle_spareparts tsb_vehicle_spareparts_spareparts_vehicle_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_spareparts
    ADD CONSTRAINT tsb_vehicle_spareparts_spareparts_vehicle_id_fkey FOREIGN KEY (spareparts_vehicle_id) REFERENCES public.tsb_vehicle(vehicle_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_vehicle_temperature_sensor tsb_vehicle_temprature_sensor_vehicle_temperature_sensor_v_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_temperature_sensor
    ADD CONSTRAINT tsb_vehicle_temprature_sensor_vehicle_temperature_sensor_v_fkey FOREIGN KEY (vehicle_temperature_sensor_vehicle_id) REFERENCES public.tsb_vehicle(vehicle_id);


--
-- Name: tsb_vehicle tsb_vehicle_vehicle_type_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle
    ADD CONSTRAINT tsb_vehicle_vehicle_type_fkey FOREIGN KEY (vehicle_type) REFERENCES public.tsb_vehicle_type(vehicle_type_id) ON UPDATE CASCADE;


--
-- Name: tsb_user user_customer_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_user
    ADD CONSTRAINT user_customer_id_fkey FOREIGN KEY (user_customer_id) REFERENCES public.tsb_customer(customer_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_vehicle_accessory vehicle_accessory_vehicle_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_accessory
    ADD CONSTRAINT vehicle_accessory_vehicle_id_fkey FOREIGN KEY (accessory_vehicle_id) REFERENCES public.tsb_vehicle(vehicle_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_vehicle_assignment vehicle_assignment_vehicle_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_assignment
    ADD CONSTRAINT vehicle_assignment_vehicle_id_fkey FOREIGN KEY (vehicle_assignment_vehicle_id) REFERENCES public.tsb_vehicle(vehicle_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_vehicle_fine vehicle_fine_vehicle_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_fine
    ADD CONSTRAINT vehicle_fine_vehicle_id_fkey FOREIGN KEY (fine_vehicle_id) REFERENCES public.tsb_vehicle(vehicle_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_vehicle_incident vehicle_incident_route_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_incident
    ADD CONSTRAINT vehicle_incident_route_id_fkey FOREIGN KEY (incident_route_id) REFERENCES public.tsb_route(route_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_vehicle_incident vehicle_incident_vehicle_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_vehicle_incident
    ADD CONSTRAINT vehicle_incident_vehicle_id_fkey FOREIGN KEY (incident_vehicle_id) REFERENCES public.tsb_vehicle(vehicle_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_trip vehicle_route_route_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_trip
    ADD CONSTRAINT vehicle_route_route_id_fkey FOREIGN KEY (trip_route_id) REFERENCES public.tsb_route(route_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_trip vehicle_route_shift_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_trip
    ADD CONSTRAINT vehicle_route_shift_id_fkey FOREIGN KEY (trip_shift) REFERENCES public.tsb_shift(shift_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_trip vehicle_route_vehicle_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_trip
    ADD CONSTRAINT vehicle_route_vehicle_id_fkey FOREIGN KEY (trip_vehicle_id) REFERENCES public.tsb_vehicle(vehicle_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: vi_vehicle_inspection_configurations vi_vehicle_inspection_configurat_vehicle_parts_category_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.vi_vehicle_inspection_configurations
    ADD CONSTRAINT vi_vehicle_inspection_configurat_vehicle_parts_category_id_fkey FOREIGN KEY (vehicle_parts_category_id) REFERENCES public.vi_vehicle_parts_categories(vehicle_parts_category_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: vi_vehicle_inspection_settings vi_vehicle_inspection_settings_inspection_category_type_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.vi_vehicle_inspection_settings
    ADD CONSTRAINT vi_vehicle_inspection_settings_inspection_category_type_id_fkey FOREIGN KEY (inspection_category_type_id) REFERENCES public.vi_inspection_category_types(inspection_category_type_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: vi_vehicle_inspection_settings vi_vehicle_inspection_settings_vehicle_category_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.vi_vehicle_inspection_settings
    ADD CONSTRAINT vi_vehicle_inspection_settings_vehicle_category_id_fkey FOREIGN KEY (vehicle_category_id) REFERENCES public.tsb_vehicle_type(vehicle_type_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: vi_vehicle_parts_categories vi_vehicle_parts_categories_vehicle_inspection_setting_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.vi_vehicle_parts_categories
    ADD CONSTRAINT vi_vehicle_parts_categories_vehicle_inspection_setting_id_fkey FOREIGN KEY (vehicle_inspection_setting_id) REFERENCES public.vi_vehicle_inspection_settings(vehicle_inspection_setting_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: tsb_pickup vt_pickup_pickup_pickup_point_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_pickup
    ADD CONSTRAINT vt_pickup_pickup_pickup_point_id_fkey FOREIGN KEY (pickup_pickup_point_id) REFERENCES public.tsb_pickup_point(pickup_point_id);


--
-- Name: tsb_pickup vt_pickup_pickup_route_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_pickup
    ADD CONSTRAINT vt_pickup_pickup_route_id_fkey FOREIGN KEY (pickup_route_id) REFERENCES public.tsb_route(route_id);


--
-- Name: tsb_pickup vt_pickup_pickup_vehicle_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: tsbdbadmin
--

ALTER TABLE ONLY public.tsb_pickup
    ADD CONSTRAINT vt_pickup_pickup_vehicle_id_fkey FOREIGN KEY (pickup_vehicle_id) REFERENCES public.tsb_vehicle(vehicle_id);


--
-- Name: SCHEMA public; Type: ACL; Schema: -; Owner: tsbdbadmin
--

REVOKE USAGE ON SCHEMA public FROM PUBLIC;
GRANT ALL ON SCHEMA public TO PUBLIC;


--
--

