
/*
 * Copyright (c) 2017 Bonnie Schulkin. All Rights Reserved.
 *
 * This file is part of BoxCharter.
 *
 * BoxCharter is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 *
 * BoxCharter is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with BoxCharter. If not, see <http://www.gnu.org/licenses/>.
 *
 */

//////////////////////////////////////////////////////////////////////////////
// Database connection and creation
//////////////////////////////////////////////////////////////////////////////

var db = require('./db')

// order is important for associations / dependencies ( or is it...? )
require('./user')
require('./note-key')
require('./chord-lyric')
require('./measure')
require('./section')
require('./chart')
require('./chartuser')
require('./associations')

var sequelize = db.sequelize

sequelize
  .authenticate()
  .then(() => {
    console.log('Connection has been established successfully.')
  })
  .catch(err => {
    console.error('Unable to connect to the database:', err)
    process.exit()
  })

// create tables, but only if they don't already exist
// sequelize.sync()
sequelize.sync({force: true}) // force=true creates tables even if they already exist
  .then(() => {
    console.log('Tables created.')
    process.exit()
  })
  .catch(error => {
    console.error(`Unable to create tables: ${error}`)
    process.exit()
  })

@@ -989,80 +989,8 @@
 db')
-%0A%0A// order is important for associations / dependencies ( or is it...? )
 %0Areq
@@ -1162,16 +1162,147 @@
 ions')%0A%0A
+// for seeding notes and keys%0Aconst addUser = require('../seed/add_user')%0Aconst addNotesAndScales = require('../seed/add_scales')%0A%0A
 var sequ
@@ -1753,32 +1753,198 @@
 ated.')%0A
+%0A
     
-process.exit
+// seed data%0A    console.log('**Adding notes and scales.')%0A    addNotesAndScales()%0A%0A    // DANGER: *****remove this when deploying!%0A    console.log('**Adding user.')%0A    addUser
 ()%0A  %7D)%0A
@@ -2018,32 +2018,13 @@
 rror%7D%60)%0A
-    process.exit()%0A
   %7D)%0A

Add seed functions.