Skip to content

Commit

Permalink
#197: Add default values for double/float
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurkushman committed Aug 11, 2020
1 parent 886630a commit 9d7ad74
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,8 @@ Note, that U have an ability to make any ranges for varchar, integer types throu
For instance, integer can be set to unsigned smallint with
`minimum: 1` (any number > 0) and `maximum: 2` (any number <= 3 to fit smallint db type range).

If double/float types used, then maximum goes for display length (or M) and minimum for precision (or D) in SQL e.g.: DOUBLE(M, D)

All migrations for specific module will be placed in ``` Modules/{ModuleName}/Database/Migrations/ ```

To execute them all - run: ``` php artisan module:migrate ```
Expand Down
4 changes: 2 additions & 2 deletions src/Blocks/MigrationsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ private function setNumberRow(array $attrVal, string $attrKey): void
&& ($attrVal[ApiInterface::RAML_TYPE_FORMAT] === ModelsInterface::MIGRATION_METHOD_DOUBLE
|| $attrVal[ApiInterface::RAML_TYPE_FORMAT] === ModelsInterface::MIGRATION_METHOD_FLOAT)
) {
$max = empty($attrVal[ApiInterface::RAML_INTEGER_MAX]) ? PhpInterface::PHP_TYPES_ARRAY : $attrVal[ApiInterface::RAML_INTEGER_MAX];
$min = empty($attrVal[ApiInterface::RAML_INTEGER_MIN]) ? PhpInterface::PHP_TYPES_ARRAY : $attrVal[ApiInterface::RAML_INTEGER_MIN];
$max = empty($attrVal[ApiInterface::RAML_INTEGER_MAX]) ? ModelsInterface::DEFAULT_DOUBLE_M : $attrVal[ApiInterface::RAML_INTEGER_MAX];
$min = empty($attrVal[ApiInterface::RAML_INTEGER_MIN]) ? ModelsInterface::DEFAULT_DOUBLE_D : $attrVal[ApiInterface::RAML_INTEGER_MIN];

$this->setRow($attrVal[ApiInterface::RAML_TYPE_FORMAT], $attrKey, $max . PhpInterface::COMMA
. PhpInterface::SPACE . $min);
Expand Down
12 changes: 4 additions & 8 deletions src/Types/ModelsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ interface ModelsInterface
{
public const ID = 'id';
// Laravel
public const LARAVEL_ACTIVE_RECORD = 'Model';
public const LARAVEL_MIGRATION_CLASS = 'Migration';
public const LARAVEL_PROPERTY_TABLE = 'table';
public const DEFAULT_LIMIT = 20;
public const MAX_LIMIT = 1000;
public const DEFAULT_PAGE = 1;
Expand All @@ -26,9 +23,6 @@ interface ModelsInterface
public const LARAVEL_FILTER_MAX = 'max';
public const COLUMN = 'column';
public const DIRECTION = 'direction';
public const PARENT_ID = 'parent_id';

public const COUNT = 'count';

// Methods
public const MODEL_METHOD_ALL = 'all';
Expand Down Expand Up @@ -104,16 +98,18 @@ interface ModelsInterface


public const ID_MAX_INCREMENTS = 10;
public const STRING_MAX_CHARS = 32;

// db indices
public const INDEX_TYPE_INDEX = 'index';
public const INDEX_TYPE_UNIQUE = 'unique';
public const INDEX_TYPE_PRIMARY = 'primary';
public const INDEX_TYPE_FOREIGN = 'foreign';
public const INDEX_COLUMN = '_column';
public const INDEX_REFERENCES = 'references';
public const INDEX_ON = 'on';
public const INDEX_ON_DELETE = 'onDelete';
public const INDEX_ON_UPDATE = 'onUpdate';

// default double/float values
public const DEFAULT_DOUBLE_M = 16; // display length
public const DEFAULT_DOUBLE_D = 4; // precision
}

0 comments on commit 9d7ad74

Please sign in to comment.