Skip to content

Commit

Permalink
Merge pull request #6 from qwertywelch/master
Browse files Browse the repository at this point in the history
Default values, fix smallint & bigint, support mediumint
  • Loading branch information
huyphams authored Mar 27, 2019
2 parents 237bc2b + e997e89 commit 1fb9e47
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 26 deletions.
34 changes: 19 additions & 15 deletions tabledump.tableplusplugin/library/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,37 +59,41 @@ function getColumnMigrate(columnName, dataType, isNullable) {
break;
case "int8":
case "bigint":
if (dataType.includes("unsigned")) {
migration = "$table->unsignedBigInteger('" + columnName + "')";
} else {
migration = "$table->bigInteger('" + columnName + "')";
}
migration = "$table->bigInteger('" + columnName + "')";
break;
case "int":
case "int4":
if (dataType.includes("unsigned")) {
migration = "$table->bigIncrements('" + columnName + "')";
} else {
migration = "$table->integer('" + columnName + "')";
}
migration = "$table->integer('" + columnName + "')";
break;
case "int3":
case "mediumint":
migration = "$table->mediumInteger('" + columnName + "')";
break;
case "int2":
case "smallint":
migration = "$table->smallInteger('" + columnName + "')";
break;
case "int1":
case "tinyint":
if (dataType.includes("unsigned")) {
migration = "$table->unsignedTinyInteger('" + columnName + "')";
} else {
migration = "$table->tinyInteger('" + columnName + "')";
}
migration = "$table->tinyInteger('" + columnName + "')";
break;
default:
migration = `$table->${typeOnly}('` + columnName + "')";
break;
}
if (dataType.includes("unsigned")) {
migration += "->unsigned()";
}
if (isNullable.toLowerCase().startsWith("y")) {
migration += "->nullable()";
}
if (defaultVal) {
// ensure non-ints are properly escaped
if (!typeOnly.includes("int")) {
defaultVal = JSON.stringify(defaultVal);
}
migration += "->default(" + defaultVal + ")";
}
return migration + ";";
}

Expand Down
41 changes: 30 additions & 11 deletions tabledump.tableplusplugin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1fb9e47

Please sign in to comment.