Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Therefore, you can add `first_name`, `last_name`, and `avatar` columns to table
php spark migrate -n Datamweb\ShieldOAuth
```

The default size of the `username` field created by Shield is **30** characters. Since Oauth uses the `username` field for the user's email address, this often is not large enough. Consider increasing the size of this field to `VARCHAR(256)`. _The migrations make this change for you_.

> **Note**
> By default, `Shield OAuth` uses columns named `first_name`, `last_name`, and `avatar`.
> For any reason, if you want to consider another name for them columns, you can do it through the config file(`config/ShieldOAuthConfig.php`) and set the desired values in:
Expand Down
10 changes: 10 additions & 0 deletions src/Database/Migrations/2022-10-20-182737_ShieldOAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ public function up(): void
];

$this->forge->addColumn('users', $fields);

$fields2 = [
'username' => [
'type' => 'VARCHAR(256)',
'null' => true,
]
];
Comment on lines +58 to +63
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Inconsistent column type declaration format.

The way you're defining the type for the username column is inconsistent with the format used for other columns in this file. Other columns separate 'type' and 'constraint', but here they're combined.

        $fields2 = [
            'username'     => [
-                'type'     => 'VARCHAR(256)',
+                'type'       => 'VARCHAR',
+                'constraint' => '256',
                'null'     => true,
            ]
        ];
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$fields2 = [
'username' => [
'type' => 'VARCHAR(256)',
'null' => true,
]
];
$fields2 = [
'username' => [
'type' => 'VARCHAR',
'constraint' => '256',
'null' => true,
]
];


// use 'modify' since the prerequisite Shield plugin will certainly have created this column
$this->forge->modifyColumn('users', $fields2);
Comment on lines +58 to +66
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Size discrepancy between migration and documentation.

The migration is setting the username field to VARCHAR(256), but the documentation in install.md suggests VARCHAR(100). Consider aligning these values for consistency.

        $fields2 = [
            'username'     => [
-                'type'     => 'VARCHAR(256)',
+                'type'     => 'VARCHAR(100)',
                'null'     => true,
            ]
        ];

Alternatively, update the documentation to reflect the actual size being set.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$fields2 = [
'username' => [
'type' => 'VARCHAR(256)',
'null' => true,
]
];
// use 'modify' since the prerequisite Shield plugin will certainly have created this column
$this->forge->modifyColumn('users', $fields2);
$fields2 = [
'username' => [
'type' => 'VARCHAR(100)',
'null' => true,
]
];
// use 'modify' since the prerequisite Shield plugin will certainly have created this column
$this->forge->modifyColumn('users', $fields2);

}

public function down(): void
Expand Down
Loading