-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from douglas-88/projeto-final
Implementando Migration User and Role
- Loading branch information
Showing
10 changed files
with
123 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
class CreateUsersTable extends AbstractMigration | ||
{ | ||
/** | ||
* Change Method. | ||
* | ||
* Write your reversible migrations using this method. | ||
* | ||
* More information on writing migrations is available here: | ||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class | ||
* | ||
* The following commands can be used in this method and Phinx will | ||
* automatically reverse them when rolling back: | ||
* | ||
* createTable | ||
* renameTable | ||
* addColumn | ||
* addCustomColumn | ||
* renameColumn | ||
* addIndex | ||
* addForeignKey | ||
* | ||
* Any other destructive changes will result in an error when trying to | ||
* rollback the migration. | ||
* | ||
* Remember to call "create()" or "update()" and NOT "save()" when working | ||
* with the Table class. | ||
*/ | ||
public function change() | ||
{ | ||
$table = $this->table("users"); | ||
$table->addColumn("name","string",["limit" => 255]); | ||
$table->addColumn("password","string",["limit" => 60]); | ||
$table->addColumn("email","string",["limit" => 70]); | ||
$table->addColumn("phone","string",["limit" => 11]); | ||
$table->addColumn("avatar","string",["limit" => 300]); | ||
$table->addColumn('role_id', 'integer', ['null' => false]); | ||
$table->addForeignKey('role_id', 'roles', 'id'); | ||
$table->addColumn("created",'timestamp', ['default' => 'CURRENT_TIMESTAMP']); | ||
$table->create(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
|
||
use Phinx\Seed\AbstractSeed; | ||
|
||
class RolesSeeder extends AbstractSeed | ||
{ | ||
/** | ||
* Run Method. | ||
* | ||
* Write your database seeder using this method. | ||
* | ||
* More information on writing seeders is available here: | ||
* http://docs.phinx.org/en/latest/seeding.html | ||
*/ | ||
public function run() | ||
{ | ||
$data = [ | ||
[ | ||
'name' => 'admin', | ||
'description' => "Administrador do Sistema", | ||
'created' => date('Y-m-d H:i:s') | ||
] | ||
]; | ||
|
||
$roles = $this->table('roles'); | ||
$roles->insert($data)->saveData(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
|
||
use Phinx\Seed\AbstractSeed; | ||
|
||
class UserSeeder extends AbstractSeed | ||
{ | ||
/** | ||
* Run Method. | ||
* | ||
* Write your database seeder using this method. | ||
* | ||
* More information on writing seeders is available here: | ||
* http://docs.phinx.org/en/latest/seeding.html | ||
*/ | ||
public function run() | ||
{ | ||
$data = [ | ||
[ | ||
'name' => 'admin', | ||
'email' => '[email protected]', | ||
'password' => '$2y$12$o0vmN5EMkgjEiBxtRot3T.JN.Yvhu1TxYpI3qfG0Xl4QvxImE0.ZC', | ||
'phone' => '21993725886', | ||
'avatar' => '', | ||
'role_id' => 1, | ||
'created' => date('Y-m-d H:i:s') | ||
] | ||
]; | ||
|
||
$users = $this->table('users'); | ||
$users->insert($data)->saveData(); | ||
} | ||
} |