Missing Dialect methods?

109 views
Skip to first unread message

Jeffrey Becker

unread,
Jul 7, 2014, 7:37:29 PM7/7/14
to nhibernate-...@googlegroups.com
I've been playing around with writing a migration framework akin to EF6 Migrations as a separate library and I've run into a number of places sql flavors aren't adequately reflected in Dialect.  Specifically I'm running into issues around dropping & altering columns where the support and syntax varies widely.  What's the process for me proposing a change, getting tests up to everyone's satisfaction and submitting a pull request? 

Oskar Berggren

unread,
Jul 8, 2014, 2:59:35 AM7/8/14
to nhibernate-...@googlegroups.com

If it involves larger structural changes you should outline them in text first. In any case you need to open at least one issue in JIRA, write the code with tests and submit pull requests. Try to structure the code in multiple logical commits for easier review.

It's also good to consider if it can be done backwards compatible.

/Oskar

Den 8 jul 2014 02:37 skrev "Jeffrey Becker" <jeffrey....@gmail.com>:
I've been playing around with writing a migration framework akin to EF6 Migrations as a separate library and I've run into a number of places sql flavors aren't adequately reflected in Dialect.  Specifically I'm running into issues around dropping & altering columns where the support and syntax varies widely.  What's the process for me proposing a change, getting tests up to everyone's satisfaction and submitting a pull request? 

--

---
You received this message because you are subscribed to the Google Groups "nhibernate-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhibernate-develo...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jeffrey Becker

unread,
Jul 9, 2014, 1:32:34 PM7/9/14
to nhibernate-...@googlegroups.com
Understood.  I'll have a JIRA issue opened "real soon now" with a pull request to follow.  Is one test fixture per property/method I'm adding with tests for every dialect acceptable?

I'm still a little concerned that I'm effectively asking for special hooks into, from my perspective, the bowels of NHibernate in order to support an external library.  
To unsubscribe from this group and stop receiving emails from it, send an email to nhibernate-development+unsub...@googlegroups.com.

Jeffrey Becker

unread,
Jul 9, 2014, 4:43:12 PM7/9/14
to nhibernate-...@googlegroups.com
Issues are :

NH-3633 - Add Support for Dropping Columns on Dialect
NH-3632 - Add Support for AlteringColumns on Dialect
NH-3631 - Add support for BatchTerminator on Dialect 

Amro El-Fakharany

unread,
Jul 9, 2014, 7:36:28 PM7/9/14
to nhibernate-...@googlegroups.com

Did you had a look at Configuration.GenerateSchemaUpdateScript method?

Amro

To unsubscribe from this group and stop receiving emails from it, send an email to nhibernate-develo...@googlegroups.com.

Jeffrey Becker

unread,
Jul 9, 2014, 7:45:33 PM7/9/14
to nhibernate-...@googlegroups.com
Yes, that's specifically where I started looking.  Turns out it doesn't actually support altering or dropping columns just adding them.


--

---
You received this message because you are subscribed to a topic in the Google Groups "nhibernate-development" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nhibernate-development/ACTD62W3eo0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nhibernate-develo...@googlegroups.com.

Jeffrey Becker

unread,
Jul 11, 2014, 10:33:01 AM7/11/14
to nhibernate-...@googlegroups.com
Ok, pull request is submitted.

Darren Kopp

unread,
Jul 11, 2014, 4:46:11 PM7/11/14
to nhibernate-...@googlegroups.com
You need to make this behavior opt-in, otherwise people will upgrade and possibly lose data because something may not be referenced in the model anymore (or perhaps multiple types mapped to same table returning different things). Entity framework is a two-step process and you can customize the migration, which mitigates this issue, but schema migration is not customizable and thus should not have this behavior enabled by default.

On Friday, July 11, 2014 8:33:01 AM UTC-6, Jeffrey Becker wrote:
Ok, pull request is submitted.

Jeffrey Becker

unread,
Jul 11, 2014, 5:21:18 PM7/11/14
to nhibernate-...@googlegroups.com
Yes, I fully agree that any migration behavior needs to be completely opt-in.  To be clear I'm not proposing to rewrite any of the current Sql generation code. I proposed to implement this as a library separate library outside NHibernate proper which implements a workflow with the two-step process and customizable migration.  All I'm asking for here is some decorator methods on Dialect which provide the necessary chunks of sql and flags to make stuff sql-flavor independent.  

