When using NHibernate, what common methods are used to propagate schema changes?

When using NHibernate ORM, what are the standard or best open source methods for distributing schema changes to users of applications that have an existing version of the software?

If I need to add or remove properties from an existing class, how can I properly handle these changes for users who use a previous version of the software?

I am looking for something that will work on Mono, if possible.

I would prefer not to parse the resulting schema from ORM changes and manually update the version every time I create a new application assembly.

(I assume that I will use NHibernate to create a schema for the database, but if there are different methods that fix this problem, then I'm open to answering).

+3
source share
1 answer

As you use version control for source code, you should use version control for the database schema, especially if you plan to provide update functionality for your application. There are some tools that will help you, but I prefer to do things manually using an XML file with SQL commands to update or revise the schema, for example:

 <Revision Id="3">
    <Up>
      <SqlCommand>CREATE TABLE [Category] ( [Id] BigInt Primary Key,    [Name] nvarchar(255) )</SqlCommand>
      <SqlCommand>ALTER TABLE [Group] ADD   CanRead bigint NULL</SqlCommand>
      <SqlCommand>UPDATE [SysValue] SET [Value] = '3' WHERE [Name] = 'Revision'</SqlCommand>
    </Up>
    <Down>
        <SqlCommand>DELETE TABLE [Category]</SqlCommand>
        <SqlCommand>ALTER TABLE [Group] DROP COLUMN [CanRead]</SqlCommand>
        <SqlCommand>UPDATE [SysValue] SET [Value] = '2' WHERE [Name] = 'Revision'</SqlCommand>
    </Down>
  </Revision>

, SQL-, , temp, , ..

+1

Source: https://habr.com/ru/post/1772645/


All Articles