Re: updating using Migrations with allowNull
Re: updating using Migrations with allowNull
- Subject: Re: updating using Migrations with allowNull
- From: David Avendasora <email@hidden>
- Date: Fri, 21 Mar 2014 08:45:00 -0400
Hi Ted,
You could create the column with allows null = false and a default value of false using:
ERXMigrationTable securityTable = database.existingTableNamed("security");
securityTable.newIntBooleanColumn("canseeprojects", false, false);
Which will set the value for all existing rows to false, and then in the next migration call:
ERXMigrationTable securityTable = database.existingTableNamed("security");
ERXMigrationColumn canSeeProjects = securityTable.existingColumnNamed(“canseeprojects”);
canSeeProjects.setDefault(null);
That way you aren’t writing any actual SQL.
Dave
On Mar 21, 2014, at 8:24 AM, Theodore Petrosky <email@hidden> wrote:
> I have a running D2W app and I need to add some booleans to my User.security Entity.
>
> Normally I accomplish this by:
>
> adding the boolean to my postgresql db with migrations:
>
> ERXMigrationTable securityTable = database.existingTableNamed("security");
> securityTable.newFlagBooleanColumn("canseeprojects", true);
>
> (I am setting allowsNull to true even thought I want it to be false. )
>
> then I update the security's new attribute to false for current security entries, and change the table to not allowsNull:
>
> /*
> * Fix the canseeprojects boolean
> */
> ERXJDBCUtilities.executeUpdate(database.adaptorChannel(), "UPDATE security SET canseeprojects = false");
>
> securityTable.existingColumnNamed("canseeprojects").setAllowsNull(false);
>
>
> Is there an easier way, or is this just an artifact to live with?
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
—————————————————————————————
WebObjects - so easy that even Dave Avendasora can do it!™
—————————————————————————————
David Avendasora
Senior Software Abuser
Nekesto, Inc.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden