I don't know where to put the database, because the instructions are for linux/mac. I don't know where to run the migration file. The instructions are just not good enough for a beginner. I am so confused. I was unsuccessful at creating a database that I could connect to. Later, in the instructions, the tutorial walks you through creating the database using db-migration. Yay, I thought that might help. Nope. I just can't create a SQLite database that I can connect to using NodeJS.
This is what I have so far:
database.json
{
"test": {
"driver": "sqlite3",
"filename": "/data/keyword-wrangler2.test.sqlite"
},
"dev": {
"driver": "sqlite3",
"filename": "/data/keyword-wrangler2.dev.sqlite"
},
"production": {
"driver": "mysql",
"host": "localhost",
"user": "root",
"password": "root",
"database": "keyword_wrangler"
}
}
The instructions have the filename = "/var/tmp/keyword-wrangler.sqlite". We don't have a /var folder on Windows. Should I create one or can I put the database where I want it?
20160304212317-createKeywordAndCategoryTable.js
Then I ran this command: db-migrate create createKeywordAndCategoryTable --env test
and made the changes according to the instructions. Following is the migration file:
'use strict';
var dbm = require('db-migrate');
var type = dbm.dataType;
var async = require('async');
var seed;
/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function(options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
};
exports.up = function(db, callback) {
async.series(
[
db.createTable.bind(db, 'keyword', {
id: { type: 'int', primaryKey: true, autoIncrement: true, notNull: true },
value: { type: 'string', length: '128', notNull: true, unique: true },
categoryID: { type: 'int', notNull: true }
}),
db.createTable.bind(db, 'category', {
id: { type: 'int', primaryKey: true, autoIncrement: true, notNull: true },
name: { type: 'string', length: '128', notNull: true }
})
], callback);
};
exports.down = function(db, callback) {
async.series(
[
db.dropTable.bind(db, 'keyword'),
db.dropTable.bind(db, 'category')
], callback);
};
According to the instructions I should be able to run this command: db-migrate up --env test
and the file should be processed and the database should exist.
From where? If I run the command from the root folder of my project, I receive this error:
db-migrate up --env test
[ERROR] Error: SQLITE_CANTOPEN: unable to open database file
at Error (native)
If I run the command from the migrations folder of my project, I receive this error:
\migrations>db-migrate up --env test
[ERROR] Error: Could not find database config file 'C:\Users\pdl\Projects\keyword-wrangler\keyword-wrangler3\migrations/database.json'
at Object.exports.loadFile (C:\Users\pdl\Projects\keyword-wrangler\keyword-wrangler3\node_modules\db-migrate\lib\config.js:45:11)
at loadConfig (C:\Users\pdl\Projects\keyword-wrangler\keyword-wrangler3\node_modules\db-migrate\api.js:508:18)
at Object.dbmigrate (C:\Users\pdl\Projects\keyword-wrangler\keyword-wrangler3\node_modules\db-migrate\api.js:67:17)
at Object.module.exports.getInstance (C:\Users\pdl\Projects\keyword-wrangler\keyword-wrangler3\node_modules\db-migrate\index.js:56:10)
at C:\Users\pdl\AppData\Roaming\npm\node_modules\db-migrate\bin\db-migrate:34:23
at C:\Users\pdl\AppData\Roaming\npm\node_modules\db-migrate\node_modules\resolve\lib\async.js:44:21
at ondir (C:\Users\pdl\AppData\Roaming\npm\node_modules\db-migrate\node_modules\resolve\lib\async.js:187:31)
at onex (C:\Users\pdl\AppData\Roaming\npm\node_modules\db-migrate\node_modules\resolve\lib\async.js:93:22)
at C:\Users\pdl\AppData\Roaming\npm\node_modules\db-migrate\node_modules\resolve\lib\async.js:24:18
at FSReqWrap.oncomplete (fs.js:82:15)
Can somebody please clue me in on the obvious steps or information I am missing?
Totally Frustrated!