Skip to content

Commit

Permalink
seeds and migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
douglas committed Feb 19, 2020
1 parent b5be604 commit 29600c3
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 2 deletions.
Binary file added public/assets/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/db/migrations/20200219004255_create_users_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function change()
$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->addForeignKey('role_id', 'roles', 'id',['delete'=> 'SET_NULL']);
$table->addColumn("created",'timestamp', ['default' => 'CURRENT_TIMESTAMP']);
$table->create();
}
Expand Down
38 changes: 38 additions & 0 deletions src/db/migrations/20200219201636_add_column_uri_role.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

use Phinx\Migration\AbstractMigration;

class AddColumnUriRole 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("roles");
$table->addColumn("uri","string",["limit" => 255]);
$table->save();
}
}
20 changes: 19 additions & 1 deletion src/db/seeds/RolesSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,30 @@ class RolesSeeder extends AbstractSeed
*/
public function run()
{
/**
* 1 => "/painel/admin",
2 => "/painel/professor",
3 => "/painel/cliente"
*/
$data = [
[
'name' => 'admin',
'description' => "Administrador do Sistema",
'uri' => "/painel/admin",
'created' => date('Y-m-d H:i:s')
]
],
[
'name' => 'professor',
'description' => "Administra os Cursos dele",
'uri' => "/painel/professor",
'created' => date('Y-m-d H:i:s')
],
[
'name' => 'cliente',
'description' => "Acessa seus dados e cursos matriculados",
'uri' => "/painel/cliente",
'created' => date('Y-m-d H:i:s')
],
];

$roles = $this->table('roles');
Expand Down
19 changes: 19 additions & 0 deletions src/db/seeds/UserSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,28 @@ public function run()
'avatar' => '',
'role_id' => 1,
'created' => date('Y-m-d H:i:s')
],
[
'name' => 'professor',
'email' => '[email protected]',
'password' => '$2y$12$o0vmN5EMkgjEiBxtRot3T.JN.Yvhu1TxYpI3qfG0Xl4QvxImE0.ZC',
'phone' => '21993725886',
'avatar' => '',
'role_id' => 2,
'created' => date('Y-m-d H:i:s')
],
[
'name' => 'cliente',
'email' => '[email protected]',
'password' => '$2y$12$o0vmN5EMkgjEiBxtRot3T.JN.Yvhu1TxYpI3qfG0Xl4QvxImE0.ZC',
'phone' => '21993725886',
'avatar' => '',
'role_id' => 3,
'created' => date('Y-m-d H:i:s')
]
];

$this->table('users')->truncate();
$users = $this->table('users');
$users->insert($data)->saveData();
}
Expand Down

0 comments on commit 29600c3

Please sign in to comment.