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

ERROR TypeError: Cannot read property 'onConnect' of undefined #2

Closed MarioVanDenEijnde closed 8 years ago

MarioVanDenEijnde commented 9 years ago

Hello CRUD team,

When calling the database with the basic code below I get this alert: ERROR TypeError: Cannot read property 'onConnect' of undefined Everthing else seems to work fine.

window.dbAdapter = new CRUD.SQLiteAdapter('mydatabase.sqlite');

Please advise. Kind regards, Mario

MarioVanDenEijnde commented 9 years ago

Hello CRUD team,

The alert is fired in the CRUD.database.js

} catch(E) { alert("ERROR "+E.toString()); }

Kind regards, Mario

SchizoDuckie commented 9 years ago

Remove the .sqlite :) window.openDatabase handles that automatically.

Also, make sure to grab the latest version of crud.js and crud.sqliteadapter from my DuckieTV repo! It contains a lot of patches i haven't synxed here yet Op 25 okt. 2015 16:17 schreef "MarioVanDenEijnde" <notifications@github.com

:

Hello CRUD team,

When calling the database with the basic code below I get this alert: ERROR TypeError: Cannot read property 'onConnect' of undefined Everthing else seems to work fine.

window.dbAdapter = new CRUD.SQLiteAdapter('mydatabase.sqlite');

Please advise. Kind regards, Mario

— Reply to this email directly or view it on GitHub https://github.com/SchizoDuckie/CreateReadUpdateDelete.js/issues/2.

MarioVanDenEijnde commented 9 years ago

Hello SchizoDuckie,

I have replaced the 2 files. Now I get the following error messages: Uncaught TypeError: Cannot read property 'map' of undefined and Cannot read property 'prototype' of undefined

Should I change code also?

Kind regards, Mario

SchizoDuckie commented 9 years ago

Please have a look at js/CRUD.entities inside DuckieTV. The api has changed indeed. Op 25 okt. 2015 16:38 schreef "MarioVanDenEijnde" <notifications@github.com

:

Hello SchizoDuckie,

I have replaced the 2 files. Now I get the following error messages: Uncaught TypeError: Cannot read property 'map' of undefined and Cannot read property 'prototype' of undefined

Should I change code also?

Kind regards, Mario

— Reply to this email directly or view it on GitHub https://github.com/SchizoDuckie/CreateReadUpdateDelete.js/issues/2#issuecomment-150935543 .

MarioVanDenEijnde commented 9 years ago

Hello SchizoDuckie,

I have read the entities but not sure where it has changed apart from possible extra options. Can you be so kind and modify below to suit the new js files:

function crudDatabase(){
    window.dbAdapter = new CRUD.SQLiteAdapter('mydatabase');
    console.log(window.dbAdapter);
    console.log(JSON.stringify(window.dbAdapter));

    CRUD.Find(Presentation, {} , { onSuccess: function(result) {
            var pres = new Presentation();
            pres.set({
                id: 1,
                name: 'Mario',
                shirt: 'white'
            });
            pres.Save();
        }
    });

    CRUD.Find(Presentation, {} , { onSuccess: function(result) {
            for (var i=0; i< result.length; i++) {
                result[i].display();
            }
        }
    });
}

    var Presentation = CRUD.define({
            className: 'Presentation',
            table : 'people',
            primary : 'id',
            fields: ['id','name','shirt'],
            /*relations: {
                'Slide': CRUD.RELATION_MANY
            },
            connectors: {
                'Slide' : 'Presentationslide' // connectors are the way for RELATION_MANY to see what the joining table is
            },*/
            adapter: 'dbAdapter'
        }, {

        display: function() {
            console.log("Displaying presentation "+this.get('name'));
            console.log(this.databaseValues);
        }
    });

Kind regards, Mario

SchizoDuckie commented 9 years ago

Urgh what a mess. i realize that this demo code isn't even promise based yet.

I'll work on updating the repo, hold on :)

SchizoDuckie commented 9 years ago

i've started on a new round of docs and examples. I hope this gets you started for now! i'll work on more examples and more love for this repo over the coming days.

https://github.com/SchizoDuckie/CreateReadUpdateDelete.js/tree/master/demo

MarioVanDenEijnde commented 9 years ago

Hello SchizoDuckie,

Thanks. We are testing it now. Some question:

  1. I  notice you use database name “createreadupdatedelete”. But where do you set this? And how do I set my own database name?
  2. What is the meaning of the prototypeMethods? Can you give an example?

    Kind regards. Mario

MarioVanDenEijnde commented 9 years ago

Hello SchizoDuckie,

I tried the following: Something is missing but I don’t know where to look: Database (MyPT), table (foodlist) and content is already there (created with plain javascript) Error: Cannot use 'in' operator to search for 'id' in undefined Please advise.

Below the CRUD-MyPT.js

window.dbAdapter = new CRUD.SQLiteAdapter('MyPT');

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

CRUD.define(Food, { adapter: 'dbAdapter', className: 'Food', table: 'foodlist', primary: 'id', fields: [ 'id', 'contentType', 'title', 'portion', 'energy' ], autoSerialize: ['title'], indexes: [ 'title', ], createStatement: 'CREATE TABLE foodlist (id INTEGER PRIMARY KEY NOT NULL, contentType TEXT NOT NULL, title TEXT NOT NULL, portion TEXT NOT NULL, energy REAL NOT NULL)', });

CRUD.Find(Food, { title: 'TestFood' }).then(function(results) { console.log("Found results: ", results);

});

Kind regards, Mario

SchizoDuckie commented 9 years ago

The database name is set in the CRUD.setAdapter function.

The Prototypemethods are put onto the Named Function, For example:

image

w.i.p. online demo: https://schizoduckie.github.io/CreateReadUpdateDelete.js/demo/

SchizoDuckie commented 9 years ago

