# Path: nrcif/records.py

# 
# Path: nrcif/ztr_reader.py
# class ZTR(nrcif.mca_reader.MCA):
#     def __init__(self, cur):


from ..records import layouts as mca_layouts
from ..ztr_reader import reduced_hd, corrected_bx
    CONS.write("SET search_path TO {0},public;\n\n".format(SCHEMA))

    DDL.write("-- The BS, BX and TN records are stored in the same table\n")
    DDL.write("CREATE TABLE basic_schedule (\n")

    DDL.write(layouts['BS'].generate_sql_ddl()+",\n")
    DDL.write(layouts['BX'].generate_sql_ddl()+",\n")
    DDL.write(layouts['TN'].generate_sql_ddl())

    DDL.write("\n\t);\n\n")

    CONS.write("-- ***The Z-Trains data appears to contain duplicates, "
               "so primary keys cannot be used***\n\n")
    CONS.write("CREATE INDEX idx_ztr_basic_schedule ON basic_schedule "
               "(train_uid, date_runs_from, stp_indicator);\n")

    DDL.write('''-- The LO, LI, CR, LT and LN tables all have a header added to relate
-- them to the relevant train\n''')

    route_template = '''CREATE TABLE {} (
\ttrain_uid\t\tCHAR(6),
\tdate_runs_from\tDATE,
\tstp_indicator\tCHAR(1),
\tloc_order\t\tINTEGER,
\txmidnight\t\tBOOLEAN,
'''
    route_pk = '''
CREATE INDEX idx_ztr_{0} ON ztr.{0} (train_uid, date_runs_from,
                                     stp_indicator, loc_order);


# Path: nrcif/records.py

# 
# Path: nrcif/ztr_reader.py
# class ZTR(nrcif.mca_reader.MCA):
#     def __init__(self, cur):


# Path: nrcif/schema/schemagen_ztr.py
from ..records import layouts as mca_layouts
from ..ztr_reader import reduced_hd, corrected_bx

    CONS.write("SET search_path TO {0},public;\n\n".format(SCHEMA))

    DDL.write("-- The BS, BX and TN records are stored in the same table\n")
    DDL.write("CREATE TABLE basic_schedule (\n")

    DDL.write(layouts['BS'].generate_sql_ddl()+",\n")
    DDL.write(layouts['BX'].generate_sql_ddl()+",\n")
    DDL.write(layouts['TN'].generate_sql_ddl())

    DDL.write("\n\t);\n\n")

    CONS.write("-- ***The Z-Trains data appears to contain duplicates, "
               "so primary keys cannot be used***\n\n")
    CONS.write("CREATE INDEX idx_ztr_basic_schedule ON basic_schedule "
               "(train_uid, date_runs_from, stp_indicator);\n")

    DDL.write('''-- The LO, LI, CR, LT and LN tables all have a header added to relate
-- them to the relevant train\n''')

    route_template = '''CREATE TABLE {} (
\ttrain_uid\t\tCHAR(6),
\tdate_runs_from\tDATE,
\tstp_indicator\tCHAR(1),
\tloc_order\t\tINTEGER,
\txmidnight\t\tBOOLEAN,
'''
    route_pk = '''
CREATE INDEX idx_ztr_{0} ON ztr.{0} (train_uid, date_runs_from,
                                     stp_indicator, loc_order);


--ALTER TABLE {0} ADD FOREIGN KEY (train_uid, date_runs_from, stp_indicator)