Skip to content

Commit a487829

Browse files
committed
Add support for SQL Server collation in flowforgePositionColumn macro and update README
1 parent 9933694 commit a487829

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ php artisan flowforge:make-board TaskBoard --model=Task
6262
- **PHP:** 8.3+
6363
- **Laravel:** 11+
6464
- **Filament:** 4.x
65-
- **Database:** MySQL, PostgreSQL, SQLite
65+
- **Database:** MySQL, PostgreSQL, SQLite, SQL Server, MariaDB
6666

6767
---
6868

@@ -342,6 +342,19 @@ Schema::create('tasks', function (Blueprint $table) {
342342
$table->flowforgePositionColumn('sort_order'); // Creates 'sort_order' column instead
343343
```
344344

345+
### Database-Specific Collations
346+
347+
The `flowforgePositionColumn()` method automatically applies the correct binary collation for each database:
348+
349+
| Database | Collation | Purpose |
350+
|----------|-----------|---------|
351+
| **MySQL/MariaDB** | `utf8mb4_bin` | Binary comparison by character code values |
352+
| **PostgreSQL** | `C` | Binary byte comparison (POSIX locale) |
353+
| **SQL Server** | `Latin1_General_BIN2` | Unicode code-point comparison |
354+
| **SQLite** | None | Uses `BINARY` collation by default |
355+
356+
These collations ensure consistent fractional ranking behavior across all database systems.
357+
345358
### Factory Integration
346359

347360
<details>

src/FlowforgeServiceProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ private function registerBlueprintMacros(): void
157157
return match ($driver) {
158158
'pgsql' => $column->collation('C'),
159159
'mysql' => $column->collation('utf8mb4_bin'),
160-
default => $column,
160+
'sqlsrv' => $column->collation('Latin1_General_BIN2'),
161+
default => $column, // No collation needed - BINARY by default, e.g. SQLite
161162
};
162163
});
163164
}

tests/Feature/BlueprintMacroTest.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,47 @@
4848
->and($column->get('collation'))->toBe('utf8mb4_bin');
4949
});
5050

51+
test('flowforgePositionColumn macro creates position column with correct collation for SQL Server', function () {
52+
// Mock SQL Server connection
53+
DB::shouldReceive('connection->getDriverName')
54+
->once()
55+
->andReturn('sqlsrv');
56+
57+
$blueprint = new Blueprint('test_table');
58+
$column = $blueprint->flowforgePositionColumn();
59+
60+
expect($column)->toBeInstanceOf(ColumnDefinition::class)
61+
->and($column->get('type'))->toBe('string')
62+
->and($column->get('nullable'))->toBeTrue()
63+
->and($column->get('collation'))->toBe('Latin1_General_BIN2');
64+
});
65+
66+
test('flowforgePositionColumn macro works with SQLite (no collation needed)', function () {
67+
// Mock SQLite connection
68+
DB::shouldReceive('connection->getDriverName')
69+
->once()
70+
->andReturn('sqlite');
71+
72+
$blueprint = new Blueprint('test_table');
73+
$column = $blueprint->flowforgePositionColumn();
74+
75+
expect($column)->toBeInstanceOf(ColumnDefinition::class)
76+
->and($column->get('type'))->toBe('string')
77+
->and($column->get('nullable'))->toBeTrue()
78+
->and($column->get('collation'))->toBeNull(); // SQLite uses BINARY by default
79+
});
80+
5181
test('flowforgePositionColumn macro works with unsupported database driver', function () {
5282
// Mock unsupported driver
5383
DB::shouldReceive('connection->getDriverName')
5484
->once()
55-
->andReturn('sqlite');
85+
->andReturn('unknown_driver');
5686

5787
$blueprint = new Blueprint('test_table');
5888
$column = $blueprint->flowforgePositionColumn();
5989

6090
expect($column)->toBeInstanceOf(ColumnDefinition::class)
6191
->and($column->get('type'))->toBe('string')
6292
->and($column->get('nullable'))->toBeTrue()
63-
->and($column->get('collation'))->toBeNull();
93+
->and($column->get('collation'))->toBeNull(); // Graceful fallback
6494
});

0 commit comments

Comments
 (0)