I am developing a JSP webapp using Spring MVC and Hibernate.
I am thinking of updating database schema within JSP
So plan so far;
- Keep database schema in a file
- Read schema into a Hash
- Check DB against Hash
* add new tables
* drop removed tables ( either tables not existing in Hash or drop them manually)
- Keep a list of all changes
* drop or add columns
* update columns
My question is, what is the best way to approach and what tools to use?
Thanks
Related
when generating a database in PowerDesigner I have the option to drop all Tables/Tablespaces and so on before generating the Database: Option to Select
But this Option isnt there when applying changes to a database. I need this, because some local databases could already have some of the Changes I made to the model and I cant drop all tables because of the data.
I'm not sure I understand the question, when you are ready to drop some tables instead of modifying them, but you don't want to drop all tables.
It seems to me that you could use Database > Apply Model Changes to Database with the Connect to a Data Source to compare the model with an existing database, and just generate the necessary modification scripts.
Maybe you could use a saved Selection to generate an Alter Script for most tables, and another to generate a Drop+Create script for some "transient" tables.
I have few tables in production environment with data in it. I want to add new tables retaining the existing tables with data in it.
I tried using flyway but for that initial schema (schema with which existing production tables and data were created) also need to be set and drop the existing tables. However, in my use case I do not want my existing tables to be deleted.
My application created database tables using JPA. I want to delete these tables programmatically using JPA and/or EclipseLink API (without using DROP TABLE command).
What is the right way to delete database tables created by JPA framework?
If you are able to use JPA 2.1, you can specify that the provider write or read scripts to drop tables, allowing you to control what gets executed. Unfortunately though, it doesn't give you fine grain control unless you can dynamically write your own drop table scripts.
Without using provider specific code, the only other way to drop a particular table is native SQL.
Within EclipseLink you would get the session from the EntityManager and create a new SchemaManager(session). With it you can call dropDefaultTables() to drop all tables in the persistence unit, or use dropObject(DatabaseObjectDefinition) to drop single DatabaseObjectDefinition objects which are used to represent tables, stored procs etc. You can use getDefaultTableCreator(boolean generateFKConstraints) to get the default table creator for the PU. With it you can use getTableDefinitions() to get all DatabaseObjectDefinition objects representing the tables in the PU, so you can select one to drop.
http://wiki.eclipse.org/EclipseLink/FAQ/JPA#How_to_access_table.2C_column_and_schema_information_at_runtime.3F
shows how to unwrap the EM to get the session.
Here's what worked for me (EclipseLink JPA 2.1):
EntityManagerFactory emf = Persistence.createEntityManagerFactory("you persistence unit");
EntityManager em = emf.createEntityManager();
SchemaManager sm = new SchemaManager(em.unwrap(DatabaseSession.class));
sm.dropTable("table name");
I am using Yii to create a web application that allows me to view, retrieve, add, and delete information from tables in a MySQL database I have already created.
Is there a way to implement this web app so that I can add or delete tables from the database using the webapp instead of having to login to phpmyadmin?
For example, My database might have 2 tables: "Employee" and "Department". How can I customize my Yii webapp so that I can add a third table "Location" on the fly, using the webapp?
Use the CDBCommand class. It has many database management methods, including dropTable and createTable
In Yii there are having CDbCommand class. With the help of this user can customize database easily. You can create, delete and update table easily with the help of this.
With the help of dropTable() method you can easily delete the table from database.
Its help you
All,
Is there some setting that I can tell hbm2ddl to run a view creation statement instead of create a table when generating the database schema?
I'm creating my database schema using the wonderful hbm2ddl tool, but I have one issue. I need to flatten some of the tables into views to aid searching the database, and hql would be overly complex a solution. I've created Entity objects pointed at these views, in order to fetch search results via hibernate. This all works fine, until hbm2ddl is used. In an empty database schema, hbm2ddl will create the database schema based on the jpa annotations, unfortunately, it will also create my views as tables. Is there some setting that I can tell hbm2ddl to run a view creation statement instead of create a table? In lieu of that, is there a way to tell hbm2ddl to skip table creation for an entity (exclude, or something)?
Thanks!
To my knowledge, and this is unfortunate, Hibernate doesn't support things like creating views instead of tables nor validating a schema containing views. See issues like HHH-1872, HHH-2018 or HHH-1329.