Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to keep fixed order for database columns? #195

Open
iwasherefirst2 opened this issue Oct 5, 2021 · 2 comments
Open

How to keep fixed order for database columns? #195

iwasherefirst2 opened this issue Oct 5, 2021 · 2 comments

Comments

@iwasherefirst2
Copy link

iwasherefirst2 commented Oct 5, 2021

I am using iseed to store specific settings table into production. My problem is that the order of the attributes changes every time I use iseed. I am already using "orderby" flag to make sure the order of elements does not change, but the attributs within each row seem to get a random order every time. Its a bit of a pain, because everytime I just change one row, essentially all rows +1000k lines will be changed.
This makes my commits unnecessarly large and the worst is, its hard to check and verify, if the reuqired change actually is in there.

Can I enfore one strict order of columns of the db fixed while using iseed (maybe alphabetically)?

@tig3
Copy link

tig3 commented Oct 8, 2021

@iwasherefirst2 had the same issue

Short temporary "solution" if you do not use the exclude option

Just comment out this line in vendor before running the command https://github.com/orangehill/iseed/blob/master/src/Orangehill/Iseed/Iseed.php#L139

$result = $result->select(array_diff($allColumns, $exclude));

Explanation

this->grammar->compileColumnListing()

"select column_name as `column_name` from information_schema.columns where table_schema = ? and table_name = ?"
  • Now, the above Mysql query returns the list of columns by A-Z order, which then being used to define the order of columns during select inside if condition with exclude option.

To order the columns by how they are defined in the table - in mysql query it should be added ORDER BY ORDINAL_POSITION ASC part
https://stackoverflow.com/questions/59357254/mysql-query-returns-columns-in-different-order-after-update/59383493#59383493

@iwasherefirst2
Copy link
Author

Actually if you don't use exclude, then you will never reach this line. so no need to exclude it. If I got you right, then columns are already sorted by A-Z order? I will observe future commits, I thought this was not the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants