Sending automated email on database update using AWS - mysql

I have a cross platform app built that uses Amazon AWS to manage the backend. I have a MySQL database created that sends and receives data to and from.the app via API calls.
This is working perfect.
On the app I have a from that users can fill in. One of the questions relates to the severity of an action e.g. high, medium and low. Once the user completes and submits the form, the data is sent to MySQL database - again, working 100%.
However, based on the answer of the question re. severity, I need to automate an email to a relevant person. E.g. if the answer was high, an email should automatically be triggered to a person.
Using the mobile OS's built in email functionality (I.e. using sendto: function) is not an option as users might not have this configured and it's not user friendly for my user base.
Is there a way I can trigger generic emails automatically from Amazon AWS if the relevant field on MySQL database is updated with a specified value?
I have no idea where to start with this or if there is a better/easier way.

As mentioned in commends you can send that email in layer between your front end and db.. Other option is migrating from MySQL to Aurora.
Third Option is that create a cronjob on some Unix server like every minute which queries this table to see if any new record in last one minute and send an email using sendmail or mutt.

Related

How to receive MySQL database notifications in Delphi?

I am developing a Delphi XE7 application with data stored in an online Mysql database. For the database access I use FireDAC. Because the application can be used on more than one computer simultaneously I need to be notified when a table is changed, so I can update the displayed information on each computer. FireDAC has a component called TFDEventAlerted which sounded like exactly what I need for this. But this component gives an error when activating (calling Register): [FireDAC][Phys][MySQL]-303. Capability is not supported.
I am not sure what this means, but after reading more about the component it seems Mysql does not support this type of events? If so: can anyone tell me whether there is another solution to accomplish the same?
Any help would be appreciated as I cannot seem to find a good solution.
Native MySQL doesn't have the push-notification feature you're hoping to use. To make this work you'll need to poll (to regularly run a query) to look for changes.
There are some ways to overcome this limitation if the scale of your system makes polling infeasible. You could add a user-defined function to your MySQL server, like this one to send messages: https://github.com/mysqludf/lib_mysqludf_stomp#readme
This won't work if you don't own the MySQL server; most hosting services won't allow you to install UDFs.
Or, you could build a message publish/subscribe app. This is pretty easy to do with the Amazon simple queuing service or with rabbitmq. But it's a different kind of system design from what you are probably used to.
In my article series about Firebird Database Events I proposed a solution based on message-oriented middleware. The middle tier of your application then would notify all interested parties about certain database events. Middle tier code would be database independent, all you need is a message broker who is specialized in reliable message delivery. An imaginary example for a 'after post' event handler is shown below:
procedure TAppDataModule.PurchaseOrderAfterPost(DataSet: TDataSet);
var
Notification: INotification;
begin
Notification := NotificationService.CreateNotification(PURCHASE_ORDER_TABLE_UPDATED);
Notification.SetIntProperty(PURCHASE_ORDER_ID, PurchaseOrderID.AsInteger);
NotificationService.Send(Notification);
end;
Popular free/libre open source message brokers are for example Apache ActiveMQ and RabbitMQ.
TFDEventAlerted control is not for MySQL database. That database doesn't support event model. If you want update data in "real time" then you must add manual request for changed data
Here are steps:
Add new field to your database table like "last_updated";
Fill that field by now() value on update or insert actions (by trigger or sql);
Add timer to delphi app and add request by SELECT MAX(last_updated) AS last_updated FROM my_table for last updated time;
If that time is new then request updated data by SELECT * FROM my_table WHERE last_updated >= :need_last_updated.

Store custom data for each user in ejabberd

I need to store data for each user in ejabberd.How can I do this ? I mean I need to add one more field to user table and I should update this data whenever.
How can I do this ?
This is what I am doing.
During registration process in my Android Chat application, I post data like the desired userid (jabberid), password, email, display name, gender, mobile etc. to my PHP API. The PHP code validates if userid already exists and if it doesn't then it creates the user first in an external mysql database, storing all the fields received in post, and then creates the real user in ejabberd by executing the ejabberdctl register command. There will be some permission issues executing the command inside apace\PHP which I successfully resolved using this answer here. Now I can access the user data using my PHP API.
The idea is that I am not overloading the mnesia database with rarely accessed or modified data. IMHO, this helps if you don't want to switch ejabberd to odbc\mysql mode and lose potential benefits of mnesia or if you are planning to run mnesia in "RAM Only" mode. All this I am saying with limited knowledge of ejabberd, hence don't take my word as gospel.

How to synchronize a SQLite Core Data database with a remote MySQL database?