For example, when altering column definitions:
Sql Server uses "Alter [Table] Alter [Column]...", Oracle uses"Alter [Table] Modify [Column]", Firebird and SQLite don't support altering columns.  One of the commits in the pull request adds 2 properties to Dialect, SupportsAlterColumn and AlterColumnString

 I'm sure the DDL generation functionality could be rewritten to use the underlying model that a script is a series of operations which is in turn a series of statements, but why bother? It seems to work but there aren't unit tests around it now so I wouldn't feel safe proposing changes. 

The pull request is here:

Darren Kopp

unread,
Jul 11, 2014, 7:35:27 PM7/11/14
to nhibernate-...@googlegroups.com
Oh ok, that's good, I thought you were planning on using this functionality in the SchemaUpdate class. I actually think this functionality would be useful in that class as well, but opt-in, which is what I was referring to.

Jeffrey Becker

unread,
Jul 11, 2014, 8:53:12 PM7/11/14
to nhibernate-...@googlegroups.com
Ultimately I intend to drive my ddl off calculating the difference between two mappings much like EF where as Schema update bases its ddl on database metadata.  I'm sure that both mechanisms could utilize a common set of underlying classes to encapsulate their ddl generation.  However, the existing schema generation code has all of like 3 unit tests against it all of them as a result of someone finding a bug.  I'd be much more comfortable building up a good suite of tests outside Nhibernate before even considering trying that.

Ricardo Peres

unread,
Jul 12, 2014, 11:38:08 AM7/12/14
to nhibernate-...@googlegroups.com
What about starting NHibernate.Migrations?
;-)

RP

Jeffrey Becker

unread,
Jul 12, 2014, 11:57:06 AM7/12/14
to nhibernate-...@googlegroups.com

I'd want to talk the architecture through a lot more before proposing that. If people are interested in a NHibernate branded project and are willing to have some discussion of how it works, sure.

--

Alexander Zaytsev

unread,
Jul 13, 2014, 10:59:36 AM7/13/14
to nhibernate-...@googlegroups.com

I think that you are trying from the wrong end.

IMO nhibernate should only provide info about what is missed, needs to be added, or changed. And other tool should consume this info and generate migrations in DSL for particular migrator (fluent-migrator or other)

Best Regards,
Alexander

12.07.2014 21:57 пользователь "Jeffrey Becker" <jeffrey....@gmail.com> написал:
You received this message because you are subscribed to the Google Groups "nhibernate-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhibernate-develo...@googlegroups.com.

Jeffrey Becker

unread,
Jul 13, 2014, 12:56:58 PM7/13/14
to nhibernate-...@googlegroups.com

To be clear, I think this is exactly what I'm proposing with an NHibernate.Migrations library. To be clear my pull request is in regards to some extra methods on Dialect that are needed to support that.

That said, I would be concerned if the proposed NHibernate.Migrations library produced sql significantly different from the schema generation tools in NHibernate.Tool.hbm2ddl.  More over, there don't seem to be adequate test cases around the existing schema generation. So, my proposal goes like this:

Work up a low level ddl generation framework in NHibernate proper with tests which is able to support both the existing tools and NHibernate.Migrations.  

Rework the existing hbm2ddl tools to utilize this framework.

Create the NHibernate.Migrations framework which exposes a DSL over top of the underlying framework, handles versioning, and other higher level concerns like DB creation.


I dont really have a preference for where the system for calcuating deltas lives so long as its able to support taking the difference between two Configurations as well as working off db metadata.  Basically the existing system never generates drop statements.  Partially because of the degree of automation but also because its generating its deltas off dbmetadata which might contain tables outside NHibernate's knowledge.  By using mappings as a source for this information we can more accurately account for drops.

To unsubscribe from this group and all its topics, send an email to nhibernate-development+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--

---
You received this message because you are subscribed to the Google Groups "nhibernate-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhibernate-development+unsub...@googlegroups.com.

Jan Schubert

unread,
Nov 13, 2014, 6:01:05 AM11/13/14
to nhibernate-...@googlegroups.com
You add support for altering columns, but it is possible to rename a column with ALTER? I saw your migration framework (Alpha) cannot rename a column.

Jeffrey Becker

unread,
Nov 13, 2014, 7:37:51 AM11/13/14
to nhibernate-...@googlegroups.com

I doubt it. Afaik, sql (or at least the mssqlserver dialect) doesn't support renaming columns in the alter syntax.  That an IDdlOperation which generates the correct ddl shouldn't be hard to whip up.

On Nov 13, 2014 7:03 AM, "Jan Schubert" <xp.dev....@gmail.com> wrote:
You add support for altering columns, but it is possible to rename a column with ALTER? I saw your migration framework (Alpha) cannot rename a column.

--

---
You received this message because you are subscribed to a topic in the Google Groups "nhibernate-development" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nhibernate-development/ACTD62W3eo0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nhibernate-develo...@googlegroups.com.

Jeffrey Becker

unread,
Nov 13, 2014, 9:26:45 AM11/13/14
to nhibernate-...@googlegroups.com
er.  Do you mean having a method off the fluent builder something like:

surface.Alter.Table("Test").RenameColumn("Example", "BetterExample");


On Thursday, November 13, 2014 7:37:51 AM UTC-5, Jeffrey Becker wrote:

I doubt it. Afaik, sql (or at least the mssqlserver dialect) doesn't support renaming columns in the alter syntax.  That an IDdlOperation which generates the correct ddl shouldn't be hard to whip up.

On Nov 13, 2014 7:03 AM, "Jan Schubert"  wrote:
You add support for altering columns, but it is possible to rename a column with ALTER? I saw your migration framework (Alpha) cannot rename a column.

--

---
You received this message because you are subscribed to a topic in the Google Groups "nhibernate-development" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nhibernate-development/ACTD62W3eo0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nhibernate-development+unsub...@googlegroups.com.

Jan Schubert

unread,
Nov 13, 2014, 1:41:21 PM11/13/14
to nhibernate-...@googlegroups.com
Yes, that I mean. It is possible to rename a column with sp_rename on mssql.

EXEC sp_rename 'Test.Example', 'BetterExample', 'COLUMN';

Jeffrey Becker

unread,
Nov 13, 2014, 1:56:11 PM11/13/14
to nhibernate-...@googlegroups.com
I'm going to build in support in my repo shortly.  If you could check the other dialects for column renaming support and let me know, that'd be awesome.  

In the mean-time you can always:

    Run(new SqlDdlOperation("EXEC sp_rename 'Test.Example', 'BetterExample', 'COLUMN';"));

or implement a RenameColumnOperation and Run that.

Jan Schubert

unread,
Nov 13, 2014, 2:44:51 PM11/13/14
to nhibernate-...@googlegroups.com
Not all dialects support rename columns.

No support found for Firebird and SQLite.

MySQL needs the data type to change the column name:
ALTER TABLE "tablename" Change "oldcolumnname" "newcolumnname" ["Data Type"]

Other dialects:
Oracle = alter table tablename rename column oldcolumnname to newcolumnname
DB2 = ALTER TABLE tablename RENAME COLUMN oldcolumnname TO newcolumnname
Ingres = ALTER TABLE tablename RENAME COLUMN oldcolumnname TO newcolumnname
PostgreSQL = ALTER TABLE tablename RENAME COLUMN oldcolumnname TO newcolumnname
Sybase = sp_rename 'tablename.oldcolumnname', 'newcolumnname'

Amro El-Fakharany

unread,
Nov 13, 2014, 3:02:08 PM11/13/14
to nhibernate-...@googlegroups.com

Firebird:
Alter <table_name> Alter column <old_column_Name> to <New_column_Name>

--

---
You received this message because you are subscribed to the Google Groups "nhibernate-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhibernate-develo...@googlegroups.com.

Alexander Zaytsev

unread,
Nov 13, 2014, 3:44:12 PM11/13/14
to nhibernate-...@googlegroups.com
I've implemented rename for MySQL in FluentMigrator https://github.com/schambers/fluentmigrator/pull/166/ 

Best Regards, 
Alexander

--

---
You received this message because you are subscribed to the Google Groups "nhibernate-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhibernate-develo...@googlegroups.com.

Jeffrey Becker

unread,
Nov 13, 2014, 4:58:10 PM11/13/14
to nhibernate-...@googlegroups.com
All updated, have-at.
To unsubscribe from this group and stop receiving emails from it, send an email to nhibernate-development+unsub...@googlegroups.com.

Jan Schubert

unread,
Nov 14, 2014, 2:48:10 AM11/14/14
to nhibernate-...@googlegroups.com
Fantastic! I will try it today.

Thank you for your great support!

José Henrique (Zote)

unread,
Nov 14, 2014, 7:36:31 AM11/14/14
to nhibernate-...@googlegroups.com
SQLAnywhere supports!

ALTER TABLE "tablename" RENAME "oldcolumnname" TO "bewcolumnname";


--
José Henrique (Zote)
Analista de TI
Bludata Software

--

---
You received this message because you are subscribed to the Google Groups "nhibernate-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhibernate-develo...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages