Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Allow for custom "shops" table for automatic migrations #1192

Merged
merged 11 commits into from
Sep 9, 2022

Conversation

nahid
Copy link
Contributor

@nahid nahid commented Aug 25, 2022

laravel-shopify allowing custom auth guard in their latest version. But it not support to allowing migration with custom table for shops in automatic migration.

This PR is allowing developer's to set their own shops table in config to execute migration with given name.

@nahid nahid changed the title added custom table name support in migrations added custom shops table name for automatic migrations Aug 25, 2022
Copy link
Owner

@gnikyt gnikyt left a comment

Choose a reason for hiding this comment

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

Good update, comments inside about a way to clean things up.
Can re-review after.

src/Storage/Commands/Charge.php Outdated Show resolved Hide resolved
src/Storage/Models/Charge.php Outdated Show resolved Hide resolved
@gnikyt gnikyt changed the title added custom shops table name for automatic migrations Allow for custom "shops" table for automatic migrations Sep 8, 2022
@gnikyt gnikyt requested a review from Kyon147 September 8, 2022 14:10
@gnikyt gnikyt self-assigned this Sep 8, 2022
@gnikyt gnikyt added the feature Enhancement to the code label Sep 8, 2022
src/Util.php Outdated Show resolved Hide resolved
@nahid nahid requested review from gnikyt and removed request for Kyon147 September 8, 2022 17:20
@nahid
Copy link
Contributor Author

nahid commented Sep 8, 2022

@osiset, I have already rewritten the code based on your change request. Please review the PR again. Thank you

@gnikyt
Copy link
Owner

gnikyt commented Sep 8, 2022

@nahid I am fine at a quick glance except for the fact that the table function is doing more than one thing.

It is named getShopsTable but also the the ability to return a string for a column. I'd split it into two functions... getShopsTable, and shopColumnFor or something?

or... return an array or object for getShopsTable.

Something like:

// Method A
public static function getShopsTable(): array
{
        $shopTable = Util::getShopifyConfig('table_names.shops') ?? 'users';
        $foreignId = Str::singular($shopTable) . '_id';
        return ['table' => $shopTable, 'foreign' => $foreignId];
}

// or .... Method B
public static function getShopsTable(): array
{
        $shopTable = Util::getShopifyConfig('table_names.shops') ?? 'users';
        $foreignId = Str::singular($shopTable) . '_id';
        return [$shopTable, $foreignId];
}

Usage could be something like:

$table = Util::getShopsTable()["table"];

// or ... Method B
list($table) = Util::getShopsTable();
// or ... Method B
$table = Util::getShopsTable()[0];

Or, if that feels messy, then split into two functions.

@nahid
Copy link
Contributor Author

nahid commented Sep 8, 2022

I think different method for each functionality will added more readability and developer experience as well.
Here is the example:

Util::getShopsTabel(): string

Util::getShopsTableForeignKey(): string

@gnikyt
Copy link
Owner

gnikyt commented Sep 8, 2022

@nahid I agree. Go ahead with it :)

@nahid
Copy link
Contributor Author

nahid commented Sep 8, 2022

@osiset, I have pushed the following changes, Please review again

@gnikyt
Copy link
Owner

gnikyt commented Sep 8, 2022

Solid. I'll approve letting Actions run and we'll see what happens. Probably will need test added to Until tests to ensure coverage is there.

@nahid
Copy link
Contributor Author

nahid commented Sep 8, 2022

Solid. I'll approve letting Actions run and we'll see what happens. Probably will need test added to Until tests to ensure coverage is there.

Maybe tests/Storage/Queries/ChargeTest.php file needs to be updated to code coverage. Please let me know if there is anything I can do. Thank you

@gnikyt
Copy link
Owner

gnikyt commented Sep 9, 2022

@nahid Tests pass, coverage didnt change as well, so thats OK.
Linting failed though, please see the Action for details.

@nahid
Copy link
Contributor Author

nahid commented Sep 9, 2022

@nahid Tests pass, coverage didnt change as well, so thats OK.
Linting failed though, please see the Action for details.

@osiset, I just pushed another commit with fixes, please check

@gnikyt
Copy link
Owner

gnikyt commented Sep 9, 2022

@nahid Still is failing the lint.

Locally, you can vendor/bin/php-cs-fixer fix --diff --dry-run to see what needs to be changed, and vendor/bin/php-cs-fixer fix if you're OK with automatic changes.

@nahid
Copy link
Contributor Author

nahid commented Sep 9, 2022

@osiset please check the latest commits

@gnikyt
Copy link
Owner

gnikyt commented Sep 9, 2022

Tests now pass, linting is good. @nahid

@Kyon147 I'm good with this one too if you are, seems like a feature thats been asked about before a few times.

@Kyon147
Copy link
Collaborator

Kyon147 commented Sep 9, 2022

Tests now pass, linting is good. @nahid

@Kyon147 I'm good with this one too if you are, seems like a feature thats been asked about before a few times.

Yeah looks good to me too

@gnikyt
Copy link
Owner

gnikyt commented Sep 9, 2022

@nahid Please review once more, and if you're good we'll merge this in.

@nahid
Copy link
Contributor Author

nahid commented Sep 9, 2022

@nahid Please review once more, and if you're good we'll merge this in.

@osiset sure

@gnikyt gnikyt merged commit 8967d29 into gnikyt:master Sep 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature Enhancement to the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants