SchizoDuckie / CreateReadUpdateDelete.js

CreateReadUpdateDelete.js aims to bring you a tiny footprint (18kb compressed), platform independent ORM/ActiveRecord implementation for Javascript that works flawlessly on SQLite / WebSQL databases, or any flavor of remote database you can think of via serverside JSON API. Written in Plain Old JavaScript without any framework dependencies, you can use this with Mootools, Jquery, Zepto, Ember, or whatever your drug of choice is.
http://schizoduckie.github.io/CreateReadUpdateDelete.js/
MIT License
38 stars 5 forks source link

Migration not working #13

Closed MarioVanDenEijnde closed 8 years ago

MarioVanDenEijnde commented 8 years ago

Hello SchizoDuckie,

Tried everything I can think of but cannot get migration to work. Can you advise on the code below?

I get error code: message: "could not prepare statement (1 table challengestest has no column named description)"

    function ChallengesTest() {
        CRUD.Entity.call(this);
    }

    CRUD.define(ChallengesTest, {
        className: 'ChallengesTest',
        table: 'challengestest',
        primary: 'ID_Challenge',
        fields: [
            'ID_Challenge',
            'title',
            'description'
        ],
        orderProperty: 'startDate',
        orderDirection: 'DESC',
        indexes: [
            'title'
        ],
        createStatement: 'CREATE TABLE challengestest (ID_Challenge TEXT PRIMARY KEY, title TEXT, description TEXT)',
        migrations: {
            1: [
                'ALTER TABLE challengestest RENAME TO challengestest_bak',
                'CREATE TABLE challengestest (ID_Challenge TEXT PRIMARY KEY, title TEXT)',
                'INSERT OR IGNORE INTO challengestest (ID_Challenge, title) select ID_Challenge, title from challengestest_bak',
                'DROP TABLE challengestest_bak'
            ]
        },
        relations: [],
        fixtures: [{
            ID_Challenge:'CH13',
            title:'PUSH-UP'
        }]
    }, {});

    CRUD.DEBUG = true;

    CRUD.setAdapter(new CRUD.SQLiteAdapter('MyPTtest', { 
      estimatedSize: 25 * 1024 * 1024 
    }));

    function addItem(){
        var ChallengesTestItem = new ChallengesTest();
        ChallengesTestItem.title = 'Arrow';
        ChallengesTestItem.description = 'description';

        ChallengesTestItem.Persist().then(function(result) {
            console.log("ChallengesTestItem persisted! ", result);
        });
    }
MarioVanDenEijnde commented 8 years ago

found it: I forgot the new column in the CREATE TABLE inside the migration bit.