@MarioVanDenEijnde Your ' where in ' error probably originates in not using the CRUD.setAdapter call. Please, if you want more support, provide need a plunkr or something so that i can see interactively what's going wrong.

MarioVanDenEijnde commented 9 years ago

Hello ScizoDuckie,

I have never used Plunkr before but here is a start: http://plnkr.co/edit/iZc1ud4M8VFnpwR98w8F?p=preview

I don’t know how to invite you so you can collaborate though

Thanks. Kind regards, Mario

SchizoDuckie commented 9 years ago

I' ve modded your work so that it works now.

http://plnkr.co/edit/BTXMBH3vSWiafsOvEYfV?p=preview

On Wed, Oct 28, 2015 at 1:05 PM, MarioVanDenEijnde <notifications@github.com

wrote:

Hello ScizoDuckie,

I have never used Plunkr before but here is a start: http://plnkr.co/edit/iZc1ud4M8VFnpwR98w8F?p=preview

I don’t know how to invite you so you can collaborate though

Thanks. Kind regards, Mario

From: SchizoDuckie [mailto:notifications@github.com] Sent: Wednesday, October 28, 2015 12:25 PM To: SchizoDuckie/CreateReadUpdateDelete.js < CreateReadUpdateDelete.js@noreply.github.com> Cc: Mario van den Eijnde mario@delafini.com Subject: Re: [CreateReadUpdateDelete.js] ERROR TypeError: Cannot read property 'onConnect' of undefined (#2)

@MarioVanDenEijndehttps://github.com/MarioVanDenEijnde Your ' where in ' error probably originates in not using the CRUD.setAdapter call. Please, if you want more support, provide need a plunkr or something so that i can see interactively what's going wrong.

— Reply to this email directly or view it on GitHub< https://github.com/SchizoDuckie/CreateReadUpdateDelete.js/issues/2#issuecomment-151807725>.

— Reply to this email directly or view it on GitHub https://github.com/SchizoDuckie/CreateReadUpdateDelete.js/issues/2#issuecomment-151823949 .

MarioVanDenEijnde commented 9 years ago

Hello SchizoDuckie,

OK. I tested and it works. But questions:

  1. At this moment we use a json file and feed this arraylist to Typeahead/Bloodhound.

    So we create a search while you type. Would this be possible with your solution? And can you advise how to?

  2. How can we introduce wildcard search? In your DuckieTV I noticed that when typing “bat*” this would return also “blabla Batman”

I would like to do the same without the *

  1. How can we return all rows (no filter)?

Kind regards, Mario

SchizoDuckie commented 9 years ago

1) Load JSON file into for instance array ' items'

No further advice, that's just programming ;)

2) You can give a custom SQL string to CRUD.Find(myClass, [' where bla like %yada%']).then(function(result){} )

3) CRUD.Find(myClass).then(function(results) { // all rows are in results.} )

values and dirtyValues are internal properties of CRUD where it checks what properties have changed. Don't worry about them, use the accessors.

MarioVanDenEijnde commented 9 years ago

Hello

Code below returns : Uncaught (in promise) undefined What does this mean?

        CRUD.Find('Food', ['where title like %food%']).then(function(results) {
            console.log("Found results: ", JSON.stringify(results));
        });

Kind regards, Mario

MarioVanDenEijnde commented 9 years ago

Hello SchizoDuckie,

What is the use of “values” and "dirtyValues" in the result array? And can I get the result without these elements?

Kind regards, Mario

SchizoDuckie commented 9 years ago

values and dirtyValues are internal properties of CRUD where it checks what properties have changed.

Don't worry about them, use the accessors , you may want to check .asObject() (which returns a POJO without CRUD extended properties so that you can serialize it.

Your where query contains a syntax error:

where title like "%food%"'

Also, please have a look at using breakpoints. they will help you solve you problems because you can see what' s going wrong.

MarioVanDenEijnde commented 9 years ago

Hello SchizoDuckie,

Sorry but still Uncaught (in promise) undefined

        CRUD.Find('Food', ['where title like "%Food%"']).then(function(results) {
            console.log("Found results: ", JSON.stringify(results));
        });

And you probably mean it differently: .asObject is not a function

        CRUD.Find('Food').then(function(results) {
            console.log("Found results: ", JSON.stringify(results.asObject()));
        });

Maybe it is better to update your plunkr?

Kind regards, Mario

SchizoDuckie commented 9 years ago

Sorry man, I have a day job too :)

    // remove the 'where'

    CRUD.Find('Food', ['title like "%Food%"']).then(function(results) {
        console.log("Found results: ", JSON.stringify(results));
    });

    CRUD.Find('Food').then(function(results) {

         // results is an array here. you want to run .asObject on

an individual entity. like results[0] console.log("Found results: ", JSON.stringify(results.asObject())); });

On Wed, Oct 28, 2015 at 2:30 PM, MarioVanDenEijnde <notifications@github.com

wrote:

CRUD.Find('Food').then(function(results) { console.log("Found results: ", JSON.stringify(results.asObject())); });

MarioVanDenEijnde commented 9 years ago

Hello SchizoDuckie,

I appreciate your support and don't want to burden you. I hope I can still ask a question and you reply whenever you have the time or feel like it.

Thanks so far.

Kind regards, Mario

SchizoDuckie commented 9 years ago

Sure, feel free! :-) responsesc an take a bit longer thuogh

MarioVanDenEijnde commented 9 years ago

Hello SchizoDuckie,

OK. Just to be sure you know what I would like to get returned: JSON.stringify(results[0].asObject())); only returns the first. And iterating through all items seems a bit lame doesn't it?

Now we get:

[{"__values__":{"id":807,"contentType":"Food","title":"Isostar actifood","portion":"zakje (90 gram)","energy":184},"__dirtyValues__":{}},{"__values__":{"id":2950,"contentType":"Food","title":"TestFood 01","portion":"Glas","energy":100},"__dirtyValues__":{}}]

