che icon indicating copy to clipboard operation
che copied to clipboard

Study Initial schema generation and how to make changes in model after migration to single database

Open skabashnyuk opened this issue 10 years ago • 1 comments

Time to time we are doing some small changes in our model. Sometimes we just adding new fields But sometimes https://github.com/eclipse/che/issues/1820 we change completely structure of some object.
We need to figure out how :

  1. Change structure of database from previus version or much earlier version
  2. What to do with existing data during migration.

skabashnyuk avatar Aug 12 '16 11:08 skabashnyuk

After a discussion and some study and investigation process it was decided to define an explicit database schema based on a current version generated by EclipseLink. This approach allows us to create native migration scripts, avoid useless mappings for those entries which need foreign keys, use all the power of abilities of SQL standard. Consider the following scripts hierarchy:

   resources/
     /sql
        /5.0.0
          1.init.sql
        /5.0.0-M1
          1.rename_fields.sql
          2.add_workspace_constraint.sql
          /postgresql
            2.add_workspace_constraint.sql
        /5.0.1
          1.stacks_migration.sql

From the example

  • There is a directory called sql which contains initialization/migration scripts
  • There are version directories under the sql like 5.0.0 or 5.0.0-M1 these directories contain scripts for specific versions
  • There are sql scripts under project version duiretories line 1.init.sql or 1.rename_fields.sql the naming of scripts is pretty simple: the first is a script version in a project versions it's 1 in 1.init.sql then description of changes(if necessary) init in 1.init.sql and then the file extension .sql in 1.init.sql
  • There is a directory under 5.0.0-M1 called postresql if current database provider is posgresql then the script from 5.0.0-M1/posgresql/2.add_workspace_constraint.sql will be used instead of 5.0.0-M1/2.add_workspace_constraint.sql, so basically if the same script name is provided in provider-specific directory then this script will be used instead

in this way we can easily create initialization scripts, extend an existing schema and manage overrides for different database. It also allows us to develop one version migrations in separate task simultaneously by versioning scripts under current project version.

voievodin avatar Oct 12 '16 13:10 voievodin