I recently completed work on an iOS app, and everything for the most part is working the way it should with the app. I have managed to create a multi-user app that uses Core Data to persist to a SQLite DB. However, the time has come where the users would like to manage their account from a remote device, i.e. their own phone, or whatever web enabled device their using. With that said, I have done a little google searching and have discovered that I am going to need to create a "web service". Now the caveat is that I already accumulated data in the SQLite DB on the iDevice that is running the app. I would like to push the existing data to a MySQL DB or a remote machine, and have it synchronized. For example when a user updates their account on the iOS device, the change gets pushed to the MySQL DB, and if the user connects to a web service using a standard browser that is updates the SQLite DB on the iOS device.
I started learning rails because I figured it would be a good solution to create a simple web front-end for the user to manage their account with, and it exposes an API for a developer to manipulate data in the database. Basically, I would like to hear some suggestions from the community, or links that could provide a good starting point for what I'm trying to accomplish.
If you're looking at rails, try taking a peek at ActiveAdmin gem. It's what I used on my first iOS and rails project for a client. It gives you an administrative dashboard that'll handle a lot of what you'll be wanting if you can get it set up. It's very confusing at first, but a few weeks will give you a pretty good web solution. In addition, depending on your experience in creating servers, you might want to look at heroku for a low cost host that does all the work for you (if you start needing more processors though, Heroku gets pricy very quickly). From a github project, you can have heroku up and running your rails code in about 5 minutes flat.
As far as synchronizing your database from Server To Phone: You'll want to institute a type of last_updated_at timestamp for your models on the server DB. Now when anything is updated, you'll update the timestamp. Now the iOS app can pass a ?last_updated_at parameter to your server. This will allow your server to figure out everything that has changed since the last time they pinged the server. Then gnab it into your core data db on the phone.
For Syncing Phone to Server:
First make sure the phone is up to date before syncing (using last_updated_at param). If it's clear, then this is where it's hard. You'll need to translate the objects you want to sync from the CoreData db (since it adds it's own columns/tables automatically) and pass them up. Otherwise you can pass up your coreData db and do some kind of conversion on the server.
OR
Do a conversion in your iPhone app with an update to migrate off of CoreData. This will be a pain but it'll help in the long run if you deploy to other OS's. You'll need to create sqlite3 queries to convert the CoreData db into a new SQL DB (we were able to copy 2-3MB of data within 1.2 seconds on an iPhone 5 so it's pretty quick). Then the app will only use SQLite3 so that it can sync up the full DB to the server. Then this will make syncing with the phone easier, where it can just grab the full DB from the server and plug it in.
typedef NS_ENUM(NSInteger, RecordStatus){
RecordStatusUnchanged = 0,
RecordStatusUpdated = 1,
RecordStatusAdded = 2,
RecordStatusRemoved = 3
};
Create a new SQL table named change_record. column like ( item_id, status, category_name)
For Update
change_record table: from the local database, you will get item_id, keep status RecordStatusUpdated, and set the category_name
For Add
change_record table: item_id will empty, keep status RecordStatusAdded
, set the category_name
For Deletion
change_record table: from the local database, you will get item_id, keep status RecordStatusRemoved
, set the category_name empty
Use a background service to check internet connection is available for each n time interval.
if change_record count > 0.
then send all items(using loop) to the server

How do I run a function with a table update trigger?

I'm new in this forum and this is my first question.
I've made a database in access for process control and I want to have the this database separated in local applications, linked with the tables, on the server.
Once this database is a process controller, it has a control pannel, designed in a form, with buttons that indicate different states during the process. This control pannel is opened in several computers and must be updated every time the tables are updated. How do I spread the trigger for all the database users? I've tried already, but only the active app, this means, the app who changed the table, is modified.
Pleasem, help! I don't know whatelse to do.
The backend database (access) you use is simply a data storage. It cannot run VBA itself or raise events. So you have to rely on your frontends to detect data-changes. And strangely access detecs no datachanges in open forms that do not originate from the respective client.
So you will have to check for changes yourself. The best bet would probably be with a timer and a routine that checks either for datachanges in a remote table or for some other trigger (like file change time etc..)
If you have any kind of server you could also create a small service where each of your access-instances can register. Then you could create triggers (afterChange or whatever you need) in your frontends that call that service, which then calls teh respective routines in each of the registered instances. This would be preferable, if you have many frontend running or if network load is of concern.

How do i capture mysql triggers and stored procedures in my vb.net application?

Hey i need some help here, i am developing a vb.net desktop application using visual Studio 2010 and mysql v5.5 whose database will be located in a main server hence the applications will have to communicate with the the database to get/post information.
My problem however is that, i want my applications to have a real time update of the database content such that if user1 updates the database, it immediately reflects that in user2's application. I have read articles that recommend use of triggers and Stored Procedures in mysql syntax to do this but i have no idea how this will work.
I have a table called 'Store' , when a user enters an item in table store, i'd like the application to know it and update the Item and its contents in a listbox or datagrid.
How do i capture these events in my vb.net code?
I hope i am clear enough, if not please ask. All your suggestions will be highly appreciated!
I think the easiest way to solve the problem would be to periodically get the records from the server and update the local list appropriately. On your client application you could store the last time the list was updated, and send that as a parameter when you do the get and get all the items that were created after that time (that way you only get new items).
Another possible solution would be to have a client register with the server application (so the server keeps track of all the clients) and when you create a new record you send that new record to all the clients, which would be listening for that event.
It's sort of hard to say what the 'best' approach is in your situation. How is your code designed (what's the architecture)? Are connections between the client and server applications persistent? Is there a server application that your client application talks to or is each client directly talking to the database?