Live update not working with numtel:mysql

I’m in the process of refactoring the code from mongo to mysql by using @numtel 's numtel:mysql.

The original repo https://github.com/tenzan/blog. Online: http://askar-blog.meteor.com
I’ve created a branch blog-mysql : https://github.com/tenzan/blog/tree/blog-mysql

For the beginning I’m just trying to:

  1. List up all posts - This is done.
  2. When I remove or add a post, the UI has to reflect those changes automatically. Which is not working. (I have another rails app that’s using same DB. So when I was adding or removing a post from there, the meteor app didn’t change the UI automatically.)

The refactored places:


client/main.js:

// Meteor.subscribe('posts'); 

I’ve comment out the line as it’s related to mongo. I thought I should replace with something like

MysqlSubscription('posts');

But just this line it seems not sufficient… I’m feeling like this is the place why it’s not getting updating when DB changed.


client/templates/posts/posts_list.js

Template.postsList.helpers({
    posts: function () {
        //return Posts.find({}, {sort: {submitted: -1}});
        return Posts.reactive();
    }
});

lib/collections/posts.js

// Posts = new Mongo.Collection('posts');
Posts = new MysqlSubscription('posts');

lib/router.js

Router.configure({
    layoutTemplate: 'layout',
    loadingTemplate: 'loading',
    waitOn: function () {
        //return Meteor.subscribe('posts');
        return Posts.reactive();
    }
});

server/publications.js

// Meteor.publish('posts', function () {
//     return Posts.find();
// });
var liveDb = new LiveMysql({
    host: 'localhost',
    post: 3306,
    user: 'root',
    password: 'root',
    database: 'postag_development'
});

var closeAndExit = function () {
    liveDb.end();
    process.exit();
};
// Close connections on hot code push
process.on('SIGTERM', closeAndExit);
// Close connections on exit (ctrl + c)
process.on('SIGINT', closeAndExit);


Meteor.publish('posts', function () {
    return liveDb.select(
        'SELECT * FROM posts ORDER BY created_at DESC',
        [{table: 'posts'}]
    );
});

I hope this post will be a subject of interest for many people. :smile:

Thanks.

I feel like this is the case when I have to use DDP clients when doing changes in database, so that live update will work… Not sure.

First, I’m going to try inserts and deletes within from Meteor app itself and then see if live update works.

I first had a play with numtel:mysql back in March, so I thought I should go back to that code, bring it up to date (meteor update) and see if it still worked.

It did - and my code is very similar to yours, so I suspect you may have missed a step in the database and/or privileges configuration.

  1. You need to enable binary logging.
  2. You need to enable row-based replication.
  3. The user you connect as must have:
  • Appropriate privileges to read/write your database(s).
  • Also have replication client privilege.
  • Also have replication slave privilege.

That’s about it, really. I get full reactivity through to the template (I can use phpmyadmin to edit a row and it’s instantly updated on the Meteor app.)

EDIT: Your LiveMysql options are missing a serverId, which is needed for replication (the number chosen must not already exist in your physical MySQL replication configuration - in my.ini). Also, you have declared post: 3306, which should be port: 3306, although I suspect this would work anyway, as it’s the default.

2 Likes

Thanks! :slight_smile:

I found serverId and other stuff you’ve mentioned here https://github.com/numtel/mysql-live-select

My understanding is mysql-live-select is already included in the numtel:mysql, correct?

Thanks a lot!

I was able to fix this by only making changes in my my.cnf:

log_bin
server_id = 1
binlog_format    = row

I didn’t do any replication settings…

Weird…

Now after I was able to see the changes in realtime by changing the db out of the Meteor app for posts, I can’t even list the tags… I just did refactoring same ways as I did for posts, but it’s showing up blank page for tags.

UPDATE: In my router.js:

waitOn: function () {
return Posts.reactive();
return Tags.reactive();
}

In WebStorm, the return for Tags.reactive() has some foggy background and when I hover mouse on it, it says: Unreachable code, so I suspect there’s something wrong with my tags related code…

hi, thanks for all explication.

i try to do the same think but the problem that i should write it in Type script can you help me .

thank you.

Pls help me . Why is not updated?