in

The ORM Foundation

Get the facts!

Generated constraint names

Last post 04-22-2014 0:41 by maubrey. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 03-08-2014 11:48

    Generated constraint names

    I have NORMA configured to use snake_case naming for generated DDL. So I get names like table_name and variable_name. Perfect.

    But for the generated constraint and domain names, it seems to still be using some CamelCase:

    CREATE DOMAIN myapp.Vote AS SMALLINT CONSTRAINT ValueTypeValueConstraint1 CHECK (VALUE IN (-1, 1));
    CREATE DOMAIN myapp.DisplayPosition AS SMALLINT CONSTRAINT DisplayPosition_Unsi gned_Chk CHECK (VALUE >= 0);
    CREATE DOMAIN myapp.WordPosition AS SMALLINT CONSTRAINT WordPosition_Unsigned_C hk CHECK (VALUE >= 0);
    CREATE DOMAIN myapp.pxValue AS INTEGER CONSTRAINT pxValue_Unsigned_Chk CHECK (V ALUE >= 0);

    IOW, I'd prefer myapp.vote, value_type_value_constraint1, etc.

    Is there a way to control that? I'm targeting PostgreSQL.

  • 03-29-2014 11:56 In reply to

    Re: Generated constraint names

     As a follow-up to this, is there a way to have NORMA specify column default values?

     For example, rather than this:

       created_at TIMESTAMP NOT NULL

     I need:

      created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP

     

     

     

  • 03-31-2014 11:38 In reply to

    Re: Generated constraint names

    Hi Maurice,

    NORMA current maps the table and column names, but not all of the constraints names. The issue that we basically have three kinds of elements:

    1. Items that are represented in the in-memory version of the relational model. These should use the naming conventions if they are specified.
    2. Items that are named in the ORM model but not directly modelled in-memory version of the relational model. Currently, only tables, columns, uniqueness constraints, and foreign key constraints are modeled in memory (note your ValueConstraint is not in this list). However, the decorators (FK and PK) look to be fixed case.
    3. Constraints mapped as the generator level. Some of these will just use the name shown in NORMA, others use additional components. For example, the value constraint you show here.

    The only way to tweak these now is to actually name the constraints, all of which should be selectable in the tool. These will just be copied to the model.

    The fix is to duplicate some of the name generation code and apply the name generator settings in the XSLT generator algorithm.

    -Matt

  • 03-31-2014 11:55 In reply to

    Re: Generated constraint names

    Hi Maurice,

    There is no way to specify this in NORMA right now. This has to be done somewhat carefully as one value type can map to multiple columns, so (like value constraints) a distinction between a 'default value' on the role vs. one on the value type vs one on the data type would need to be made.

    At the XSL level, we currently go from ORM+CDB (ORM with the 'Map to Relational Model' turned on) to DCIL (relational schema definition) to DDIL (DDL language definition). There is currently no notion of DEFAULT at the ORM+CDB or DCIL, but there is a 'defaultClause' at the DDIL level which should format correctly to your DB output if you can sneak it into the DDIL the file.

    There is a built in mechanism with the generators called a 'Format Modifier' that I've referenced a few times on this site. Basically, you register a separate generator file that can modify each of the generated files before moving onto the next step. I've shown this used for using custom properties to specify multiple SQL Server schema names and to add audit columns to any DB (for example, see http://www.ormfoundation.org/forums/p/573/1706.aspx#1706). Both of these modifiers apply to the DCIL, meaning that the DCIL that is transformed to DDIL is not the one generated directly from the ORM file. It will likely be a while before this is designed in formally, but it would be fairly easy to write a format modifier to take a default value (based on a Custom Property from a role or value type) and modify the DDIL.

    In your case, you want a system-named function (CURRENT_TIMESTAMP) instead of an actual default. I have a bit of a concern with rendering this instead of a constant value, but the system will probably just leave it untouched.

    I'm curious as to the level of interest in this. The format modifier to do this would be fairly straightforward (around a page of XSLT) and could be directly based on the earlier modifiers.

    -Matt

  • 04-22-2014 0:41 In reply to

    Re: Generated constraint names

    Thanks, Matt.

    For the time-being, I just wrote a script to rewrite the generated DDL (adding the default values and changing the casing). But I certainly would be interested in this longer term.

     

     

Page 1 of 1 (5 items)
© 2008-2014 The ORM Foundation: A UK not-for-profit organisation -------------- Terms of Service