and I need:

[{"id":807,"contentType":"Food","title":"Isostar actifood","portion":"zakje (90 gram)","energy":184},{"id":2950,"contentType":"Food","title":"TestFood 01","portion":"Glas","energy":100}]

Kind regards, Mario

SchizoDuckie commented 9 years ago

.then(function(results) { return results.map(function(entity) { return entity.asObject() } ); } ? :)

On Wed, Oct 28, 2015 at 3:07 PM, MarioVanDenEijnde <notifications@github.com

wrote:

Hello SchizoDuckie,

OK. Just to be sure you know what I would like to get returned: JSON.stringify(results[0].asObject())); only returns the first. And iterating through all items seems a bit lame doesn't it?

Now we get:

[{"values":{"id":807,"contentType":"Food","title":"Isostar actifood","portion":"zakje (90 gram)","energy":184},"dirtyValues":{}},{"values":{"id":2950,"contentType":"Food","title":"TestFood 01","portion":"Glas","energy":100},"dirtyValues":{}}]

and I need:

[{"id":807,"contentType":"Food","title":"Isostar actifood","portion":"zakje (90 gram)","energy":184},{"id":2950,"contentType":"Food","title":"TestFood 01","portion":"Glas","energy":100}]

Kind regards, Mario

— Reply to this email directly or view it on GitHub https://github.com/SchizoDuckie/CreateReadUpdateDelete.js/issues/2#issuecomment-151856193 .

MarioVanDenEijnde commented 9 years ago

Your the man (or woman) can't tell by the name ;-)

Thanks

MarioVanDenEijnde commented 9 years ago

Hello SchizoDuckie,

