itemvirtual/laravel-doctrine

Doctrine Console Commands for Laravel framework

1.0.6 2023-03-14 15:44 UTC

This package is auto-updated.

Last update: 2024-04-14 18:22:24 UTC


README

Latest Version on Packagist Total Downloads

Doctrine Console Commands for Laravel framework.
This package is just to keep your database in sync (instead of migrations).
Update, validate and generate xml-mappings from the database.

Installation

You can install the package via composer:

composer require itemvirtual/laravel-doctrine

In order to edit the default configuration you may execute: (with --force option to update)

php artisan vendor:publish --provider="Itemvirtual\LaravelDoctrine\LaravelDoctrineServiceProvider" --tag=config

Laravel comes with some predefined migrations, you can put them in place with this publish

php artisan vendor:publish --provider="Itemvirtual\LaravelDoctrine\LaravelDoctrineServiceProvider" --tag=laravel_default_migrations

Usage

· Generate xml-mappings from database

This command is only useful when you have an existing database, It should not be necessary for you to call this method multiple times

You can provide the destination path where the generated files will be saved.
You also have the option to only generate the mappings for certain tables.

php artisan doctrine:generate-mappings [--path=destination/path/to/xml-mappings] [--table=<table_name>]+
php artisan doctrine:generate-mappings --path=database/doctrine/xml-mappings --table=ursers --table=password_resets

Options:

  --path[=PATH]     The path where your xml-mapping files will be generated
  --table[=TABLE]   The database tables to be generated (multiple values allowed)

· Validate mappings and database

Check if the associations are defined correctly, and their mappings are in sync with the database.
You can remove all your entities before perform validating.

php artisan doctrine:validate [-R | --remove-entities]

Options:

  -R, --remove-entities  Delete current entities before generating new ones

· Update database

Run the queries to update your database or preview them without querying.
You can remove all of your entities before upgrading.
Every time you run this command, doctrine:generate-entities is called

php artisan doctrine:update [-D | --dump-sql] [-R | --remove-entities]
php artisan doctrine:update -DR

Options:

  -D, --dump-sql         Dumps generated SQL statements to the console (does not execute them)
  -R, --remove-entities  Delete current entities before generating new ones

· Cache clear

Sometimes you can get missing entity errors, deleting cached data can help to fix it.

php artisan doctrine:clear-cache [--flush]

# This command will run these three commands at once, you can run them separately if you want 
php artisan doctrine:clear-cache:metadata [--flush]
php artisan doctrine:clear-cache:query [--flush]
php artisan doctrine:clear-cache:result [--flush]

Options:

  --flush    If defined, cache entries will be flushed instead of deleted/invalidated

· Generate migrations (for testing)

For testing purposes, you will need your project migrations. You can generate it with the following command.
By default, they will be generated in tests/database/migrations

php artisan doctrine:migrations-generate [destination/path]
php artisan doctrine:migrations-generate --tables users,password_resets --ignore users,password_resets

Arguments:

  path    If defined, it will generate the files in the given path, by default

Options:

  -R, --remove                     Remove previous generated migration files
  -O, --output                     View migrations package console output
  -S, --single-file[=SINGLE-FILE]  Generate all migrations in a single file [default: "true"]
  -T, --tables[=TABLES]            A list of Tables or Views you wish to Generate Migrations separated by comma: users,products,labels
  -I, --ignore[=IGNORE]            A list of Tables or Views you wish to ignore, separated by comma: users,products,labels

Available commands for the "doctrine" namespace

  doctrine:clear-cache           Clear metadata, query and result cache of the various cache drivers
  doctrine:clear-cache:metadata  Clear all metadata cache of the various cache drivers
  doctrine:clear-cache:query     Clear all query cache of the various cache drivers
  doctrine:clear-cache:result    Clear all result cache of the various cache drivers
  doctrine:convert-mapping       Convert mapping information between supported formats
  doctrine:generate-entities     Generate entity classes and method stubs from your mapping information (xml-mappings)
  doctrine:generate-mappings     Generate xml-mappings from your database
  doctrine:remove-entities       Remove all entities
  doctrine:update                Update the database (or dump SQL) based on the entities information
  doctrine:validate              Validate mappings and synchronization with the database
  doctrine:migrations-generate   Generate laravel migration files from database 

You can see the arguments and options of each of them with the help command

php artisan -help <command>

utf8mb4

To change the character set and collation of a table, add this options to the entity

<options>
    <option name="collate">utf8mb4_unicode_ci</option>
    <option name="charset">utf8mb4</option>
</options>

Problems with mysql 5.7

mysql versions prior to 5.7.7 may throw an error "Specified key was too long; max key length is 767 bytes"
You must verify that any column of type string and unique=true must set its maximum length="190"

Important, check the indexes

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

Doctrine XML Mapping documentation and examples

Doctrine documentation Doctrine Types