Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
Clubphp
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Clubphp
Commits
ae64a019
Commit
ae64a019
authored
Apr 07, 2026
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update 2 files via Son of Anton
parent
5157eafb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
52 deletions
+43
-52
MigrationRunner.php
app/Core/Migration/MigrationRunner.php
+41
-44
Phase_11_003_create_receipts_table.php
database/migrations/Phase_11_003_create_receipts_table.php
+2
-8
No files found.
app/Core/Migration/MigrationRunner.php
View file @
ae64a019
...
...
@@ -33,12 +33,11 @@ final class MigrationRunner
echo
" Migrating:
{
$name
}
...
\n
"
;
try
{
$migration
=
require
$file
;
if
(
is_array
(
$migration
)
&&
isset
(
$migration
[
'up'
]))
{
// Array format: ['up' => 'SQL...', 'down' => 'SQL...']
$upSql
=
$migration
[
'up'
];
// Handle multiple statements separated by semicolons
$statements
=
$this
->
splitStatements
(
$upSql
);
foreach
(
$statements
as
$stmt
)
{
$stmt
=
trim
(
$stmt
);
...
...
@@ -59,6 +58,12 @@ final class MigrationRunner
]);
$results
[]
=
$name
;
echo
" ✔
{
$name
}
\n
"
;
}
catch
(
\Throwable
$e
)
{
echo
" ❌
{
$name
}
FAILED: "
.
$e
->
getMessage
()
.
"
\n
"
;
// Continue to next migration — don't let one failure kill the whole batch
continue
;
}
}
return
$results
;
...
...
@@ -84,6 +89,7 @@ final class MigrationRunner
if
(
file_exists
(
$file
))
{
echo
" Rolling back:
{
$name
}
...
\n
"
;
try
{
$migration
=
require
$file
;
if
(
is_array
(
$migration
)
&&
isset
(
$migration
[
'down'
]))
{
...
...
@@ -91,16 +97,15 @@ final class MigrationRunner
foreach
(
$statements
as
$stmt
)
{
$stmt
=
trim
(
$stmt
);
if
(
$stmt
!==
''
)
{
try
{
$this
->
db
->
raw
(
$stmt
);
}
catch
(
\Throwable
$e
)
{
echo
" ⚠️ Rollback warning for
{
$name
}
: "
.
$e
->
getMessage
()
.
"
\n
"
;
}
}
}
}
elseif
(
is_object
(
$migration
)
&&
method_exists
(
$migration
,
'down'
))
{
$migration
->
down
(
$this
->
db
);
}
}
catch
(
\Throwable
$e
)
{
echo
" ⚠️ Rollback warning: "
.
$e
->
getMessage
()
.
"
\n
"
;
}
}
$this
->
db
->
query
(
"DELETE FROM migrations WHERE migration = ?"
,
[
$name
]);
...
...
@@ -133,7 +138,6 @@ final class MigrationRunner
try
{
$this
->
db
->
selectOne
(
"SELECT 1 FROM migrations LIMIT 1"
);
}
catch
(
\Throwable
$e
)
{
// Table doesn't exist — create it
$this
->
db
->
raw
(
"
CREATE TABLE IF NOT EXISTS `migrations` (
`id` INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
...
...
@@ -167,7 +171,7 @@ final class MigrationRunner
if
(
$files
===
false
||
empty
(
$files
))
{
return
[];
}
sort
(
$files
);
// Lexicographic sort: Phase_01_001 < Phase_02_001 < Phase_03_001
sort
(
$files
);
return
$files
;
}
...
...
@@ -186,10 +190,6 @@ final class MigrationRunner
}
}
/**
* Split SQL string into individual statements.
* Handles semicolons inside the SQL properly.
*/
private
function
splitStatements
(
string
$sql
)
:
array
{
$sql
=
trim
(
$sql
);
...
...
@@ -197,14 +197,11 @@ final class MigrationRunner
return
[];
}
// Simple split on semicolons followed by whitespace/newline
// This handles 99% of cases for DDL statements
$statements
=
preg_split
(
'/;\s*\n/'
,
$sql
);
if
(
$statements
===
false
)
{
return
[
$sql
];
}
// Clean up: remove trailing semicolons from last statement
$result
=
[];
foreach
(
$statements
as
$stmt
)
{
$stmt
=
trim
(
$stmt
);
...
...
database/migrations/Phase_11_003_create_receipts_table.php
View file @
ae64a019
...
...
@@ -31,13 +31,7 @@ return [
CONSTRAINT `fk_receipts_member` FOREIGN KEY (`member_id`) REFERENCES `members`(`id`),
CONSTRAINT `fk_receipts_payment` FOREIGN KEY (`payment_id`) REFERENCES `payments`(`id`) ON DELETE SET NULL,
CONSTRAINT `chk_receipts_amount` CHECK (`amount` >= 0)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
ALTER TABLE `payments`
ADD CONSTRAINT `fk_payments_receipt` FOREIGN KEY (`receipt_id`) REFERENCES `receipts`(`id`) ON DELETE SET NULL;
"
,
'down'
=>
"
ALTER TABLE `payments` DROP FOREIGN KEY IF EXISTS `fk_payments_receipt`;
DROP TABLE IF EXISTS `receipts`;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
"
,
'down'
=>
"DROP TABLE IF EXISTS `receipts`"
,
];
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment