Exclude Table from Schema Export

363 views
Skip to first unread message

Will Shaver

unread,
Dec 12, 2008, 5:18:13 PM12/12/08
to nhibernate-...@googlegroups.com
A while back I asked about means to exclude a table from the schema export. As this wasn't possible, I've now added it to my version of the trunk. Before I commit I wanted to run it by people. Currently I have it set up as follows:
 
Tables are included by default. (As before.)
 
Tables mapped as:

<

class name="Products" exportable="false">
 ...

Will not be published in either the 'Drop Table' or the 'Create Table' commands from the schema export tool. This solves Jira issue 1274. I have this working including the modification to the xsd/Hbm.generated.cs files. Is this an acceptable means of excluding certain classes from export? For reference, the reason for doing this could include mapping Views, tables from a different project, tables with existing data to be preserved etc.

Your .02c would be useful.

 -Will

Tuna Toksöz

unread,
Dec 12, 2008, 5:23:42 PM12/12/08
to nhibernate-...@googlegroups.com
Hi,

How does it play in SchemaExport tool, does it now have a list to be excluded/included, or get it right from the Configuration object?

Otherwise, it sounds great to me.
--
Tuna Toksöz
http://tunatoksoz.com

Typos included to enhance the readers attention!

Will Shaver

unread,
Dec 12, 2008, 5:26:49 PM12/12/08
to nhibernate-...@googlegroups.com
It is done in each mapping file, so you don't need to supply a list to SchemaExport. The export code already excludes classes that are not mapped to physical tables, so I simply added a conditional there for IsExportable. Was actually simpler than I thought it would be.

Tuna Toksöz

unread,
Dec 12, 2008, 6:13:46 PM12/12/08
to nhibernate-...@googlegroups.com
Ok, I thought about another possibility, thing on SchemaExport. _Maybe_ it is useful to have it explicitly on SchemaExport, but _maybe_. I don't have any idea here :)

Will Shaver

unread,
Dec 12, 2008, 6:25:39 PM12/12/08
to nhibernate-...@googlegroups.com
Sorry, I don't follow what you're trying to say here.

Fabio Maulo

unread,
Dec 13, 2008, 6:26:36 AM12/13/08
to nhibernate-...@googlegroups.com
I Will.
We have various tools involving the schema:
- Export
- Drop
- Update
- Verify

What about something like the follow:
<classe name="Something" schema-action="export, drop, update, verify">
The schema-action attribute can work like the "cascade" attribute as a multiple choice.
All possible values of schema-action will be: none, all, export, drop, update, verify
Default value is : all

Thought ?

2008/12/12 Will Shaver <will....@gmail.com>



--
Fabio Maulo

Stephen Bohlen

unread,
Dec 13, 2008, 7:09:50 AM12/13/08
to nhibernate-...@googlegroups.com
I am inclined to agree with this suggestionl; I had the same thought when reading this thread: what about the rest of the other schema-related ops?  It would be great if we had a more extensible approach to this (as you are proposing here) that would also allow for easily adding support for any MORE schema-related ops that might be introduced in the future too.
 
BTW, I think it would be great to get something like this into NH -- the awkwardness of handling mapped view during schema-gen has been a nuisance I have battled with on several projects (and we have dealt with it by using custom sql in the create/drop sections of the mappings but this always felt like a hack).  This approach (Will's combined with Fabio's suggestion) seems much more elegant.
 
-Steve B.

Fabio Maulo

unread,
Dec 13, 2008, 7:26:40 AM12/13/08
to nhibernate-...@googlegroups.com
Related to this issue we have probably something else...
Do someone can check if catalog+schema is well supported in each schema-action ?

Thanks.

2008/12/13 Stephen Bohlen <sbo...@gmail.com>



--
Fabio Maulo

Will Shaver

unread,
Dec 15, 2008, 4:04:02 PM12/15/08
to nhibernate-...@googlegroups.com
Ok, am doing the work to switch this over now based on your feedback.

Update, export and drop are easy to implement and I think I have those
done and working. I'm writing test cases to make sure.

What do you mean by 'verify'? Do you mean Configuration.cs Like 1985
-> ValidateSchema?

Tuna Toksöz

unread,
Dec 15, 2008, 4:07:20 PM12/15/08
to nhibernate-...@googlegroups.com
Verify is a newly added tool. SchemaValidator is the name, in Tools namespace.
And yes ValidateSchema is what is used in that.

Will Shaver

unread,
Dec 15, 2008, 4:21:59 PM12/15/08
to nhibernate-...@googlegroups.com
Because the tool and the method are called 'validate' instead of
'verify' I am going to go with 'validate' as the xml keyword.

Tuna Toksöz

unread,
Dec 15, 2008, 4:24:35 PM12/15/08
to nhibernate-...@googlegroups.com
You're right.

            if ("validate" == autoSchemaExport)
            {
                settings.IsAutoValidateSchema = true;
            }

so validate would be consistent with the configuration.




On Mon, Dec 15, 2008 at 11:21 PM, Will Shaver <will....@gmail.com> wrote:

Because the tool and the method are called 'validate' instead of
'verify' I am going to go with 'validate' as the xml keyword.



Fabio Maulo

unread,
Dec 15, 2008, 4:57:20 PM12/15/08
to nhibernate-...@googlegroups.com
I'm sorry... my fault.
"validate" is the right value for the new attribute.

2008/12/15 Will Shaver <will....@gmail.com>



--
Fabio Maulo
Reply all
Reply to author
Forward
0 new messages