File tree Expand file tree Collapse file tree 6 files changed +66
-7
lines changed
Expand file tree Collapse file tree 6 files changed +66
-7
lines changed Original file line number Diff line number Diff line change @@ -44,10 +44,6 @@ migrate: replenish
4444migrate-to :
4545 @docker compose exec -u www-data web sh -c ' . ./scripts/migrate-version.sh && ./orm migrations:migrate $$migrations --object-manager doctrine.entitymanager.$$alias'
4646
47- migration-list : replenish
48- @docker compose exec -u www-data -T web ./orm migrations:list --object-manager doctrine.entitymanager.orm_default
49- @docker compose exec -u www-data -T web ./orm migrations:list --object-manager doctrine.entitymanager.orm_report
50-
5147migration-diff : replenish
5248 @docker compose exec -u root web chown www-data:www-data /code/module/Database/migrations/
5349 @docker compose exec -u www-data -T web ./orm migrations:diff --object-manager doctrine.entitymanager.orm_default
@@ -58,10 +54,10 @@ migration-diff: replenish
5854 @docker cp " $( shell docker compose ps -q web) " :/code/module/Report/migrations ./module/Report
5955 @docker compose exec -u root web chown -R root:root /code/module/Report/migrations/
6056
61- migration-up : replenish migration-list
57+ migration-up : replenish
6258 @docker compose exec -u www-data web sh -c ' . ./scripts/migrate-version.sh && ./orm migrations:execute --up $$migrations --object-manager doctrine.entitymanager.$$alias'
6359
64- migration-down : replenish migration-list
60+ migration-down : replenish
6561 @docker compose exec -u www-data web sh -c ' . ./scripts/migrate-version.sh && ./orm migrations:execute --down $$migrations --object-manager doctrine.entitymanager.$$alias'
6662
6763seed : replenish
Original file line number Diff line number Diff line change 66
77use Application \Model \Enums \ConfigNamespaces ;
88use Database \Model \Trait \TimestampableTrait ;
9+ use Database \Model \Trait \VersionTrait ;
910use DateTime ;
1011use Doctrine \ORM \Mapping \Column ;
1112use Doctrine \ORM \Mapping \Entity ;
3435class ConfigItem
3536{
3637 use TimestampableTrait;
38+ // We implement locking by using version numbers (optimistic locking)
39+ // rather than by banning other processes from locking the same row.
40+ // This is more versatile and is possible because we do not care which
41+ // process in the end changes the config, as long as it is only one.
42+ use VersionTrait;
3743
3844 /**
3945 * Primary key item ID (to avoid reference issues).
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Database \Migrations ;
6+
7+ use Doctrine \DBAL \Schema \Schema ;
8+ use Doctrine \Migrations \AbstractMigration ;
9+
10+ final class Version20251207150548 extends AbstractMigration
11+ {
12+ public function getDescription (): string
13+ {
14+ return 'Implement versioning of config items for optimistic locking ' ;
15+ }
16+
17+ public function up (Schema $ schema ): void
18+ {
19+ $ this ->addSql ('ALTER TABLE configitem ADD version INT DEFAULT 1000 NOT NULL ' );
20+ }
21+
22+ public function down (Schema $ schema ): void
23+ {
24+ $ this ->addSql ('ALTER TABLE ConfigItem DROP version ' );
25+ }
26+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Database \Model \Trait ;
6+
7+ use Doctrine \ORM \Mapping \Column ;
8+ use Doctrine \ORM \Mapping \Version ;
9+
10+ trait VersionTrait
11+ {
12+ /**
13+ * integer version
14+ * From the docs:
15+ * "Version numbers [should] be preferred as they can not potentially conflict in a highly concurrent environment"
16+ */
17+ #[Version()]
18+ #[Column(type: 'integer ' )]
19+ private int $ version ;
20+ }
Original file line number Diff line number Diff line change 1+ # /bin/sh
2+
3+ # This script prints the available migrations for a specific alias
4+ set -e
5+
6+ . /code/scripts/migrate-alias.sh
7+
8+ ./orm migrations:list --no-interaction --object-manager doctrine.entitymanager.$alias
9+
10+ export alias=$alias
11+ export migrations=$migrations
Original file line number Diff line number Diff line change 44# If you put this directly in the makefile, replace $ with $$
55set -e
66
7- . /code/scripts/migrate-alias .sh
7+ . /code/scripts/migrate-list .sh
88
99read -rp " Give (partial, unique) version name (e.g. Database\Migrations\Version20241020224949 or 20241020)): " version
1010
You can’t perform that action at this time.
0 commit comments