Please take your time on this one: I want to build an app and include a json file with 100.000 objects (I don't want to fetch them from the internet because this will take too long) And when installing the app (or right after) I want to insert the objects into a database table. Would I just do:

jQuery.get('FoodListJson.txt',function(data){

and create records from the list? Or is there a better approach?

Kind regards, Mario

SchizoDuckie commented 9 years ago

If you' re going to perform 100.000 inserts I can recommend providing the user with a pre-filled database where tables are already created and filled. Inserting 100.000 records will take quite some time (and that can vary wildy based on the user' s device specs

Then again, i don't know about what kind of wrapper you' re using and if you can even access the webkit databases db to manually insert one.

If you have to do it clientside I would indeed just do a $.get with a promise and show the user some progress on what's happening ( Object.Observe(CRUD.Stats) will help you here)

On Wed, Oct 28, 2015 at 3:42 PM, MarioVanDenEijnde <notifications@github.com

wrote:

Hello SchizoDuckie,

Please take your time on this one: I want to build an app and include a json file with 100.000 objects (I don't want to fetch them from the internet because this will take too long) And when installing the app (or right after) I want to insert the objects into a database table. Would I just do:

jQuery.get('FoodListJson.txt',function(data){

and create records from the list? Or is there a better approach?

Kind regards, Mario

— Reply to this email directly or view it on GitHub https://github.com/SchizoDuckie/CreateReadUpdateDelete.js/issues/2#issuecomment-151867717 .

MarioVanDenEijnde commented 9 years ago

Hello SchizoDuckie,

Small question: CRUD.Find(myClass).then(function(results) only seems to return 1000 records (from about 2800) is this a setting somewhere?

Kind regards, Mario

MarioVanDenEijnde commented 9 years ago

Hello SchizoDuckie,

Small question: CRUD.Find(myClass).then(function(results) only seems to return 1000 records (from about 2800) is this a setting somewhere?

Kind regards, Mario

SchizoDuckie commented 9 years ago

Correct. This is a default protection so that the app won't choke on a huge dataset by default. :)

You can pass a third parameter to CRUD.Find with options.

CRUD.Find(class, {}, { limit: '0,10000' }).then()

Other options include:

MarioVanDenEijnde commented 9 years ago

And another small one.

I have read something about caching. Are the find results cached or stored in memory and I only have to recall the find after a data modification?

Kind regards, Mario

SchizoDuckie commented 9 years ago

CRUD.EntityManager doubles as both a caching layer and an Entity Manager.

You can find entities that have been cached in CRUD.EntityManger.cache and the entity definitions in CRUD.EntityManager.entities.

The cool thing about this is that all .Find queries run through this. this prevents race conditions by ensuring you'll always get a handle to same unique CRUD entity if multiple queries result in the same entity

MarioVanDenEijnde commented 9 years ago

Hello SchizoDuckie,

I have read the sentences multiple times and try to understand it. And though I was quite good at math in highschool (40 years back) this is of a higher magnitude. If you want to and think you can explain this for dummies then please do. But the main question for me is do I have to make specific code choices in order to use cache (memory) or the persistent one (hope this sentence makes sense) But the reason why I also ask is that I came across 2 database "processing" code libraries that work in the OS memory and therefore presume to be (much) faster then persistent database queries. They are called LokiJS and alaSQL. Working with these libraries means that one must be able to store and work with a significant amount of records and thus should allow a "big" database in memory. Do you know these libraries and is your "method" similar to those two, meaning your solution makes efficient use of available memory?

Kind regards, Mario

SchizoDuckie commented 9 years ago

Haha sorry, I've finished that sentence with my kid on my lap so It may have come out a bit wonky, sorry for that.

What I meant to say is that the library makes sure that there's always only one single instance of a database record, so there are not 4 clones of the same objects, but one reference to a 'master' CRUD entity (i hope that makes more sense)

The 'in memory' databases you refer to are a vastly different technology that requires serverside (nodejs) code. There it reserves a memory block and stores the full database in there. SQLite / WebSQL stores things in a .sqlite file, so that's a big difference.

I highly doubt you will require that though if you do some smart queries. I've stored up to 250 megabytes into an SQLite file and the performance is blazing.

CreateReadUpdateDelete is only as fast as the platform that runs the WebSQL code. If it's a phone, it's (logically) slower than a desktop, especially when using large batches of writes.

What CreateReadUpdateDelete does do to somewhat alleviate this, is give higher priority to SELECT queries than to INSERT queries. Ergo: If you queue up 1000 inserts (by creating new entities and running Persist() on them, 1000 promises will be queued up, which will each return a result when it's done or fails.

These 1000 new entities exist only in-memory (in the browser's context) when you haven't run Persist() on them, so you won't find them if you run any other select queries.

If you want a nice demo of some intense usage, please grab a nightly build of DuckieTV and have a look around :) Add some shows, and you'll see that there's a background queue where inserts happen, but the UI is still responsive. If you have an android tablet laying around you can grab the apk and compare the performance from within a Cordova environment.

SchizoDuckie commented 9 years ago

By the way, I'm working on extended docs here http://schizoduckie.github.io/CreateReadUpdateDelete.js/docs/

MarioVanDenEijnde commented 9 years ago

Thanks. Will take a look. And I have also installed DuckieTV on my desktop chrome yesterday.;-) Will install also on the Android tablet.

Thanks, Mario

MarioVanDenEijnde commented 9 years ago

Just one last thing tonight: I see code for create and code for update. In plain javascript I can do a "INSERT OR REPLACE INTO" Can I also use one to do an "upsert"?

Kind regards, Mario

SchizoDuckie commented 9 years ago

Nope, there is currently only an 'insert'

MarioVanDenEijnde commented 9 years ago

Hello SchizoDuckie

OK. What would you advise:

    • do something like 'UPDATE foodlist SET name="'+name+'" WHERE id = "'+itemId+'"; INSERT INTO foodlist SET id="'+itemId+'", name="'+name+'" WHERE changes() = 0;' But then in promise style using your code? OR
    • go back to the basic INSERT OR REPLACE INTO

I think I prefer 1. But could you write an example for this?

Kind regards, Mario

SchizoDuckie commented 9 years ago

I'm not certain what you want to accomplish. Can you give me some more info on the big picture here? How many records do you need to process? How often? Can't you easily pre-fetch the existing ones and update those? What does your datastructure and database structure look like?

MarioVanDenEijnde commented 9 years ago

We sync the local database with a remote one (remote to local). The recordset from remote includes new and updated records. This would mean that the id already exists in the local table or not. Id exists means an update. Id does not exist means insert. So what is the most efficient way to handle this?

Kind regards, Mario

SchizoDuckie commented 9 years ago

Ah, I see where you're getting at now. A replace into would definitely be the quickest way.

I just added a little patch that you'll like (make sure to grab the latest update from src/. untested, but should work.

var energiedrankjes = [{"id":807,"contentType":"Food","title":"Isostar actifood","portion":"zakje (90 gram)","energy":184},{"id":2950,"contentType":"Food","title":"TestFood 01","portion":"Glas","energy":100}];
Promise.all(energiedrankjes.map(function(row) {
 var el = CRUD.fromCache(Food, row);
 return el.Persist(true, 'REPLACE');
}).then(function(results) { 
  console.log("Klaar!", results); 
});
MarioVanDenEijnde commented 9 years ago

Thanks we will test this. And some question/remarks so I understand: 1.) the new/modified records are assembled in 1 json array to be processed. In our case we receive the updates in Xml and have to assemble the appropriate elements into 1 json string and then feed it to the replace process. 2.) We also have deletes (not frequently probably). Do we handle them individual or also in batch? 3.) the CRUD.fromCache takes the entity from cache so if the entity is not already in cache it will first be put in there to process the replace faster. Am I right in this?

By the way: Your dutch seems to be very good ;-)

MarioVanDenEijnde commented 9 years ago

We tested and it works. A follow up question on point 1.) above: From remote we retrieved XML and do a for each to capture the appropriate elements to store them in a assembled json string. Does your code divide the string into rows and do a replace for each row? If this is the case would it be more efficient to do a replace with every for each we do to transform the Xml to json?

4.) Could you give me more info how to use "Object.Observe(CRUD.Stats)" or point me to some doc info?

5.) Suppose we would do a Find on another field then the primary. Is it important to add this field to the indexes? I suppose so but just to make sure.

6.) You include a CRUD.entities.js in your demo (a DuckieTV copy): I suppose this file is taking care of all entity mappings in your solution. And you include this file in every application page where you need database info.

7.) CRUD.Entity.call(this); Why do we call this?

Cheers. Mario

MarioVanDenEijnde commented 9 years ago

Ah yes. and 8.) Is CreateReadUpdateDelete.js the minimized version of CRUD + CRUD.SqliteAdapter?

;-)

SchizoDuckie commented 9 years ago

Holy moly loads of questions :P, remind me to work this thread into a wiki or faq

1.) the new/modified records are assembled in 1 json array to be processed. In our case we receive the updates in Xml and have to assemble the appropriate elements into 1 json string and then feed it to the replace process.

Why would you transform the parsed XML into a string? Don't you mean a POJO (Plain Old Javascript Object ? )

2.) We also have deletes (not frequently probably). Do we handle them individual or also in batch?

I would say CRUD.ExecuteQuery('DELETE from Table where id in (1,4,5,6,9)') fire and forget :)

3.) the CRUD.fromCache takes the entity from cache so if the entity is not already in cache it will first be put in there to process the replace faster. Am I right in this?

Not exactly, fromCache here, means from any cache other than WebSQL. In this case, a POJO. It will be registered on the CRUD.EntityManager.cache as well. This doesn't really affect performance though.

By the way: Your dutch seems to be very good ;-)

Geen commentaar ;)

4.) Could you give me more info how to use "Object.Observe(CRUD.Stats)" or point me to some doc info?

