Skip to content

Other Actions

Clean the database and export the schema.

Clean the database

The clean action drops the tables of the database, or deletes their data. It does not drop the log table, the SQLite internal tables (for example sqlite_sequence) or the PostgreSQL tables of an extension. Without --force, it stops with the error The clean action drops tables or deletes data: add --force to run it.

vendor/bin/phalcon-migrations clean --force
Command Result
clean --force Drops all the tables and empties the log. The next run starts from the first version
clean --force --table=users,roles Drops only these tables. The log does not change
clean --force --data-only Deletes the rows of all the tables, and keeps the tables. The log does not change

--table accepts table names, separated with commas. Tables that refer to each other work.

Export the schema

The export action shows the SQL of the schema of the migration files at a version. The default is the newest version.

vendor/bin/phalcon-migrations export --config=migrations.php --version=1.0.0

The output has the CREATE TABLE statements first. Then it has the other statements of the tables, for example the PostgreSQL and SQLite indexes and the PostgreSQL column comments. Then it has the foreign keys. For the example file above, the output on MySQL is:

CREATE TABLE `users` (
    `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
    `email` VARCHAR(255) NOT NULL COMMENT 'Login email',
    `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`),
    UNIQUE KEY `users_email_uindex` (`email`)
) ENGINE=InnoDB COLLATE=utf8mb4_unicode_ci;
  • To export only some tables, use --table with table names, separated with commas.
  • The names have no schema.
  • The output has no data.
  • The database does not change. If a morph() method has code other than morphTable(), export runs that code.

To write the SQL to a file, redirect the output. The banner and the error messages go to stderr, so the file has only the SQL:

vendor/bin/phalcon-migrations export --config=migrations.php > schema.sql
Navigation

Type to search…

↑↓ navigate↵ selectEsc close