creonit/propel-schema-converter-bundle
Symfony bundle that lets you define Propel database schemas in YAML. Place schema.yml in Resources/config, run Propel build/migration commands, and the bundle generates schema.xml automatically. Supports columns, indexes, unique keys, relations, and behaviors.
Installation:
composer require creonit/propel-schema-converter-bundle
Register the bundle in config/bundles.php (Laravel) or AppKernel.php (Symfony):
Creonit\PropelSchemaConverterBundle\CreonitPropelSchemaConverterBundle::class => ['all' => true],
First Schema File:
Create config/propel/schema.yml (or src/YourBundle/Resources/config/schema.yml for bundle-specific schemas):
config:
database:
name: default
namespace: App\Models
package: src/Models
Generate Models:
php bin/console propel:schema:convert
This generates schema.xml in the same directory.
Build Models/Migrations:
php bin/console propel:build --no-confirm
Define a simple users table in schema.yml:
users:
id: integer ~pk
name: varchar(255)
email: varchar(255) ~uniq
created_at: timestamp
Run propel:schema:convert and propel:build to generate models and migrations.
Modular Schema Files:
Split schemas by domain (e.g., users.yml, products.yml) and merge them in a root schema.yml:
# config/propel/schema.yml
import:
- { resource: "users.yml" }
- { resource: "products.yml" }
Reusable Config Blocks:
Define shared configurations (e.g., config/database.yml) and include them:
config:
+: { resource: "database.yml" }
namespace: App\Models\Users
Schema-First Development:
schema.xml → Build models.propel:schema:diff to compare changes before migrations:
php bin/console propel:schema:diff --write-sql
Behavior Integration:
Attach Propel behaviors (e.g., timestampable, sortable) directly in YAML:
users:
+behavior:
- timestampable
- sortable: { column: name }
Foreign Key Relationships: Define relationships declaratively:
orders:
user_id: int ~fk:users.id
product_id: int ~fk:products.id
Migration Generation:
Use propel:migrate:diff to generate migrations from schema changes:
php bin/console propel:migrate:diff --write-sql > migrations/20230101000000_create_users.sql
Laravel-Specific:
config/propel/ and update config/propel.php to point to the bundle.Manager:
$this->app->bind('propel.manager', function () {
return Propel::getConnectionManager()->getConnection('default')->getManager();
});
Testing:
PropelTestCase for database-agnostic tests:
use Creonit\PropelSchemaConverterBundle\Tests\PropelTestCase;
class UserTest extends PropelTestCase {
public function testUserCreation() {
$user = new User();
$user->setName('Test');
$user->save();
$this->assertEquals(1, UserQuery::create()->count());
}
}
CI/CD:
propel:build to your deployment script to ensure schemas are up-to-date.propel:schema:validate to catch schema issues early:
php bin/console propel:schema:validate
Namespace Conflicts:
namespace in config matches your actual model directory (e.g., App\Models).AppBundle\Model).Behavior Misconfiguration:
timestampable require specific column names (e.g., created_at, updated_at). Mismatches cause runtime errors.propel:schema:validate:
php bin/console propel:schema:validate --behaviors
Foreign Key Syntax:
~fk:table.column) may not generate proper constraints. Use:
user_id: int ~fk:users.id(onDelete: CASCADE)
YAML Parsing Errors:
yamllint) to catch issues early.-, +). Use underscores instead.Schema Overwrites:
propel:schema:convert overwrites schema.xml. Back up or use version control for this file.Dry Runs:
Use --dry-run to preview changes:
php bin/console propel:schema:convert --dry-run
Log Output: Enable verbose mode for detailed logs:
php bin/console propel:build -vvv
SQL Generation: Generate SQL without executing to verify migrations:
php bin/console propel:migrate:diff --write-sql > migration.sql
Partial Updates:
Use propel:schema:convert --only=table_name to regenerate a single table’s schema.
Custom Types:
Extend Propel’s types by defining custom mappings in config/propel.php:
'types' => [
'json' => ['class' => 'Propel\Runtime\Connection\ConnectionInterface::TYPE_VARCHAR'],
],
Environment-Specific Schemas:
Override schemas per environment (e.g., schema.dev.yml, schema.prod.yml) and load them conditionally:
# config/propel/schema.yml
config:
+: { resource: "schema.${APP_ENV}.yml" }
IDE Support:
php bin/console propel:build --write-doc
Performance:
schema.xml in CI to avoid runtime conversion.propel:build --no-confirm in scripts to skip interactive prompts.Extending the Bundle:
# config/services.yaml
Creonit\PropelSchemaConverterBundle\Converter\YamlSchemaConverter:
arguments:
$customLogic: '@your.custom_service'
How can I help you explore Laravel packages today?