# Path: nrcif/records.py



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

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

    CONS.write("ALTER TABLE basic_schedule ADD PRIMARY KEY(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 = '''
ALTER TABLE {0} ADD PRIMARY KEY (train_uid, date_runs_from,
                                 stp_indicator, loc_order);

ALTER TABLE {0} ADD FOREIGN KEY (train_uid, date_runs_from, stp_indicator)
REFERENCES basic_schedule (train_uid, date_runs_from,
                           stp_indicator) DEFERRABLE;
'''

    for i in ('LO', 'LI', 'CR', 'LT', 'LN'):
        tablename = layouts[i].name.lower().replace(" ", "_")
        DDL.write(route_template.format(tablename))

# Path: nrcif/records.py



# Path: nrcif/schema/schemagen_mca.py
from ..records import layouts

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

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

    CONS.write("ALTER TABLE basic_schedule ADD PRIMARY KEY(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 = '''
ALTER TABLE {0} ADD PRIMARY KEY (train_uid, date_runs_from,
                                 stp_indicator, loc_order);

ALTER TABLE {0} ADD FOREIGN KEY (train_uid, date_runs_from, stp_indicator)
REFERENCES basic_schedule (train_uid, date_runs_from,
                           stp_indicator) DEFERRABLE;
'''

    for i in ('LO', 'LI', 'CR', 'LT', 'LN'):
        tablename = layouts[i].name.lower().replace(" ", "_")
        DDL.write(route_template.format(tablename))

        DDL.write(layouts[i].generate_sql_ddl())