There's no docs on this yet, but maybe this will give you some insights. (if you need more help, just shout)

5.) Suppose we would do a Find on another field then the primary. Is it important to add this field to the indexes? I suppose so but just to make sure.

Depends on how often you query it ofcourse, but yes, that's generally the idea of a field to add an index on.

6.) You include a CRUD.entities.js in your demo (a DuckieTV copy): I suppose this file is taking care of all entity mappings in your solution. And you include this file in every application page where you need database info.

That is correct. This is easier in DuckieTV since this is a Single Page Application, but if you have many different pages you will want to add the entities to the pages that use the functionality.

7.) CRUD.Entity.call(this); Why do we call this?

This fires off the parent constructor when creating an instance of the Entity. CRUD.define places the generic prototype methods on the Named function, the constructor places the values and dirtyValues instance properties on the instance (These can obviously not be set on the prototype)

CRUD.Entity = function(className, methods) {
    this.__values__ = {};
    this.__dirtyValues__ = {};
    return this;
}; 

8.) Is CreateReadUpdateDelete.js the minimized version of CRUD + CRUD.SqliteAdapter?

Correct, it's not up to date with the latest patches currently though (the insertMode is not yet in there), i'll sync that soon.

MarioVanDenEijnde commented 9 years ago

Yes sorry for the number of questions but we are learning ;D ad 1.) Yes I mean an assembly of json objects

Thanks

SchizoDuckie commented 9 years ago

Not a problem :) Always happy to share knowledge, and you've finally given me the kick to properly document this!

MarioVanDenEijnde commented 9 years ago

Hello SchizoDuckie,

