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.
Related
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)
I created some tables using rails. Now I want to modify the structure of a few of them. I know it can be done using rails migration. But i was wondering if it would cause any anomaly in the rails app if I modify the schemas using mysql rdbms?
Doing such changes through a migration has the advantage of not losing the changes if you decide to recreate/remigrate the database.
Also it serves as documentation. Imagine if your coworker altered some tables sneakily (and then you both forgot about it).
Technically, updating schemas directly in the database should work, but don't do it.
To add to Sergio's point, you're missing a simple fact - Rails' migrations create the famous db/schema.rb file - from which your migrations pull all their data.
The importance of schema.rb is overlooked - it is one of the most crucial aspects of your application.
db/schema.rb
The schema gives all your migrations a version of your DB to change / add to. Each time you perform a migration, Rails changes the schema file to ensure it has a "blueprint" of your db stored on file.
The schema is then able to rebuild the database using such methods as rake db:schema:load (ONLY RECOMMENDED FOR NEW INSTALLS -- DELETES PREVIOUS DATA)
So whilst there's no problem setting up the db using the db's own native tools, I recommend against it. You need to keep your migrations up to speed so that Rails can build the appropriate tables from its schema.
I tried using https://github.com/building5/sails-db-migrate module for creating migrations but it did not run correctly. Table used to get generated but few columns were missing.
Is there a better way to create and run migrations? Sorry i am new to sails, recently migrated from Php.
So, it turn out i was stupid to think we need a module to write migration in sails. It turn out on sails lift the application automatically creates the table from attributes of the model.
But on trying that i realized the waterline module which takes care of this does not create for foreign-key constraints as of now.They are still working on it.
If you are using a nosql db then you can use the associations
http://sailsjs.org/#!/documentation/concepts/ORM
Time is pass, but nothing changes with sails. Beware use it.
If you already in this trap - try https://www.npmjs.com/package/sails-migrations
So people will get a clean and correct answer: The sails ORM (waterline) already supports auto migration, you can change this in the config file (/config/models.js):
module.exports.models = {
migrate: 'alter'
};
It accepts the following options:
safe - never auto-migrate my database(s). I will do it myself (by hand)
alter - auto-migrate, but attempt to keep my existing data (experimental)
drop - wipe/drop ALL my data and rebuild models every time I lift Sails
http://sailsjs.org/#!/documentation/concepts/ORM/model-settings.html
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)
how to see my liferay table in mysql database?
i have created portal-ext.properties in liferay home.but i cant see my liferey table mySql..
table is created in docroot/web-inf/sql in eclipse IDE...
help me where i m wrong and which thing missing?
#
# MySQL
#
include-and-override=portal-ext.properties
include-and-override=${liferay.home}/portal-ext.properties
jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost/kportal?useUnicode=true&characterEn
coding=UTF-8&useFastDateParsing=false
jdbc.default.username=root
jdbc.default.password=ubuntu123
schema.run.enabled=true
schema.run.minimal=true
Tables created through service-builder will only be created once you deploy your plugin to the actual server (and run the server), not on build time. Also, your plugin needs to deploy correctly - if initialization fails (e.g. due to missing pieces or dependencies that are not met), the tables will not be created.
Also, the tables by default will be named with the namespace you gave as a prefix. So if you declare a namespace X (in service.xml) and an entity named Y, the table to look for will be named X_Y.
Also, remember you'll have to run ant build-services after you edited your service.xml. Then deploy it and wait for a log message similar "...your plugin... is available for use" to be sure it deployed correctly. (Edit: This is no longer printed for portlets, only for the other plugin types, so you might not see it when you deployed your plugin)
If this doesn't help, please give more information. Currently you don't give any details about what you've actually tried. You'll find more steps and details on the development guide.
Also, make sure
that the account you use for the database has CREATE TABLE permissions (you use root in your configuration above - that should do the trick)
that you're checking the correct database in case you have multiple
that Liferay actually picks up your configuration file. The startup log will tell you which portal-ext.properties files are read, as well as which database it will use. In case you can't find the name/location of your portal-ext.properties file, make sure that you indeed have a file with this name. A common problem on windows is that people create portal-ext.properties.txt (and Windows hides the .txt part of the name)