Download the PHP package pinkcrab/wp-db-migrations without Composer

On this page you can find all versions of the php package pinkcrab/wp-db-migrations. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?
pinkcrab/wp-db-migrations
Rate from 1 - 5
Rated 5.00 based on 1 reviews

Informations about the package wp-db-migrations

WPDB_Migrations

System for creating database migrations with WordPress

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require GitHub contributors GitHub issues WordPress 5.9 Test Suite [PHP7.2-8.1] WordPress 6.0 Test Suite [PHP7.2-8.1] WordPress 6.1 Test Suite [PHP7.2-8.1] codecov Scrutinizer Code Quality Maintainability


Requirements

Requires PinkCrab Table Builder, Composer and WordPress.

Uses the WPDB Table Builder library.

TESTED AGAINST

  • PHP 7.2, 7.3, 7.4, 8.0 & 8.1
  • Mysql 5.7, MariaDB 10.2, 10.3, 10.4, 10.5, 10.6 & 10.7
  • WP5.9, WP6.0 & WP6.1

Installation

If you are using this with the PinkCrab Perique framework, please use the Perique Migrations module.

Why

Creates a wrapper around the WPDB_Table_Builder to make it easier to create Migrations for use with WP plugins or themes. Allows for the creation and dropping of database tables and the seeding of initial data.

How to use

You will need to create your Migrations using the abstract class.

Read the Schema documentation

Once you have your Migrations created it is a case of using the Migration_Manager to handle the creation, seeding and eventual dropping of the table.

Read the Builder documentation

It is suggested to wrap create_tables, seed_tables and drop_tables in a try/catch as they can throw exceptions.

Reade more about the Migration Manager

Factory

You can create an instance of both a Migration Manager and Migration Log.

Factory::manager_with_db_delta(?string $option_key = null, ?wpdb $wpdb = null)

Can be used to create a manager set with a standard wpdb instance. A custom log option key can be defined and a custom wpdb instance can be used if you wish to use multiple databases.

Factory::migration_log(?string $option_key = null)

Creates an instance of the migration log, the option key used in the migration manager can be optionally passed if a custom value is set.

Migration Log

The Migration Manager has an internal log which is serialised and stored as a WP Option. This is used to ensure that tables are only updated when the schema has changed and that only a single seeding of each table can happen. If you need to access the Log, you can either call it from a Migration_Manager instance or by creating an instance.

Reade more about the Migration Log

Exceptions

During the process, multiple exceptions can be thrown, these are all

All of our exceptions contain the instance of Schema being worked on, this can be accessed via $exception->get_schema(). Also WPDB error is set if WPDB error triggered, this can be accessed using $exception->get_wpdb_error() (seed_column_doesnt_exist, doesn't use this)

seed_column_doesnt_exist

Thrown when trying get the column data from a schema, where the column doesn't exist.

Message: Could not find column {column name} in {table name} schema definition

Error Code: 1

failed_to_insert_seed

Thrown when attempting to insert seed data, but wpdb returns an error.

Message: Could not insert seed into {table name}, failed with error {wpdb error}

Error Code: 2

failed_to_drop_table

Thrown when wpdb produces an error removing a table.

Message: Failed to drop {table name}

Error Code: 3

Use With Plugins

The best way to use the Migration service is as part of your plugins activation/uninstall process. This would ensure that all tables are created and seeded when the plugin is activated and all tables are dropped when the plugin is uninstalled.

Thanks to the Migration_Log, tables will only be reprocessed if the schema has changed and data can only be seeded once. So if you plan to add seed data in for later versions of your plugin, they can be added when ready.

When working with Foreign Keys, ensure that all base tables are created first, then those that reference it. But when dropping ensure this is done in reverse.

Tables are all created, then all seeded in the same order

See our example plugin


Change log


All versions of wp-db-migrations with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2.0
pinkcrab/table_builder Version 1.2.*
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package pinkcrab/wp-db-migrations contains the following files

Loading the files please wait ....