Skip to content

Commit d7cda9b

Browse files
committed
Add SQLite compatibility for enum columns in GDPR migration
Updates the GDPR user deletion migration to ensure compatibility with SQLite by replacing `enum` columns with `string` columns when SQLite is detected. Retains the use of `enum` for other database types. Improves cross-database support and ensures migrations can be executed consistently across supported database platforms.
1 parent acfc5f1 commit d7cda9b

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

db/migrations/20250120181848_gdpr_user_deletion.php

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,28 @@ public function change(): void
2929
->addColumn('user_id', 'integer', array_merge(['null' => false], $unsigned))
3030
->addColumn('requested_by_user_id', 'integer', array_merge(['null' => false], $unsigned))
3131
->addColumn('request_date', 'datetime', ['null' => false])
32-
->addColumn('reason', 'text', ['null' => true])
33-
->addColumn('deletion_type', 'enum', [
34-
'values' => ['soft', 'hard', 'anonymize'],
35-
'default' => 'soft',
36-
'null' => false
37-
])
38-
->addColumn('status', 'enum', [
39-
'values' => ['pending', 'approved', 'rejected', 'completed'],
40-
'default' => 'pending',
41-
'null' => false
42-
])
32+
->addColumn('reason', 'text', ['null' => true]);
33+
34+
// Add enum columns - use enum for MySQL/PostgreSQL, string for SQLite
35+
if ($this->adapter->getAdapterType() === 'sqlite') {
36+
$deletionRequests
37+
->addColumn('deletion_type', 'string', ['limit' => 20, 'default' => 'soft', 'null' => false])
38+
->addColumn('status', 'string', ['limit' => 20, 'default' => 'pending', 'null' => false]);
39+
} else {
40+
$deletionRequests
41+
->addColumn('deletion_type', 'enum', [
42+
'values' => ['soft', 'hard', 'anonymize'],
43+
'default' => 'soft',
44+
'null' => false
45+
])
46+
->addColumn('status', 'enum', [
47+
'values' => ['pending', 'approved', 'rejected', 'completed'],
48+
'default' => 'pending',
49+
'null' => false
50+
]);
51+
}
52+
53+
$deletionRequests
4354
->addColumn('reviewed_by_user_id', 'integer', array_merge(['null' => true], $unsigned))
4455
->addColumn('review_date', 'datetime', ['null' => true])
4556
->addColumn('review_notes', 'text', ['null' => true])
@@ -57,11 +68,19 @@ public function change(): void
5768
$deletionAudit
5869
->addColumn('deletion_request_id', 'integer', array_merge(['null' => false], $unsigned))
5970
->addColumn('table_name', 'string', ['limit' => 128, 'null' => false])
60-
->addColumn('record_id', 'integer', ['null' => true])
61-
->addColumn('action', 'enum', [
71+
->addColumn('record_id', 'integer', ['null' => true]);
72+
73+
// Add action column - use enum for MySQL/PostgreSQL, string for SQLite
74+
if ($this->adapter->getAdapterType() === 'sqlite') {
75+
$deletionAudit->addColumn('action', 'string', ['limit' => 20, 'null' => false]);
76+
} else {
77+
$deletionAudit->addColumn('action', 'enum', [
6278
'values' => ['deleted', 'anonymized', 'retained'],
6379
'null' => false
64-
])
80+
]);
81+
}
82+
83+
$deletionAudit
6584
->addColumn('reason', 'string', ['limit' => 255, 'null' => true])
6685
->addColumn('data_before', 'text', ['null' => true])
6786
->addColumn('data_after', 'text', ['null' => true])

0 commit comments

Comments
 (0)