Skip to content

Commit 88b98ae

Browse files
Enforce CamelCase Latin migration names
1 parent 271a0c9 commit 88b98ae

3 files changed

Lines changed: 33 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All significant changes to this project will be documented in this file.
44

5+
## [1.4.2] - 2025-12-10
6+
7+
### Changed
8+
9+
- **CLI make:migration:** Migration names must now be CamelCase Latin words (e.g., `CreateUsersTable`); invalid names are rejected with an error.
10+
511
## [1.4.1] - 2025-12-10
612

713
### Added

README.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
A lightweight, framework-agnostic database layer for PHP.
99
Part of the Codemonster ecosystem — but works fully standalone.
1010

11-
## 📦 Installation
11+
## Installation
1212

1313
```bash
1414
composer require codemonster-ru/database
1515
```
1616

17-
## 🚀 Usage
17+
## Usage
1818

1919
### 1. Database Manager
2020

@@ -232,7 +232,7 @@ transaction(fn() => // convenience wrapper
232232

233233
Helpers are thin wrappers around `DatabaseManager` and the connection’s `schema()` / `transaction()` methods.
234234

235-
## 📐 Schema Builder
235+
## Schema Builder
236236

237237
The package includes a lightweight schema builder.
238238

@@ -271,7 +271,7 @@ $db->schema()->drop('users');
271271
$db->schema()->dropIfExists('users');
272272
```
273273

274-
## 🗄 Supported Column Types
274+
## Supported Column Types
275275

276276
- Integers: `id`, `integer`, `bigInteger`, `mediumInteger`, `smallInteger`, `tinyInteger`
277277
- Floats: `decimal`, `double`, `float`
@@ -283,7 +283,7 @@ $db->schema()->dropIfExists('users');
283283
- Indexes: `index`, `unique`, `primary`
284284
- Foreign keys with `foreign()` / `references()` / `on()` and `onDelete()` / `onUpdate()` helpers
285285

286-
## 🚦 Migrations
286+
## Migrations
287287

288288
The package includes a migration system (designed to be used via the CLI).
289289

@@ -314,7 +314,7 @@ return new class extends Migration {
314314
};
315315
```
316316

317-
## 🧬 ORM (ActiveRecord / Eloquent‑style)
317+
## ORM (ActiveRecord / Eloquent‑style)
318318

319319
**Since 1.3.0**, the package includes a complete ORM layer:
320320

@@ -371,7 +371,7 @@ $user->save();
371371
$user->delete();
372372
```
373373

374-
## 🔗 Relationships
374+
## Relationships
375375

376376
Available relations:
377377

@@ -408,7 +408,7 @@ $user->posts;
408408
$user->load('posts');
409409
```
410410

411-
## 🧹 Soft Deletes
411+
## Soft Deletes
412412

413413
```php
414414
use Codemonster\Database\Traits\SoftDeletes;
@@ -423,7 +423,7 @@ class User extends Model {
423423
- `User::onlyTrashed()`
424424
- `User::withTrashed()`
425425

426-
## 🧰 CLI Tool
426+
## CLI Tool
427427

428428
A standalone CLI ships with the package:
429429

@@ -455,6 +455,8 @@ vendor/bin/database migrate:status
455455
vendor/bin/database make:migration CreatePostsTable
456456
```
457457

458+
Migration names must be CamelCase using only Latin letters (e.g., `CreateUsersTable`). Names that include other symbols or casing styles are rejected.
459+
458460
Default migrations directory:
459461

460462
```text
@@ -467,16 +469,16 @@ You can override paths via the migration kernel/path resolver:
467469
$kernel->getPathResolver()->addPath('/path/to/migrations');
468470
```
469471

470-
## 🧪 Tests
472+
## Tests
471473

472474
```bash
473475
composer test
474476
```
475477

476-
## 👨‍💻 Author
478+
## Author
477479

478480
[**Kirill Kolesnikov**](https://github.com/KolesnikovKirill)
479481

480-
## 📜 License
482+
## License
481483

482484
[MIT](https://github.com/codemonster-ru/database/blob/main/LICENSE)

src/CLI/Commands/MakeMigrationCommand.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ public function handle(array $arguments): int
3535
return 1;
3636
}
3737

38+
if (!$this->isValidName($name)) {
39+
fwrite(STDERR, "Migration name must be CamelCase, Latin letters only. Example: CreateUsersTable\n");
40+
41+
return 1;
42+
}
43+
3844
$path = $this->detectPath();
3945

4046
if (!$path) {
@@ -76,11 +82,17 @@ protected function detectPath(): ?string
7682
return null;
7783
}
7884

85+
protected function isValidName(string $name): bool
86+
{
87+
return (bool) preg_match('/^[A-Z][a-z]*(?:[A-Z][a-z]*)*$/', $name);
88+
}
89+
7990
protected function buildFileName(string $name): string
8091
{
8192
$now = new \DateTimeImmutable('now');
8293
$timestamp = $now->format('Y_m_d_His');
83-
$slug = preg_replace('/[^A-Za-z0-9]+/', '_', $name);
94+
$slug = preg_replace('/(?<!^)([A-Z])/', '_$1', $name);
95+
$slug = preg_replace('/[^A-Za-z0-9]+/', '_', $slug);
8496
$slug = trim($slug, '_');
8597
$slug = strtolower($slug);
8698

0 commit comments

Comments
 (0)