Database Schema in Zend Framework 2 - mysql

I am new in zend framework 2. I am alwasys wondering that how to maintain database schema in my web application. suppose i had a website and later on i decided to add new features in my website and it need 5 more tables in an existing database.
Problem:
How can i create database tables in mysql if they are not exist, if not exist then create new tables before new feature are initiated in zend framework 2?. By doing this I also maintane my application version control.
Example:
As we did in in wordpress. When we install a new plugin we check first that database has tables for plugin work, if not then we create database first.
Please share with me, what are the Best Practices to overcome this problem.

First to do that you need a migration tool like phinx, it will allow you to build migration script and of course rollback script. Moreover you can version your migration scripts, and you can manage different detabase environment and migrating or rollbacking them one by one.
Phinx is easy to use, light and not framework dependent, I don't think it is the best tool ever but it does its duty.
But it works in command line (could be used in ZF2, there are modules, or you using exec command)

Related

What is the correct way of structuring mySQL code in a nodejs projects?

I have been working on a project lately and using node as my back-end but instead of Mongodb I am using MySQL as my DBMS as I will need it in my project but I am having trouble organizing MySQL queries and can't find a good solution that helps me structure my code and files right. And another issue is that I don't know when to close my connection or if leaving it is a good practice or not.
NOTE: I already use express generator for generating my file architecture my only problem is where to place the MySQL related code and what are the best practices for a clean code.
You can create a model folder and add all your 'tables'.js there.
You can also create a DB.js file, so you can use Mysql from Nodejs and also manipulate it from the prompt:
Model Exemple
I.e of DB connection:
DB Connection
You can create tables on the way below. ID's, creating date and updated date are created automatically by Nodejs, so you don't need to worry about.
how to create a table
You also will need to download mySQL (npm install MySQL --save) and to interact with MySQL (selects, deletes,...)
Another way is create a repository.js and add SQL queries there, but is not really useful since you are using nodejs and it provides you these queries.

Domain classes and database are out of sync in Grails

I've this weird problem. I have a Grails app in which some database changelog files are missing. Therefore, the database has gone out of sync with the domain classes. I've done some changes in the domain classes. When I try to run the database migration plugin, it is creating a diff betweeb the current domain classes and the database and try to execute all the sql commands that has already been run which is causing error in executing the commands that I want to execute.
Is there is a solution for this problem?
If I understand your problem correctly, you can re-create all of the missing changelogs using dbm-generate-changelog. This will create changelogs based on the current data model. Then you can use dbm-changelog-sync to mark those changelogs as EXECUTED (which will populate the DATABASECHANGELOG table). Once the DATABASECHANGELOG table is in sync with the current data model, you can use dbm-gorm-diff to make sure you're not missing any other data model changes.
https://grails-plugins.github.io/grails-database-migration/1.4.0/ref/Maintenance%20Scripts/dbm-changelog-sync.html
NOTE: My answer assumes you're using Grails 2.x and Database Migration plugin 1.4.x, but I believe the process is similar in Grails 3.x with Database Migration Plugin 2.x or 3.x.

Meteor - Mysql (Integration between LAMP and Meteor.JS) cross platform

I have an existing application based in LAMP and now I am looking to develop a new module of the existing system in Meteor.JS (Only New Module, keeping the existing system as it is)
I know that Mysql is not officially supported till now in Meteor. I have gathered some knowledge that, using a package numtel:mysql, we may get support for mysql, but I feel that is also limited.
Now, my question is: I have one project built on a LAMP stack, and I wanted to develop a new module for this in Meteor using the same Mysql database, as its contains existing records. (I know that I have to do some workaround for sign-in and authentication between two, and that I have to take care too.
But I just wanted to know, Is it possible to use the existing system (Mysql database) and what are the possibilities of creating a new module in Meteor. Can someone put shed light into this scenario?
Also, can someone suggest to me how to do single sign-on between these two different applications (LAMP and Meteor)
What are the steps that I should take in order to achieve this?

how I can create a table and a trigger in mysql with springframework and maven?

I am continuing the development of an android app that works against a server using maven, springframework and server database is MySQL.
need 2 very specific things:
I want to create a table
I want to create a trigger
But I want to create from springframework and maven and I could not find a way to do it.
Since it is a project among several people I want to be as automatic as possible to keep things simple.
I want to start when the server maven can create the table and the trigger if there are not exist.
It will be done?
I would like a simple example or a site I can visit and give me at least the concept of how.
Maven is a tool which builds your application. It's not available when the application runs. Therefore, it's often not the best choice to create database tables, etc.
A better approach is to locate the place where Spring's ApplicationContext is created and add code there that examines the database, finds out which tables already exist and create those which don't.
Later, you can extend the code to migrate data when your data model changes.
To execute SQL, check the Spring JDBC documentation and especially JdbcTemplate.

How to use import an existing Database into a Ruby on Rails 2.3.8 project in Netbeans 6.9.1

I am doing a project in which it has been imposed that I must use Netbeans 6.9.1 and Rails 2.3.8. The operating system must be Windows and we are not allowed to use the command line. We are required to use a MySQL Database (already created and fully functional) and we must import the tables from the database into models, view, and controllers in the Rails project. I don't know how we're supposed to do this because the way Rails works implies that you use the application to make the database, but we have to use the database to make the application.
I've put several dozen of hours into looking this up but I've come up empty handed because every tutorial I found for Rails either uses the command line, or uses scaffolding to create tables to put in the database instead of vice versa.
The question is, how can I generate models, views, controllers, etc. from existing database tables using only the tools in Netbeans? I'm new to both Rails and Ruby so coding them all manually would be extremely difficult because all the routes go funny. If anyone has a solution it would be most appreciated.