View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 17492 | Bug reports | Other | public | 2021-08-02 20:17 | 2022-02-28 12:58 |
| Reporter | ollehar | Assigned To | ollehar | ||
| Priority | none | Severity | minor | ||
| Status | closed | Resolution | fixed | ||
| Summary | 17492: Refactor updatedb helper into multiple command classes | ||||
| Description | https://refactoring.guru/design-patterns/command/php/example https://www.yiiframework.com/doc/guide/1.1/en/database.migration https://www.yiiframework.com/doc/guide/2.0/en/db-migrations Use-case:
NB: Using timestamp for dbversion instead of a small manual number is the same as manual number but with larger space between the number. File: updatedb_helper.php Function db_upgrade_all() signature stays exactly the same but is added to a new service class. The function body is refactored. Algorithm:
class DatabaseUpdateHelper Interface: interface DatabaseUpdateInterface Alternative base class: abstract class DatabaseUpdateBase Example class: Class name is DatabaseUpdate_ + timestamp when update was created. This timestamp replaces dbversion number to avoid merge conflicts when multiple updates are added. // TODO: Inherit from CDbMigration? It has all helper methods like dropIndex(), addPrimaryKey(), etc public function safeUp() public function isCritical() private function upgradeTokenTables134() A Yii command is added to generate the scaffold class for a new database update, including the timestamp class name. $ php yii command/create-new-update | ||||
| Tags | No tags attached. | ||||
| Bug heat | 8 | ||||
| Complete LimeSurvey version number (& build) | |||||
| I will donate to the project if issue is resolved | |||||
| Browser | |||||
| Database type & version | |||||
| Server OS (if known) | |||||
| Webserver software & version (if known) | |||||
| PHP Version | |||||
| Git branch / Pull Request URL | N/A | ||||
|
About the refactor, make sense to include each migration in its own file. I like the general approach.
I know laravel works with migrations. I have some ideas about changing: That would avoid most of the collisions: collisions of independent migrations. Just a thought. We can ellaborate more. Another idea:
|
|
Maybe we can name files with the base dbversion they are based on. |
|
Check the Yii links at the top. I wouldn't mind logging all applied migrations to see if anything missed. Not a big effort. |
|
|
|
Sorry, I meant in relation to Laravel migrations. :) Yii migrations does not take into account different branches, tho. Don't know if Laravel does. Can google it. |
|
|
Other ideas:
|
|
|
The command class could add an assert() function to check for post-conditions visible when debug = 2. |
|
|
Another thing to consider is logging (via Yii) to make debugging easier. Tear-down will not be supported. |
|
|
NB: Split big updates into smaller parts to be able to trace problems? NB: Use floats for dbversion to designate parts of an update? |
|
An example?
Could be a good idea for the update helper. We need to see how to include that requirement in the whole package |
|
Not sure, actually. The problem is with auto-commit, which happens when you do addColumn, dropColumn and other structural changes. If the db update then breaks in the middle, you're screwed and have to either restore the database or manually revert it. |
|
|
Ohh those updates you mean. Good. We can put them ina different DB version. |
|
|
Started to work on this on branch dev/17492-refactor-updatedb |
|
|
Vim macro with writing to file: :call writefile(getreg("", 1, 1), "Update_" . getreg("a") . ".php") Delete first line (begin transaction) in ls | xargs -i sed -i '1d' {} Delete last two lines of all update files: ls | xargs -i sed -i -e :a -e '$d;N;2,2ba' -e 'P;D' {} Replace oDB with this->db in all update files: ls | xargs -i sed -i 's/oDB/this->db/g' {} |
|
|
codegen.php (646 bytes)
<?php
// Small script to fix update files.
$file = $argv[1];
$lines = file($file);
$parts = explode('_', $file);
$dbVersion = (int) $parts[1];
$lines = array_merge(
array_map(
fn ($l) => $l . PHP_EOL,
[
'<?php',
'',
'namespace LimeSurvey\Helpers\Update;',
'',
sprintf('class Update_%d extends DatabaseUpdateBase', $dbVersion),
'{',
' public function run()',
' {',
],
),
$lines
);
$lines = array_merge(
$lines,
[
' }' . PHP_EOL,
'}'
],
);
file_put_contents($file, $lines);
|
|
|
Love this code generation scripts! |
|
|
^^ |
|
|
TODO: Logging TODO: Make it possible to mock db connection |
|
|
codegen !!! |
|
|
Hack the planet! :D |
|
|
Fixed in Release 5.3.0+220228 |
|
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2021-08-02 20:17 | ollehar | New Issue | |
| 2021-08-02 20:23 | ollehar | Description Updated | |
| 2021-08-02 20:27 | ollehar | Description Updated | |
| 2021-08-02 20:29 | ollehar | Description Updated | |
| 2021-08-02 20:33 | ollehar | Description Updated | |
| 2021-08-02 20:35 | ollehar | Description Updated | |
| 2021-08-02 20:36 | ollehar | Description Updated | |
| 2021-08-02 20:37 | ollehar | Description Updated | |
| 2021-08-02 20:39 | ollehar | Description Updated | |
| 2021-08-02 20:41 | ollehar | Description Updated | |
| 2021-08-02 20:41 | ollehar | Product Version | => 5.x.0-dev |
| 2021-08-02 20:42 | ollehar | Description Updated | |
| 2021-08-02 20:43 | ollehar | Description Updated | |
| 2021-08-02 20:51 | ollehar | Description Updated | |
| 2021-08-02 20:51 | ollehar | Description Updated | |
| 2021-08-02 20:52 | ollehar | Description Updated | |
| 2021-08-02 20:53 | ollehar | Sync to Zoho Project | => |Yes| |
| 2021-08-02 20:54 | LimeBot | Zoho Projects ID | => 85781000001111001 |
| 2021-08-02 20:55 | ollehar | Description Updated | |
| 2021-08-02 20:55 | ollehar | Sync to Zoho Project | Yes => |Yes| |
| 2021-08-02 20:58 | ollehar | Description Updated | |
| 2021-08-02 20:58 | ollehar | Sync to Zoho Project | Yes => |Yes| |
| 2021-08-02 21:04 | ollehar | Description Updated | |
| 2021-08-02 21:04 | ollehar | Sync to Zoho Project | Yes => |Yes| |
| 2021-08-03 15:04 | galads | Assigned To | => ollehar |
| 2021-08-03 15:04 | galads | Status | new => assigned |
| 2021-08-04 14:00 | ollehar | Description Updated | |
| 2021-08-04 14:00 | ollehar | Sync to Zoho Project | Yes => |Yes| |
| 2021-08-04 14:01 | ollehar | Description Updated | |
| 2021-08-04 14:01 | ollehar | Sync to Zoho Project | Yes => |Yes| |
| 2021-08-04 14:23 | ollehar | Description Updated | |
| 2021-08-04 14:23 | ollehar | Sync to Zoho Project | Yes => |Yes| |
| 2021-08-04 14:26 | ollehar | Description Updated | |
| 2021-08-04 14:26 | ollehar | Sync to Zoho Project | Yes => |Yes| |
| 2021-08-04 14:33 | gabrieljenik | Note Added: 65808 | |
| 2021-08-04 14:38 | gabrieljenik | Note Added: 65810 | |
| 2021-08-04 14:51 | ollehar | Note Added: 65814 | |
| 2021-08-04 15:02 | gabrieljenik | Note Added: 65816 | |
| 2021-08-04 15:03 | ollehar | Note Added: 65818 | |
| 2021-08-06 11:44 | ollehar | Note Added: 65872 | |
| 2021-08-13 15:13 | ollehar | Note Added: 65962 | |
| 2021-08-13 15:18 | ollehar | Note Added: 65964 | |
| 2021-08-19 11:27 | ollehar | Note Added: 66066 | |
| 2021-08-19 14:20 | gabrieljenik | Note Added: 66073 | |
| 2021-08-19 14:21 | ollehar | Note Added: 66075 | |
| 2021-08-19 16:04 | gabrieljenik | Note Added: 66078 | |
| 2021-11-15 17:24 | ollehar | Note Added: 67334 | |
| 2021-11-15 17:25 | ollehar | Zoho Project Synchronization | Yes => |
| 2021-11-15 17:25 | ollehar | Zoho Projects ID | 85781000001111001 => |
| 2021-11-16 14:34 | ollehar | Note Added: 67342 | |
| 2021-11-16 14:37 | ollehar | Note Added: 67343 | |
| 2021-11-16 14:37 | ollehar | File Added: codegen.php | |
| 2021-11-16 15:14 | gabrieljenik | Note Added: 67345 | |
| 2021-11-16 15:34 | ollehar | Note Added: 67346 | |
| 2021-11-16 15:39 | ollehar | Note Edited: 67346 | |
| 2021-11-16 15:40 | ollehar | Note Edited: 67342 | |
| 2021-11-16 18:28 | ollehar | Note Added: 67347 | |
| 2021-11-17 11:46 | ollehar | Status | assigned => ready for testing |
| 2021-11-26 11:12 | DenisChenu | Note Added: 67584 | |
| 2021-11-26 11:31 | ollehar | Note Added: 67585 | |
| 2022-02-28 12:58 | LimeBot | Note Added: 68431 | |
| 2022-02-28 12:58 | LimeBot | Status | ready for testing => closed |
| 2022-02-28 12:58 | LimeBot | Resolution | open => fixed |