# Path: nrcif/msn_records.py



from ..msn_records import layouts



def gen_sql(DDL, CONS):

    SCHEMA = "msn"

    DDL.write('-- SQL DDL for data extracted from ATOC .MSN timetable files\n'
              '-- in NR CIF format. Auto-generated by schemagen_msn.py\n\n')

    CONS.write('-- SQL constraints & indexes definitions for data extracted\n'
               '-- from ATOC .MSN timetable files in NR CIF format. \n'
               '-- Auto-generated by schemagen_msn.py\n\n')

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

    normal_template = "CREATE TABLE {} (\n"

    for i in ('A', 'L', 'V'):
        tablename = layouts[i].name.lower().replace(" ", "_")
        DDL.write(normal_template.format(tablename))
        DDL.write(layouts[i].generate_sql_ddl())
        DDL.write("\n\t);\n\n")

    CONS.write('ALTER TABLE station_detail ADD PRIMARY KEY(tiploc_code);\n')
    CONS.write('CREATE INDEX idx_stn_detail_stn_name\n'
               '    ON station_detail (station_name);\n')
    CONS.write('CREATE INDEX idx_stn_detail_3alpha \n'

# Path: nrcif/msn_records.py



# Path: nrcif/schema/schemagen_msn.py
from ..msn_records import layouts




def gen_sql(DDL, CONS):

    SCHEMA = "msn"

    DDL.write('-- SQL DDL for data extracted from ATOC .MSN timetable files\n'
              '-- in NR CIF format. Auto-generated by schemagen_msn.py\n\n')

    CONS.write('-- SQL constraints & indexes definitions for data extracted\n'
               '-- from ATOC .MSN timetable files in NR CIF format. \n'
               '-- Auto-generated by schemagen_msn.py\n\n')

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

    normal_template = "CREATE TABLE {} (\n"

    for i in ('A', 'L', 'V'):
        tablename = layouts[i].name.lower().replace(" ", "_")
        DDL.write(normal_template.format(tablename))
        DDL.write(layouts[i].generate_sql_ddl())
        DDL.write("\n\t);\n\n")

    CONS.write('ALTER TABLE station_detail ADD PRIMARY KEY(tiploc_code);\n')
    CONS.write('CREATE INDEX idx_stn_detail_stn_name\n'
               '    ON station_detail (station_name);\n')
    CONS.write('CREATE INDEX idx_stn_detail_3alpha \n'

               '    ON station_detail (_3_alpha_code);\n')