File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ var Column = function(config) {
2020 direction : new TextNode ( 'DESC' )
2121 } ) ;
2222 this . dataType = config . dataType ;
23+ this . defaultValue = config . defaultValue ;
2324} ;
2425
2526// mix in value expression
Original file line number Diff line number Diff line change @@ -826,6 +826,9 @@ Postgres.prototype.visitColumn = function(columnNode) {
826826 if ( ! columnNode . primaryKey && columnNode . unique ) {
827827 txt . push ( ' UNIQUE' ) ;
828828 }
829+ if ( columnNode . defaultValue !== undefined ) {
830+ txt . push ( ' DEFAULT ' + this . _getParameterValue ( columnNode . defaultValue ) ) ;
831+ }
829832 }
830833
831834 if ( ! ! columnNode . references ) {
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ module.exports = Node.define({
2020 this . distinct = config . distinct ;
2121 this . primaryKey = config . primaryKey ;
2222 this . notNull = config . notNull ;
23+ this . defaultValue = config . defaultValue ;
2324 this . references = config . references ;
2425 // If subfieldContainer is present, this is a subfield and subfieldContainer
2526 // is the parent Column
Original file line number Diff line number Diff line change @@ -248,6 +248,39 @@ Harness.test({
248248 }
249249} ) ;
250250
251+ Harness . test ( {
252+ query : Table . define ( {
253+ name : 'user' ,
254+ columns : [ {
255+ name : 'id' ,
256+ dataType : 'int' ,
257+ primaryKey : true ,
258+ notNull : true
259+ } , {
260+ name : 'posts' ,
261+ dataType : 'int' ,
262+ notNull : true ,
263+ defaultValue : 0
264+ } ]
265+ } ) . create ( ) ,
266+ pg : {
267+ text : 'CREATE TABLE "user" ("id" int PRIMARY KEY, "posts" int NOT NULL DEFAULT 0)' ,
268+ string : 'CREATE TABLE "user" ("id" int PRIMARY KEY, "posts" int NOT NULL DEFAULT 0)'
269+ } ,
270+ sqlite : {
271+ text : 'CREATE TABLE "user" ("id" int PRIMARY KEY, "posts" int NOT NULL DEFAULT 0)' ,
272+ string : 'CREATE TABLE "user" ("id" int PRIMARY KEY, "posts" int NOT NULL DEFAULT 0)'
273+ } ,
274+ mysql : {
275+ text : 'CREATE TABLE `user` (`id` int PRIMARY KEY, `posts` int NOT NULL DEFAULT 0)' ,
276+ string : 'CREATE TABLE `user` (`id` int PRIMARY KEY, `posts` int NOT NULL DEFAULT 0)'
277+ } ,
278+ oracle : {
279+ text : 'CREATE TABLE "user" ("id" int PRIMARY KEY, "posts" int NOT NULL DEFAULT 0)' ,
280+ string : 'CREATE TABLE "user" ("id" int PRIMARY KEY, "posts" int NOT NULL DEFAULT 0)'
281+ }
282+ } ) ;
283+
251284Harness . test ( {
252285 query : Table . define ( {
253286 name : 'post' ,
You can’t perform that action at this time.
0 commit comments