# Path: nrcif/records.py



from ..records import layouts
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#

'''Generate SQL that will create a suitable schema for storing data
from ATOC .MCA timetable files. This is done dynamically to ensure it
keeps in sync with the definitions in nrcif.py and nrcif_fields.py'''



def gen_sql(DDL, CONS):

    SCHEMA = "mca"

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

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

    DDL.write("CREATE SCHEMA {0};\nSET search_path TO {0},public;\n\n"
              .format(SCHEMA))
    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")


# Path: nrcif/records.py



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

#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#

'''Generate SQL that will create a suitable schema for storing data
from ATOC .MCA timetable files. This is done dynamically to ensure it
keeps in sync with the definitions in nrcif.py and nrcif_fields.py'''



def gen_sql(DDL, CONS):

    SCHEMA = "mca"

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

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

    DDL.write("CREATE SCHEMA {0};\nSET search_path TO {0},public;\n\n"
              .format(SCHEMA))
    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")