sevens/consoler

专门为Altvel框架构建的命令行和迁移库。

v0.1.0 2020-11-14 00:08 UTC

This package is auto-updated.

Last update: 2024-09-14 09:31:08 UTC


README

专门为Altvel设计,只能通过大量代码更改进行迁移。它是一个封闭的代码结构。

控制台命令

=> Console Command

安装

=> This will already be pre-installed with Altvel Framework
composer require sevens/consoler

初始化SchemaMap引擎

=> Since You're most likely using Altvel Framework Engineer Console, You won't be setting this up.
$schemaMap = new SchemaMap($config = [ 
	'directory' => __DIR__.'/migration', 
	'migrator'  => 'Migration.php', 
	'populator' => 'Population.php'
]);

###迁移器

=> id is automatically generated on all tables by the schemaMap Engine

=> constraints: a table can only have one primary key and it will be autogenerated

=> Add your migrations to the Migration.php file in the migration folder

=> migrations are logged in Migration.History in the Altvel Engineer Console, 

示例用例

return[
	'apps' => [
	  #the referenced table must already exist and the name must be exact to avoid errors
	  #$type can be one of ['int','string'] on a foreign key column
	  'token' => $this->foreign_key($table='sessions_table', $column='session' $type='string'),
	  
	  //$key can be one of ['unique','fulltext', '']
	  'name' => $this->string($max_length=125, $null=true, $key='fulltext'),
	  'pos' => $this->integer($max_length=10),
	  
	  //in other to specify a maximum length, float should be used instead of a double
	  'account_balance' => $this->double(),
	  'ledger' => $this->float($max_length=16), 
	  'is_verified' => $this->oneOf($options=["'true'", "'false'"], $default="'false'" ),
	  'created_at' => $this->datetime()
	],
	'users' => [
		'name' => $this->string($max_length=125, $null=false),
		'email' => $this->string($max_length=125, $null=false, $key='unique'),
		'password' => $this->string($max_length=125),
		'backup_pass' => $this->string($max_length=150),
		'activation' => $this->string($max_length=225),
		'verified' => $this->oneOf($options=["'true'", "'false'"], $default="'false'" ),
		'created_at' => $this->dateTime(),
		'deleted' => $this->oneOf($options=["'true'", "'false'"], $default="'false'" )
	],
	'contact_us' => [
		'name' => $this->string($max_length=125, $null=false),
		'email' => $this->string($max_length=125),
		'feedback' => $this->string($max_length=1025),
		'created_at' => $this->datetime(),
		'deleted' => $this->oneOf($options=["'true'", "'false'"], $default="'false'" )
	],
	'user_sessions' => [
		'user_id' => $this->foreign_key($table='users', $column='id', $type = 'int' ),
		'session' => $this->string($max_length=225, $null=false),
		'user_agent' => $this->string($max_length=225, $null=false),
		'push_token' => $this->string($max_length=225, $null=false),
		'created_at' => $this->dateTime(),
		'deleted' => $this->oneOf($options=["'true'", "'false'"], $default="'false'" )
	],
];

###填充文件

通过向population.php返回数组添加数组数组,以这种格式向表中填充数据

return [
	'table name' => [ 'column name' => 'value' , 'column name' => 'value' , 'column name' => 'value' ],
	'table name' => [...],
];

示例用例

return [

	'users' => [
		[
			'name' => "Elisha TemmyScope",
			'email' => "esdentemmy@gmail.com",
			'password' => hash("password"),
			'activation' => "random code",
			'verified' => "false",
			'created_at' => date("Y-m-d h:i:s"),
			'deleted' => "false"
		]
	],

];