masumsoft / express-cassandra

Cassandra ORM/ODM/OGM for NodeJS with support for Apache Cassandra, ScyllaDB, Datastax Enterprise, Elassandra & JanusGraph.
http://express-cassandra.readthedocs.io
GNU Lesser General Public License v3.0
232 stars 68 forks source link

Cannot map model object to a table with a collection #165

Closed vgjenks closed 6 years ago

vgjenks commented 6 years ago

Using latest driver w/ Cassandra 3.11. Created the following table and UDT:

create keyspace if not exists admin
with replication = {
    'class': 'SimpleStrategy',
    'replication_factor': 1
};

use admin;

create type role_permission (
    permission_name text,
    permission_friendly_name text,
    permission_descr text,
    status_flag int
);

create table if not exists user_profile (
    user_profile_id text,
    first_name text,
    last_name text,
    email text,
    auth_token text,
    role_permissions frozen<set<role_permission>>,
    last_mod_timestamp timestamp,
    create_timestamp timestamp,
    status_flag int,
    primary key (user_profile_id)
);

Mapping w/ the following object (user_profileModel.js):

module.exports = {
    fields: {
        user_profile_id: "text",
        first_name: "text",
        last_name: "text",
        email: "text",
        auth_token: "text",
        role_permissions: {
            type: "frozen",
            typeDef: "<set<role_permission>>"
        },
        last_mod_timestamp: "timestamp",
        create_timestamp: "timestamp",
        status_flag: "int"
    },
    key: ["user_profile_id"]
};

Results in the following error:

apollo.model.tablecreation.schemamismatch: Given Schema does not match existing DB Table "user_profile"migration suspended, please apply the change manually

Strangely enough, if I let express-cassandra generate the keyspace and table, it works...the first time. It's all there. If I restart the app, I get the same error described above. If I remove the "role_permissions" collection from the table/entity, it works just fine. Single UDTs also work just fine - it's only collections of UDTs that do not.

vgjenks commented 6 years ago

Follow up: Even though the exception occurs, the ORM continues to behave properly, as expected. As ugly as it is; as long as I handle the exception...and ignore it...everything seems fine. My application continues to read and write data, regardless.

masumsoft commented 6 years ago

It looks like you've defined the UDT by hand and the definition is not present in express-cassandra configuration you are using, hence the error I guess. Express cassandra manages the udt for you using your configuration and you don't need to create them by hand. As you've created them already, you can also just set the udt definition in your express-cassandra config to eliminate the error.

Have a look at the express-cassandra documentation for udt to get the idea to do it.

vgjenks commented 6 years ago

That's definitely not the case - sorry to omit the configuration. The UDT and tables are both configured. It appears to be a migrations issue because I can catch this error and ignore it, and everything appears to work (except migrations.)

Re-open this issue or should I post a new one?

masumsoft commented 6 years ago

Ok could you post your configuration here?

vgjenks commented 6 years ago

Sorry, had already posted a new issue. I believe it has better detail and explanation anyhow. Thanks.

masumsoft commented 6 years ago

ok then closing this one