larskarbo / napchart

Drag-and-drop time-planning library using HTML5 and the canvas element
https://napchart.com
GNU General Public License v3.0
140 stars 36 forks source link

Initialise MySQL database and table #1

Closed gianpaj closed 9 years ago

gianpaj commented 9 years ago

If the database will be used a lot more perhaps an ORM would be a good idea:

Otherwise:

### ERROR  { [Error: ER_NO_SUCH_TABLE: Table 'napchart.chart' doesn't exist]
  code: 'ER_NO_SUCH_TABLE',
  errno: 1146,
  sqlState: '42S02',
  index: 0 }

/Users/gianfranco/temp/napchart.com/node_modules/mysql/lib/protocol/Parser.js:82
        throw err;
              ^
Error: ER_NO_SUCH_TABLE: Table 'napchart.chart' doesn't exist
    at Query.Sequence._packetToError (/Users/gianfranco/temp/napchart.com/node_modules/mysql/lib/protocol/sequences/Sequence.js:48:14)
    at Query.ErrorPacket (/Users/gianfranco/temp/napchart.com/node_modules/mysql/lib/protocol/sequences/Query.js:83:18)
    at Protocol._parsePacket (/Users/gianfranco/temp/napchart.com/node_modules/mysql/lib/protocol/Protocol.js:274:23)
    at Parser.write (/Users/gianfranco/temp/napchart.com/node_modules/mysql/lib/protocol/Parser.js:77:12)
    at Protocol.write (/Users/gianfranco/temp/napchart.com/node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket.<anonymous> (/Users/gianfranco/temp/napchart.com/node_modules/mysql/lib/Connection.js:96:28)
    at Socket.emit (events.js:95:17)
    at Socket.<anonymous> (_stream_readable.js:765:14)
    at Socket.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:427:10)
    --------------------
    at Protocol._enqueue (/Users/gianfranco/temp/napchart.com/node_modules/mysql/lib/protocol/Protocol.js:135:48)
    at Connection.query (/Users/gianfranco/temp/napchart.com/node_modules/mysql/lib/Connection.js:201:25)
    at setChartID (/Users/gianfranco/temp/napchart.com/script.js:170:14)
    at Object.app.post.text [as handle] (/Users/gianfranco/temp/napchart.com/script.js:193:12)
    at next_layer (/Users/gianfranco/temp/napchart.com/node_modules/express/lib/router/route.js:103:13)
    at Route.dispatch (/Users/gianfranco/temp/napchart.com/node_modules/express/lib/router/route.js:107:5)
    at c (/Users/gianfranco/temp/napchart.com/node_modules/express/lib/router/index.js:195:24)
    at Function.proto.process_params (/Users/gianfranco/temp/napchart.com/node_modules/express/lib/router/index.js:251:12)
    at next (/Users/gianfranco/temp/napchart.com/node_modules/express/lib/router/index.js:189:19)
    at next (/Users/gianfranco/temp/napchart.com/node_modules/express/lib/router/index.js:166:38)
larskarbo commented 9 years ago

Maybe I should add a setup command, so that you can add credentials from the command line and also create tables if they are missing?

Something like ./napchart setup ?

I have seen it been used in nodebb like this $ ./nodebb setup . How can I do that?

larskarbo commented 9 years ago

ORM is a good idea. It makes it more readable and structured. I will look into that

larskarbo commented 9 years ago

I have now added a initialization script using sequelize. Run node script --setup

gianpaj commented 9 years ago

awesome!