Skip to content

Commit

Permalink
Add column modifiers — comment, default, nullable, unsigned
Browse files Browse the repository at this point in the history
  • Loading branch information
elpete committed Sep 22, 2017
1 parent f35e1f1 commit 25fbade
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
8 changes: 7 additions & 1 deletion models/Grammars/Grammar.cfc
Expand Up @@ -745,7 +745,8 @@ component displayname="Grammar" accessors="true" {
modifyUnsigned( column ),
generateNullConstraint( column ),
generateAutoIncrement( column ),
generateDefault( column )
generateDefault( column ),
generateComment( column )
], function( item ) {
return item != "";
} ), " " );
Expand All @@ -771,6 +772,11 @@ component displayname="Grammar" accessors="true" {
return column.getDefault() != "" ? "DEFAULT #column.getDefault()#" : "";
}

function generateComment( column ) {
return column.getComment() != "" ? "COMMENT ""#column.getComment()#""" : "";

}

/*====================================
= Column Types =
====================================*/
Expand Down
17 changes: 17 additions & 0 deletions models/Schema/Column.cfc
Expand Up @@ -10,6 +10,7 @@ component accessors="true" {
property name="unsigned" default="false";
property name="autoIncrement" default="false";
property name="default" default="";
property name="comment" default="";
property name="values";

function init( blueprint ) {
Expand All @@ -18,10 +19,26 @@ component accessors="true" {
return this;
}

function comment( comment ) {
return setComment( comment );
}

function default( value ) {
return setDefault( value );
}

function nullable() {
return setNullable( true );
}

function references( column ) {
arguments.type = "foreign";
arguments.foreignKey = getName();
return getBlueprint().addIndex( argumentCollection = arguments );
}

function unsigned() {
return setUnsigned( true );
}

}
16 changes: 12 additions & 4 deletions tests/specs/Schema/SchemaBuilder+GrammarSpec.cfc
Expand Up @@ -396,12 +396,20 @@ component extends="testbox.system.BaseSpec" {
} );

describe( "column modifiers", function() {
xit( "comment", function() {
fail( "test not implemented yet" );
it( "comment", function() {
var schema = getBuilder();
var blueprint = schema.create( "users", function( table ) {
table.boolean( "active" ).comment( "This is a comment" );
}, false );
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""users"" (""active"" TINYINT(1) NOT NULL COMMENT ""This is a comment"")" );
} );

xit( "default", function() {
fail( "test not implemented yet" );
it( "default", function() {
var schema = getBuilder();
var blueprint = schema.create( "users", function( table ) {
table.boolean( "active" ).default( 1 );
}, false );
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""users"" (""active"" TINYINT(1) NOT NULL DEFAULT 1)" );
} );

it( "nullable", function() {
Expand Down

0 comments on commit 25fbade

Please sign in to comment.