Regarding: migrations: your DuckieTV CRUD.entities,js Does the migration work its way down? Or is the Migration number stored somewhere so the process knows which migration to execute? And why did you start with 5?

    migrations: {
        5: [
            'ALTER TABLE Series RENAME TO Series_bak',
            'CREATE TABLE Series (ID_Serie INTEGER PRIMARY KEY NOT NULL, name VARCHAR(250) DEFAULT(NULL), banner VARCHAR(1024) DEFAULT(NULL), overview TEXT DEFAULT(NULL), TVDB_ID INTEGER UNIQUE NOT NULL, IMDB_ID INTEGER DEFAULT(NULL), TVRage_ID INTEGER DEFAULT(NULL), networkid VARCHAR(50) DEFAULT(NULL), seriesid VARCHAR(50) DEFAULT(NULL), zap2it_id VARCHAR(50) DEFAULT(NULL), actors VARCHAR(1024) DEFAULT(NULL), airs_dayofweek VARCHAR(10) DEFAULT(NULL), airs_time VARCHAR(15) DEFAULT(NULL), contentrating VARCHAR(20) DEFAULT(NULL), firstaired DATE DEFAULT(NULL), genre VARCHAR(50) DEFAULT(NULL), language VARCHAR(50) DEFAULT(NULL), network VARCHAR(50) DEFAULT(NULL), rating INTEGER DEFAULT(NULL), ratingcount INTEGER DEFAULT(NULL), runtime INTEGER DEFAULT(NULL), status VARCHAR(50) DEFAULT(NULL), added DATE DEFAULT(NULL), addedby VARCHAR(50) DEFAULT(NULL), fanart VARCHAR(150) DEFAULT(NULL), poster VARCHAR(150) DEFAULT(NULL), lastupdated TIMESTAMP DEFAULT (NULL), lastfetched TIMESTAMP DEFAULT (NULL), nextupdate TIMESTAMP DEFAULT (NULL), displaycalendar TINYINT DEFAULT(1) )',
            'INSERT OR IGNORE INTO Series (ID_Serie, name, banner, overview, TVDB_ID, IMDB_ID, TVRage_ID, networkid, seriesid, zap2it_id, actors, airs_dayofweek, airs_time, contentrating, firstaired, genre, language, network, rating, ratingcount, runtime, status, added, addedby, fanart, poster, lastupdated, lastfetched, nextupdate) select ID_Serie, name, banner, overview, TVDB_ID, IMDB_ID, TVRage_ID, networkid, seriesid, zap2it_id, actors, airs_dayofweek, airs_time, contentrating, firstaired, genre, language, network, rating, ratingcount, runtime, status, added, addedby, fanart, poster, lastupdated, lastfetched, nextupdate from Series_bak',
            'DROP TABLE Series_bak'
        ],
        6: [
            'ALTER TABLE Series RENAME TO Series_bak',
            'CREATE TABLE Series (ID_Serie INTEGER PRIMARY KEY NOT NULL, name VARCHAR(250) DEFAULT(NULL), banner VARCHAR(1024) DEFAULT(NULL), overview TEXT DEFAULT(NULL), TVDB_ID INTEGER UNIQUE NOT NULL, IMDB_ID INTEGER DEFAULT(NULL), TVRage_ID INTEGER DEFAULT(NULL), actors VARCHAR(1024) DEFAULT(NULL), airs_dayofweek VARCHAR(10) DEFAULT(NULL), airs_time VARCHAR(15) DEFAULT(NULL), timezone VARCHAR(30) DEFAULT(NULL), contentrating VARCHAR(20) DEFAULT(NULL), firstaired DATE DEFAULT(NULL), genre VARCHAR(50) DEFAULT(NULL), country VARCHAR(50) DEFAULT(NULL), language VARCHAR(50) DEFAULT(NULL), network VARCHAR(50) DEFAULT(NULL), rating INTEGER DEFAULT(NULL), ratingcount INTEGER DEFAULT(NULL), runtime INTEGER DEFAULT(NULL), status VARCHAR(50) DEFAULT(NULL), added DATE DEFAULT(NULL), addedby VARCHAR(50) DEFAULT(NULL), fanart VARCHAR(150) DEFAULT(NULL), poster VARCHAR(150) DEFAULT(NULL), lastupdated TIMESTAMP DEFAULT (NULL), lastfetched TIMESTAMP DEFAULT (NULL), nextupdate TIMESTAMP DEFAULT (NULL), displaycalendar TINYINT DEFAULT(1) )',
            'INSERT OR IGNORE INTO Series (ID_Serie, name, banner, overview, TVDB_ID, IMDB_ID, TVRage_ID, actors, airs_dayofweek, airs_time, contentrating, firstaired, genre, language, network, rating, ratingcount, runtime, status, added, addedby, fanart, poster, lastupdated, lastfetched, nextupdate) select ID_Serie, name, banner, overview, TVDB_ID, IMDB_ID, TVRage_ID, actors, airs_dayofweek, airs_time, contentrating, firstaired, genre, language, network, rating, ratingcount, runtime, status, added, addedby, fanart, poster, lastupdated, lastfetched, nextupdate from Series_bak',
            'DROP TABLE Series_bak'
        ],
        7: [
            'ALTER TABLE Series RENAME TO Series_bak',
            'CREATE TABLE Series (ID_Serie INTEGER PRIMARY KEY NOT NULL, name VARCHAR(250) DEFAULT(NULL), banner VARCHAR(1024) DEFAULT(NULL), overview TEXT DEFAULT(NULL), TVDB_ID INTEGER UNIQUE NOT NULL, IMDB_ID INTEGER DEFAULT(NULL), TVRage_ID INTEGER DEFAULT(NULL), actors VARCHAR(1024) DEFAULT(NULL), airs_dayofweek VARCHAR(10) DEFAULT(NULL), airs_time VARCHAR(15) DEFAULT(NULL), timezone VARCHAR(30) DEFAULT(NULL), contentrating VARCHAR(20) DEFAULT(NULL), firstaired DATE DEFAULT(NULL), genre VARCHAR(50) DEFAULT(NULL), country VARCHAR(50) DEFAULT(NULL), language VARCHAR(50) DEFAULT(NULL), network VARCHAR(50) DEFAULT(NULL), rating INTEGER DEFAULT(NULL), ratingcount INTEGER DEFAULT(NULL), runtime INTEGER DEFAULT(NULL), status VARCHAR(50) DEFAULT(NULL), added DATE DEFAULT(NULL), addedby VARCHAR(50) DEFAULT(NULL), fanart VARCHAR(150) DEFAULT(NULL), poster VARCHAR(150) DEFAULT(NULL), lastupdated TIMESTAMP DEFAULT (NULL), lastfetched TIMESTAMP DEFAULT (NULL), nextupdate TIMESTAMP DEFAULT (NULL), displaycalendar TINYINT DEFAULT(1), autoDownload TINYINT DEFAULT(1), customSearchString VARCHAR(150) DEFAULT(NULL), watched TINYINT DEFAULT(0) )',
            'INSERT OR IGNORE INTO Series (ID_Serie, name, banner, overview, TVDB_ID, IMDB_ID, TVRage_ID, actors, airs_dayofweek, airs_time, timezone, contentrating, firstaired, genre, country, language, network, rating, ratingcount, runtime, status, added, addedby, fanart, poster, lastupdated, lastfetched, nextupdate, displaycalendar) select ID_Serie, name, banner, overview, TVDB_ID, IMDB_ID, TVRage_ID, actors, airs_dayofweek, airs_time, timezone, contentrating, firstaired, genre, country, language, network, rating, ratingcount, runtime, status, added, addedby, fanart, poster, lastupdated, lastfetched, nextupdate, displaycalendar from Series_bak',
            'DROP TABLE Series_bak'
        ],
        8: [
            'ALTER TABLE Series RENAME TO Series_bak',
            'CREATE TABLE Series (ID_Serie INTEGER PRIMARY KEY NOT NULL, name VARCHAR(250) DEFAULT(NULL), banner VARCHAR(1024) DEFAULT(NULL), overview TEXT DEFAULT(NULL), TVDB_ID INTEGER UNIQUE NOT NULL, IMDB_ID INTEGER DEFAULT(NULL), TVRage_ID INTEGER DEFAULT(NULL), actors VARCHAR(1024) DEFAULT(NULL), airs_dayofweek VARCHAR(10) DEFAULT(NULL), airs_time VARCHAR(15) DEFAULT(NULL), timezone VARCHAR(30) DEFAULT(NULL), contentrating VARCHAR(20) DEFAULT(NULL), firstaired DATE DEFAULT(NULL), genre VARCHAR(50) DEFAULT(NULL), country VARCHAR(50) DEFAULT(NULL), language VARCHAR(50) DEFAULT(NULL), network VARCHAR(50) DEFAULT(NULL), rating INTEGER DEFAULT(NULL), ratingcount INTEGER DEFAULT(NULL), runtime INTEGER DEFAULT(NULL), status VARCHAR(50) DEFAULT(NULL), added DATE DEFAULT(NULL), addedby VARCHAR(50) DEFAULT(NULL), fanart VARCHAR(150) DEFAULT(NULL), poster VARCHAR(150) DEFAULT(NULL), lastupdated TIMESTAMP DEFAULT (NULL), lastfetched TIMESTAMP DEFAULT (NULL), nextupdate TIMESTAMP DEFAULT (NULL), displaycalendar TINYINT DEFAULT(1), autoDownload TINYINT DEFAULT(1), customSearchString VARCHAR(150) DEFAULT(NULL), watched TINYINT DEFAULT(0), notWatchedCount INTEGER DEFAULT(0) )',
            'INSERT OR IGNORE INTO Series (ID_Serie, name, banner, overview, TVDB_ID, IMDB_ID, TVRage_ID, actors, airs_dayofweek, airs_time, timezone, contentrating, firstaired, genre, country, language, network, rating, ratingcount, runtime, status, added, addedby, fanart, poster, lastupdated, lastfetched, nextupdate, displaycalendar, autoDownload, customSearchString, watched) select ID_Serie, name, banner, overview, TVDB_ID, IMDB_ID, TVRage_ID, actors, airs_dayofweek, airs_time, timezone, contentrating, firstaired, genre, country, language, network, rating, ratingcount, runtime, status, added, addedby, fanart, poster, lastupdated, lastfetched, nextupdate, displaycalendar, autoDownload, customSearchString, watched from Series_bak',
            'DROP TABLE Series_bak'
        ]
    }

Kind regards, Mario

SchizoDuckie commented 9 years ago

Older migrations have been removed here because there' s no one that has a duckietv instance version 0.4 or so anymore, that would require including the migations all the way from version one.

On Fri, Oct 30, 2015 at 4:48 PM, MarioVanDenEijnde <notifications@github.com

wrote:

Hello SchizoDuckie,

Regarding: migrations: your DuckieTV CRUD.entities,js Does the migration work its way down? Or is the Migration number stored somewhere so the process knows which migration to execute? And why did you start with 5?

migrations: {
    5: [
        'ALTER TABLE Series RENAME TO Series_bak',
        'CREATE TABLE Series (ID_Serie INTEGER PRIMARY KEY NOT NULL, name VARCHAR(250) DEFAULT(NULL), banner VARCHAR(1024) DEFAULT(NULL), overview TEXT DEFAULT(NULL), TVDB_ID INTEGER UNIQUE NOT NULL, IMDB_ID INTEGER DEFAULT(NULL), TVRage_ID INTEGER DEFAULT(NULL), networkid VARCHAR(50) DEFAULT(NULL), seriesid VARCHAR(50) DEFAULT(NULL), zap2it_id VARCHAR(50) DEFAULT(NULL), actors VARCHAR(1024) DEFAULT(NULL), airs_dayofweek VARCHAR(10) DEFAULT(NULL), airs_time VARCHAR(15) DEFAULT(NULL), contentrating VARCHAR(20) DEFAULT(NULL), firstaired DATE DEFAULT(NULL), genre VARCHAR(50) DEFAULT(NULL), language VARCHAR(50) DEFAULT(NULL), network VARCHAR(50) DEFAULT(NULL), rating INTEGER DEFAULT(NULL), ratingcount INTEGER DEFAULT(NULL), runtime INTEGER DEFAULT(NULL), status VARCHAR(50) DEFAULT(NULL), added DATE DEFAULT(NULL), addedby VARCHAR(50) DEFAULT(NULL), fanart VARCHAR(150) DEFAULT(NULL), poster VARCHAR(150) DEFAULT(NULL), lastupdated TIMESTAMP DEFAULT (NULL), lastfetched TIMESTAMP DEFAULT

(NULL), nextupdate TIMESTAMP DEFAULT (NULL), displaycalendar TINYINT DEFAULT(1) )', 'INSERT OR IGNORE INTO Series (ID_Serie, name, banner, overview, TVDB_ID, IMDB_ID, TVRage_ID, networkid, seriesid, zap2it_id, actors, airs_dayofweek, airs_time, contentrating, firstaired, genre, language, network, rating, ratingcount, runtime, status, added, addedby, fanart, poster, lastupdated, lastfetched, nextupdate) select ID_Serie, name, banner, overview, TVDB_ID, IMDB_ID, TVRage_ID, networkid, seriesid, zap2it_id, actors, airs_dayofweek, airs_time, contentrating, firstaired, genre, language, network, rating, ratingcount, runtime, status, added, addedby, fanart, poster, lastupdated, lastfetched, nextupdate from Series_bak', 'DROP TABLE Series_bak' ], 6: [ 'ALTER TABLE Series RENAME TO Series_bak', 'CREATE TABLE Series (ID_Serie INTEGER PRIMARY KEY NOT NULL, name VARCHAR(250) DEFAULT(NULL), banner VARCHAR(1024) DEFAULT(NULL), overview TEXT DEFAULT(NULL), TVDB_ID INTEGER UNIQUE NOT NULL, IMDB_ID INTEGER DEFAULT(NULL), TVRage_ID INTEGER DEFAULT(NULL), actors VARCHAR(1024) DEFAULT(NULL), airs_dayofweek VARCHAR(10) DEFAULT(NULL), airs_time VARCHAR(15) DEFAULT(NULL), timezone VARCHAR(30) DEFAULT(NULL), contentrating VARCHAR(20) DEFAULT(NULL), firstaired DATE DEFAULT(NULL), genre VARCHAR(50) DEFAULT(NULL), country VARCHAR(50) DEFAULT(NULL), language VARCHAR(50) DEFAULT(NULL), network VARCHAR(50) DEFAULT(NULL), rating INTEGER DEFAULT(NULL), ratingcount INTEGER DEFAULT(NULL), runtime INTEGER DEFAULT(NULL), status VARCHAR(50) DEFAULT(NULL), added DATE DEFAULT(NULL), addedby VARCHAR(50) DEFAULT(NULL), fanart VARCHAR(150) DEFAULT(NULL), poster VARCHAR(150) DEFAULT(NULL), lastupdated TIMESTAMP DEFAULT (NULL), lastfetched TIMESTAMP DEFAULT (NULL), nextupdate TIMESTAMP DEFAULT (N ULL), displaycalendar TINYINT DEFAULT(1) )', 'INSERT OR IGNORE INTO Series (ID_Serie, name, banner, overview, TVDB_ID, IMDB_ID, TVRage_ID, actors, airs_dayofweek, airs_time, contentrating, firstaired, genre, language, network, rating, ratingcount, runtime, status, added, addedby, fanart, poster, lastupdated, lastfetched, nextupdate) select ID_Serie, name, banner, overview, TVDB_ID, IMDB_ID, TVRage_ID, actors, airs_dayofweek, airs_time, contentrating, firstaired, genre, language, network, rating, ratingcount, runtime, status, added, addedby, fanart, poster, lastupdated, lastfetched, nextupdate from Series_bak', 'DROP TABLE Series_bak' ], 7: [ 'ALTER TABLE Series RENAME TO Series_bak', 'CREATE TABLE Series (ID_Serie INTEGER PRIMARY KEY NOT NULL, name VARCHAR(250) DEFAULT(NULL), banner VARCHAR(1024) DEFAULT(NULL), overview TEXT DEFAULT(NULL), TVDB_ID INTEGER UNIQUE NOT NULL, IMDB_ID INTEGER DEFAULT(NULL), TVRage_ID INTEGER DEFAULT(NULL), actors VARCHAR(1024) DEFAULT(NULL), airs_dayofweek VARCHAR(10) DEFAULT(NULL), airs_time VARCHAR(15) DEFAULT(NULL), timezone VARCHAR(30) DEFAULT(NULL), contentrating VARCHAR(20) DEFAULT(NULL), firstaired DATE DEFAULT(NULL), genre VARCHAR(50) DEFAULT(NULL), country VARCHAR(50) DEFAULT(NULL), language VARCHAR(50) DEFAULT(NULL), network VARCHAR(50) DEFAULT(NULL), rating INTEGER DEFAULT(NULL), ratingcount INTEGER DEFAULT(NULL), runtime INTEGER DEFAULT(NULL), status VARCHAR(50) DEFAULT(NULL), added DATE DEFAULT(NULL), addedby VARCHAR(50) DEFAULT(NULL), fanart VARCHAR(150) DEFAULT(NULL), poster VARCHAR(150) DEFAULT(NULL), lastupdated TIMESTAMP DEFAULT (NULL), lastfetched TIMESTAMP DEFAULT (NULL), nextupdate TIMESTAMP DEFAULT (N ULL), displaycalendar TINYINT DEFAULT(1), autoDownload TINYINT DEFAULT(1), customSearchString VARCHAR(150) DEFAULT(NULL), watched TINYINT DEFAULT(0) )', 'INSERT OR IGNORE INTO Series (ID_Serie, name, banner, overview, TVDB_ID, IMDB_ID, TVRage_ID, actors, airs_dayofweek, airs_time, timezone, contentrating, firstaired, genre, country, language, network, rating, ratingcount, runtime, status, added, addedby, fanart, poster, lastupdated, lastfetched, nextupdate, displaycalendar) select ID_Serie, name, banner, overview, TVDB_ID, IMDB_ID, TVRage_ID, actors, airs_dayofweek, airs_time, timezone, contentrating, firstaired, genre, country, language, network, rating, ratingcount, runtime, status, added, addedby, fanart, poster, lastupdated, lastfetched, nextupdate, displaycalendar from Series_bak', 'DROP TABLE Series_bak' ], 8: [ 'ALTER TABLE Series RENAME TO Series_bak', 'CREATE TABLE Series (ID_Serie INTEGER PRIMARY KEY NOT NULL, name VARCHAR(250) DEFAULT(NULL), banner VARCHAR(1024) DEFAULT(NULL), overview TEXT DEFAULT(NULL), TVDB_ID INTEGER UNIQUE NOT NULL, IMDB_ID INTEGER DEFAULT(NULL), TVRage_ID INTEGER DEFAULT(NULL), actors VARCHAR(1024) DEFAULT(NULL), airs_dayofweek VARCHAR(10) DEFAULT(NULL), airs_time VARCHAR(15) DEFAULT(NULL), timezone VARCHAR(30) DEFAULT(NULL), contentrating VARCHAR(20) DEFAULT(NULL), firstaired DATE DEFAULT(NULL), genre VARCHAR(50) DEFAULT(NULL), country VARCHAR(50) DEFAULT(NULL), language VARCHAR(50) DEFAULT(NULL), network VARCHAR(50) DEFAULT(NULL), rating INTEGER DEFAULT(NULL), ratingcount INTEGER DEFAULT(NULL), runtime INTEGER DEFAULT(NULL), status VARCHAR(50) DEFAULT(NULL), added DATE DEFAULT(NULL), addedby VARCHAR(50) DEFAULT(NULL), fanart VARCHAR(150) DEFAULT(NULL), poster VARCHAR(150) DEFAULT(NULL), lastupdated TIMESTAMP DEFAULT (NULL), lastfetched TIMESTAMP DEFAULT (NULL), nextupdate TIMESTAMP DEFAULT (N ULL), displaycalendar TINYINT DEFAULT(1), autoDownload TINYINT DEFAULT(1), customSearchString VARCHAR(150) DEFAULT(NULL), watched TINYINT DEFAULT(0), notWatchedCount INTEGER DEFAULT(0) )', 'INSERT OR IGNORE INTO Series (ID_Serie, name, banner, overview, TVDB_ID, IMDB_ID, TVRage_ID, actors, airs_dayofweek, airs_time, timezone, contentrating, firstaired, genre, country, language, network, rating, ratingcount, runtime, status, added, addedby, fanart, poster, lastupdated, lastfetched, nextupdate, displaycalendar, autoDownload, customSearchString, watched) select ID_Serie, name, banner, overview, TVDB_ID, IMDB_ID, TVRage_ID, actors, airs_dayofweek, airs_time, timezone, contentrating, firstaired, genre, country, language, network, rating, ratingcount, runtime, status, added, addedby, fanart, poster, lastupdated, lastfetched, nextupdate, displaycalendar, autoDownload, customSearchString, watched from Series_bak', 'DROP TABLE Series_bak' ] }

Kind regards, Mario

— Reply to this email directly or view it on GitHub https://github.com/SchizoDuckie/CreateReadUpdateDelete.js/issues/2#issuecomment-152562105 .