Skip to content

Commit

Permalink
Add big, medium, small, and tiny integer and increments variants.
Browse files Browse the repository at this point in the history
  • Loading branch information
elpete committed Sep 22, 2017
1 parent 35b7d83 commit 2bb379d
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 33 deletions.
10 changes: 9 additions & 1 deletion models/Grammars/Grammar.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -826,10 +826,18 @@ component displayname="Grammar" accessors="true" {
return "TEXT";
}

function typeMediumInteger( column ) {
return "INTEGER(#column.getPrecision()#)";
}

function typeMediumText( column ) {
return "TEXT";
}

function typeSmallInteger( column ) {
return "INTEGER(#column.getPrecision()#)";
}

function typeString( column ) {
return "VARCHAR(#column.getLength()#)";
}
Expand All @@ -847,7 +855,7 @@ component displayname="Grammar" accessors="true" {
}

function typeTinyInteger( column ) {
return "TINYINT" & (column.getLength() != "" ? "(#column.getLength()#)" : "");
return "INTEGER(#column.getPrecision()#)";
}

/*===================================
Expand Down
67 changes: 52 additions & 15 deletions models/Schema/Blueprint.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ component accessors="true" {
function increments( name ) {
arguments.autoIncrement = true;
addIndex( type = "primary", column = name );
return unsignedInt( argumentCollection = arguments );
return unsignedInteger( argumentCollection = arguments );
}

function integer( name, precision = 10 ) {
Expand All @@ -128,29 +128,30 @@ component accessors="true" {
return addColumn( argumentCollection = arguments );
}

function mediumText( name ) {
arguments.type = "mediumText";
return addColumn( argumentCollection = arguments );
function mediumIncrements( name ) {
arguments.autoIncrement = true;
addIndex( type = "primary", column = name );
return unsignedMediumInteger( argumentCollection = arguments );
}

function tinyInteger( name, length = "" ) {
arguments.type = "tinyInteger";
function mediumInteger( name, precision = 10 ) {
arguments.type = "mediumInteger";
return addColumn( argumentCollection = arguments );
}

function unsignedBigInteger( name ) {
arguments.unsigned = true;
return bigInteger( argumentCollection = arguments );
function mediumText( name ) {
arguments.type = "mediumText";
return addColumn( argumentCollection = arguments );
}

function unsignedInteger( name ) {
arguments.unsigned = true;
return integer( argumentCollection = arguments );
function smallIncrements( name ) {
arguments.autoIncrement = true;
addIndex( type = "primary", column = name );
return unsignedSmallInteger( argumentCollection = arguments );
}

function unsignedInt( name ) {
arguments.type = "integer";
arguments.unsigned = true;
function smallInteger( name, precision = 10 ) {
arguments.type = "smallInteger";
return addColumn( argumentCollection = arguments );
}

Expand All @@ -177,4 +178,40 @@ component accessors="true" {
return addColumn( argumentCollection = arguments );
}

function tinyIncrements( name ) {
arguments.autoIncrement = true;
addIndex( type = "primary", column = name );
return unsignedTinyInteger( argumentCollection = arguments );
}

function tinyInteger( name, precision = 10 ) {
arguments.type = "tinyInteger";
return addColumn( argumentCollection = arguments );
}

function unsignedBigInteger( name ) {
arguments.unsigned = true;
return bigInteger( argumentCollection = arguments );
}

function unsignedInteger( name ) {
arguments.unsigned = true;
return integer( argumentCollection = arguments );
}

function unsignedMediumInteger( name ) {
arguments.unsigned = true;
return mediumInteger( argumentCollection = arguments );
}

function unsignedSmallInteger( name ) {
arguments.unsigned = true;
return smallInteger( argumentCollection = arguments );
}

function unsignedTinyInteger( name ) {
arguments.unsigned = true;
return tinyInteger( argumentCollection = arguments );
}

}
70 changes: 53 additions & 17 deletions tests/specs/Schema/SchemaBuilder+GrammarSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ component extends="testbox.system.BaseSpec" {
table.string( "first_name" );
table.string( "last_name" );
table.string( "password", 100 );
table.unsignedInt( "country_id" ).references( "id" ).setTable( "countries" ).setOnDelete( "cascade" );
table.unsignedInteger( "country_id" ).references( "id" ).setTable( "countries" ).setOnDelete( "cascade" );
table.timestamp( "created_date" ).setDefault( "CURRENT_TIMESTAMP" );
table.timestamp( "modified_date" ).setDefault( "CURRENT_TIMESTAMP" );
}, false );
Expand Down Expand Up @@ -226,12 +226,20 @@ component extends="testbox.system.BaseSpec" {
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""posts"" (""body"" TEXT NOT NULL)" );
} );

xit( "mediumIncrements", function() {
fail( "test not implemented yet" );
it( "mediumIncrements", function() {
var schema = getBuilder();
var blueprint = schema.create( "users", function( table ) {
table.mediumIncrements( "id" );
}, false );
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""users"" (""id"" INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT, PRIMARY KEY (""id""))" );
} );

xit( "mediumInteger", function() {
fail( "test not implemented yet" );
it( "mediumInteger", function() {
var schema = getBuilder();
var blueprint = schema.create( "users", function( table ) {
table.integer( "age" );
}, false );
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""users"" (""age"" INTEGER(10) NOT NULL)" );
} );

it( "mediumText", function() {
Expand All @@ -254,12 +262,20 @@ component extends="testbox.system.BaseSpec" {
fail( "test not implemented yet" );
} );

xit( "smallIncrements", function() {
fail( "test not implemented yet" );
it( "smallIncrements", function() {
var schema = getBuilder();
var blueprint = schema.create( "users", function( table ) {
table.smallIncrements( "id" );
}, false );
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""users"" (""id"" INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT, PRIMARY KEY (""id""))" );
} );

xit( "smallInteger", function() {
fail( "test not implemented yet" );
it( "smallInteger", function() {
var schema = getBuilder();
var blueprint = schema.create( "users", function( table ) {
table.smallInteger( "age" );
}, false );
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""users"" (""age"" INTEGER(10) NOT NULL)" );
} );

it( "string", function() {
Expand Down Expand Up @@ -294,20 +310,28 @@ component extends="testbox.system.BaseSpec" {
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""recurring_tasks"" (""fire_time"" TIME NOT NULL)" );
} );

it( "tinyIncrements", function() {
var schema = getBuilder();
var blueprint = schema.create( "users", function( table ) {
table.tinyIncrements( "id" );
}, false );
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""users"" (""id"" INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT, PRIMARY KEY (""id""))" );
} );

it( "tinyInteger", function() {
var schema = getBuilder();
var blueprint = schema.create( "users", function( table ) {
table.tinyInteger( "active" );
}, false );
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""users"" (""active"" TINYINT NOT NULL)" );
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""users"" (""active"" INTEGER(10) NOT NULL)" );
} );

it( "tinyInteger with length", function() {
var schema = getBuilder();
var blueprint = schema.create( "users", function( table ) {
table.tinyInteger( "active", 3 );
}, false );
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""users"" (""active"" TINYINT(3) NOT NULL)" );
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""users"" (""active"" INTEGER(3) NOT NULL)" );
} );

it( "timestamp", function() {
Expand All @@ -334,16 +358,28 @@ component extends="testbox.system.BaseSpec" {
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""users"" (""age"" INTEGER(10) UNSIGNED NOT NULL)" );
} );

xit( "unsignedMediumInteger", function() {
fail( "test not implemented yet" );
it( "unsignedMediumInteger", function() {
var schema = getBuilder();
var blueprint = schema.create( "users", function( table ) {
table.unsignedMediumInteger( "age" );
}, false );
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""users"" (""age"" INTEGER(10) UNSIGNED NOT NULL)" );
} );

xit( "unsignedSmallInteger", function() {
fail( "test not implemented yet" );
it( "unsignedSmallInteger", function() {
var schema = getBuilder();
var blueprint = schema.create( "users", function( table ) {
table.unsignedSmallInteger( "age" );
}, false );
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""users"" (""age"" INTEGER(10) UNSIGNED NOT NULL)" );
} );

xit( "unsignedTinyInteger", function() {
fail( "test not implemented yet" );
it( "unsignedTinyInteger", function() {
var schema = getBuilder();
var blueprint = schema.create( "users", function( table ) {
table.unsignedTinyInteger( "age" );
}, false );
expect( blueprint.toSql() ).toBeWithCase( "CREATE TABLE ""users"" (""age"" INTEGER(10) UNSIGNED NOT NULL)" );
} );

xit( "uuid", function() {
Expand Down

0 comments on commit 2bb379d

Please sign in to comment.