Liquibase create schema for MySQL - mysql

Is there any way to create schema through liquibase script ?
After some research I've found out that we need to include a create schema in change log file.
I'm thinking on similar terms for question asked previously for postgres
Any pointers or help is welcomed.

Found an answer that was mentioned already on stackoverflow.
We can create a fresh database using this URL.
jdbc:mysql://localhost:3306/database_name?createDatabaseIfNotExist=true
createDatabaseIfNotExist this keyword create a fresh new database in your system. If the database does not exist. if exist, skip executing.

Your proposed solution to your own question is to separate stuff by database, while your original question was about how to separate stuff using schema. Those are not the same.
If you are using Liquibase in "embedded mode", meaning it is your application code which controls Liquibase execution, not some Maven cmd or Liquibase CLI, then you can have a look at Pre-Liquibase.
Pre-Liquibase attempts to solve the chicken-and-egg problem inherent to Liquibase: It cannot be used to setup its own "home" (Liquibase needs two tables of its own that has to live somewhere), nor can Liquibase ChangeSets be used to create databases or schemas.
This is the problem which Pre-Liquibase solves. It executes some SQL prior to Liquibase itself. For example, you can use it with MySQL to make sure the database exists without fiddling with URL. In such case your Pre-Liquibase SQL script file would look like this:
CREATE DATABASE IF NOT EXISTS my_database_name
You can use Pre-Liquibase if you are using Spring Boot or just Spring Framework without Spring Boot. However, feel free to steal the ideas if you have another tech stack.
(full disclosure: I'm the author of Pre-Libuibase)

Related

Do I need to create DB migration, if I have a designed DB in MySQL?

I designed a database in MYSQL. Now I want to connect that with my Laravel application. But after researching, I understand that I need to migrate the database into Laravel by creating migration tables. But doing the same thing that I did in MySQL is tedious. I think there is another way to do the stuff. After searching I got this article from stackoverflow, but this is related to yii framework. I think someone knows here the solution of my problem.
I don't see a problem here, you can just connect Laravel to your DB (by editing your .env file) without any problems, migration files are just an easier way to design and implement your tables (also altering your tables' scheme on production is a very useful usage for migrations), but with that being done then no further actions are required, and you are good to go!
it's pretty obvious, you can update the database setting in the .env file and use DB::table('your_table_name') and get whatever query you want.
The upside of using migrations is that the exact same database can be created on different systems (ex: co-workers or acceptance/production servers).
Laravel migrations have an up and a down function so you can rollback to a specific version if something went wrong, very usefull when publishing your code.
That being said, co-workers could also review the database changes and for example hint at using more indexes and foreign keys.
As the other comments said, it's not a requirement you use migrations but it has considerable advantages versus creating and updating the database manually.

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.

Slick Database Migrations

I'm working on a project using Scala which uses Slick.io for handling database interactions. I have the database schema implemented via Slick using its DDL.
This all works fine when I was starting out but now that I am some way into the project, making changes to the database schema is becoming a pain. I have to drop all the tables, manage data, re-create the schema etc...
I've previously used the PHP framework Laravel which had a nice way of dealing with database migrations & making changes to databases. This was done via a set of classes that were controlled by a timestamp and the "most recent" migrations could be run to make any changes to a database schema.
Does Slick have any equivalent?
Thanks
No, slick itself does not have an equivalent, but you can use something like:
Flyway:
https://github.com/flyway/flyway
http://flywaydb.org/
As you have not given any additional info:
for the play-framework there is an own module, which can be found here: https://github.com/flyway/flyway-play

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.

Trying to create MySql DB with Nhibernate - need some direction

So I am very new to web development and working on a new project that will make use of Nhibernate as my ORM and MySql database.
I wanted to set it up so that NHibernate would create my database table based on the (all necessary NHibernate files). So far I have concluded that NHibernate will generate the DB schema that I have laid out with the mappings and class files.
The problem I am seeing is that it appears that you must have the database in place in MySql first for NHibernate to create the table (understood). However, when reviewing creating a MySql database in the manual it is requiring you to specify the schema with the create command.
So far the number of blogs I have read concentrate on what you need for NHibernate and not much details in correctly prepping your MySql server.
Any direction or advise is greatly appreciated.
You need to run the "create database [databasename];" command before building up your schema. You don't neeed to specify a schema to use this command.