Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/LoadEntities.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,32 @@ function DumpDDL(array $paths, string $dialect, ?Configuration $config = null):
);
$entityManager = new MockEntityManager($connection, $config);
$metadatas = $entityManager->getMetadataFactory()->getAllMetadata();

$directives = [];
foreach ($metadatas as $metadata) {
$class = $metadata->getReflectionClass();
if (($file = $class->getFileName())
&& ($start = $class->getStartLine())
&& ($end = $class->getEndLine())
) {
$relPath = str_replace(getcwd() . DIRECTORY_SEPARATOR, '', $file);
$relPath = str_replace(DIRECTORY_SEPARATOR, '/', $relPath);
$directives[] = sprintf(
'-- atlas:pos %s[type=table] %s:%d-%d',
$metadata->getTableName(),
$relPath,
$start,
$end
);
}
}
$output = '';
if (!empty($directives)) {
$output .= implode("\n", $directives) . "\n\n";
}
$sql = (new SchemaTool($entityManager))->getCreateSchemaSql($metadatas);
return empty($sql) ? '' : implode(";\n", $sql) . ";\n";
if (!empty($sql)) {
$output .= implode(";\n", $sql) . ";\n";
}
return $output;
}
4 changes: 2 additions & 2 deletions tests/BundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testRegisterCommandsNoConfig(): void
'--dialect' => 'mysql',
'--path' => 'tests/entities/uppercase'
]);
$expected = "CREATE TABLE UserCommands (id INT AUTO_INCREMENT NOT NULL, command VARCHAR(255) NOT NULL, PRIMARY KEY(id));\n";
$expected = "-- atlas:pos UserCommands[type=table] tests/entities/uppercase/UserCommands.php:8-17\n\nCREATE TABLE UserCommands (id INT AUTO_INCREMENT NOT NULL, command VARCHAR(255) NOT NULL, PRIMARY KEY(id));\n";
$this->assertEquals($expected, $commandTester->getDisplay());
}

Expand Down Expand Up @@ -63,7 +63,7 @@ public function testRegisterCommandsWithConfig(): void
$commandTester->execute([
'command' => $command->getName(),
]);
$expected = "CREATE TABLE user_commands (id INT AUTO_INCREMENT NOT NULL, command VARCHAR(255) NOT NULL, PRIMARY KEY(id));\n";
$expected = "-- atlas:pos user_commands[type=table] tests/entities/uppercase/UserCommands.php:8-17\n\nCREATE TABLE user_commands (id INT AUTO_INCREMENT NOT NULL, command VARCHAR(255) NOT NULL, PRIMARY KEY(id));\n";
$this->assertEquals($expected, $commandTester->getDisplay());
}
}
3 changes: 3 additions & 0 deletions tests/data/regular_mysql.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
-- atlas:pos users[type=table] tests/entities/regular/User.php:11-28
-- atlas:pos bugs[type=table] tests/entities/regular/Bug.php:12-33

CREATE TABLE users (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id));
CREATE TABLE bugs (id INT AUTO_INCREMENT NOT NULL, description VARCHAR(255) NOT NULL, created DATETIME NOT NULL, status VARCHAR(255) NOT NULL, engineer_id INT DEFAULT NULL, reporter_id INT DEFAULT NULL, INDEX IDX_1E197C9F8D8CDF1 (engineer_id), INDEX IDX_1E197C9E1CFE6F5 (reporter_id), PRIMARY KEY(id));
ALTER TABLE bugs ADD CONSTRAINT FK_1E197C9F8D8CDF1 FOREIGN KEY (engineer_id) REFERENCES users (id);
Expand Down
3 changes: 3 additions & 0 deletions tests/data/regular_postgres.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
-- atlas:pos users[type=table] tests/entities/regular/User.php:11-28
-- atlas:pos bugs[type=table] tests/entities/regular/Bug.php:12-33

CREATE TABLE users (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id));
CREATE TABLE bugs (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, description VARCHAR(255) NOT NULL, created TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, status VARCHAR(255) NOT NULL, engineer_id INT DEFAULT NULL, reporter_id INT DEFAULT NULL, PRIMARY KEY(id));
CREATE INDEX IDX_1E197C9F8D8CDF1 ON bugs (engineer_id);
Expand Down
3 changes: 3 additions & 0 deletions tests/data/regular_sqlite.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
-- atlas:pos users[type=table] tests/entities/regular/User.php:11-28
-- atlas:pos bugs[type=table] tests/entities/regular/Bug.php:12-33

CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name VARCHAR(255) NOT NULL);
CREATE TABLE bugs (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, description VARCHAR(255) NOT NULL, created DATETIME NOT NULL, status VARCHAR(255) NOT NULL, engineer_id INTEGER DEFAULT NULL, reporter_id INTEGER DEFAULT NULL, CONSTRAINT FK_1E197C9F8D8CDF1 FOREIGN KEY (engineer_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_1E197C9E1CFE6F5 FOREIGN KEY (reporter_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE);
CREATE INDEX IDX_1E197C9F8D8CDF1 ON bugs (engineer_id);
Expand Down
3 changes: 3 additions & 0 deletions tests/data/regular_sqlserver.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
-- atlas:pos users[type=table] tests/entities/regular/User.php:11-28
-- atlas:pos bugs[type=table] tests/entities/regular/Bug.php:12-33

CREATE TABLE users (id INT IDENTITY NOT NULL, name NVARCHAR(255) NOT NULL, PRIMARY KEY (id));
CREATE TABLE bugs (id INT IDENTITY NOT NULL, description NVARCHAR(255) NOT NULL, created DATETIME2(6) NOT NULL, status NVARCHAR(255) NOT NULL, engineer_id INT, reporter_id INT, PRIMARY KEY (id));
CREATE INDEX IDX_1E197C9F8D8CDF1 ON bugs (engineer_id);
Expand Down