node-orm2
node-orm2 copied to clipboard
sql-ddl-sync does not support sqlite
I tried to replicate the error described in #470 with a simple model.
models.js:
var orm = require("orm");
exports.initialize = function(db){
exports.Car = db.define(
"car", {
date: Date,
type: String,
name: String
}
);
};
test_sync.js:
var orm = require("orm");
var Models = require("./models.js");
orm.connect("sqlite:///tmp/test_sync.sqlite?debug=true", function (err, db) {
if(err){
console.log(err);
return;
}
Models.initialize(db);
db.sync(function (err) {
if(err){
console.log(err);
return;
}
console.log("ready");
});
});
checkout node-orm2 v2.1.3, then:
$ rm /tmp/test_sync.sqlite
$ node test_sync.js
ready
checkout node-orm2 master, then:
$ node test_sync.js
(orm/sqlite) SELECT * FROM sqlite_master WHERE type = 'table' and name = 'car'
(orm/sqlite) PRAGMA table_info(`car`)
(orm/sqlite) ALTER TABLE `car` MODIFY `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT
(orm/sqlite) PRAGMA index_list(`car`)
{ [Error: SQLITE_ERROR: near "MODIFY": syntax error] errno: 1, code: 'SQLITE_ERROR', model: 'car' }
(orm/sqlite) CREATE INDEX `car_pkey` ON `car` (`id`)
It turns out: sqlite does not support ALTER TABLE .. MODIFY: http://www.sqlite.org/lang_altertable.html
Ugh, not what you want to find out a day before you plan to release.. taking a look.
Edit It's an issue with syncing once a table already exists. Also broken for postgres (but for different reasons)
The above code should work now. The underlying issue is still present, but it shouldn't be a problem in the short term. I've scheduled fixing the MODIFY problem for 2.1.5.
Now I get this error:
{ message: 'Connection protocol not supported - have you installed the database driver for sqlite?',
code: 4,
literalCode: 'NO_SUPPORT' }
Maybe this is a problem on my side, I need to investigate this tonight, my lunchtime is over now.
Ok. Make sure you npm install sqlite3
.
I was my fault, as I had not my usual environment I forgot to npm install
after cloning the repo.
This works now, but I let this ticket open for the underlying issue. Or do you want to create a new ticket? Then feel free to close this one.