node-orm2 icon indicating copy to clipboard operation
node-orm2 copied to clipboard

sql-ddl-sync does not support sqlite

Open Locke opened this issue 10 years ago • 5 comments

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

Locke avatar Mar 14 '14 11:03 Locke

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)

dxg avatar Mar 17 '14 08:03 dxg

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.

dxg avatar Mar 17 '14 10:03 dxg

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.

Locke avatar Mar 17 '14 11:03 Locke

Ok. Make sure you npm install sqlite3.

dxg avatar Mar 17 '14 11:03 dxg

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.

Locke avatar Mar 17 '14 22:03 Locke