Coder Social home page Coder Social logo

migration-cli's Introduction

Database Migrations (Cli)

Opensource ByJG GitHub source GitHub license GitHub release Build Status

This is a simple library written in PHP for database version control. Currently supports Sqlite, MySql, Sql Server and Postgres.

Database Migration can be used as:

  • Command Line Interface
  • PHP Library to be integrated in your functional tests
  • Integrated in you CI/CD indenpent of your programming language or framework.

Important Note

This package is the command line interface of ByJG PHP Migration. To get more information about the the project and how to please visit: https://github.com/byjg/migration

Installing

composer require 'byjg/migration-cli=4.1.*'

Running in the command line

Migration library creates the 'migrate' script. It has the follow syntax:

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  create   Create the directory structure FROM a pre-existing database
  down     Migrate down the database version.
  help     Displays help for a command
  install  Install or upgrade the migrate version in a existing database
  list     Lists commands
  reset    Create a fresh new database
  up       Migrate Up the database version
  update   Migrate Up or Down the database version based on the current database version and the migration scripts available
  version  Get the current database version

Commands

Basic Usage

The basic usage is:

vendor/bin/migrate <COMMAND> --path=<scripts> uri://connection

The --path specify where the base.sql and migrate scripts are located. If you omitted the --path it will assume the current directory. You can also set the MIGRATE_PATH environment variable with the base path

The uri://connection is the uri that represents the connection to the database. You can see here to know more about the connection string.

You can omit the uri parameter if you define it in the MIGRATE_CONNECTION environment variable and the parameter path with MIGRATE_PATH environment variable

export MIGRATE_CONNECTION=sqlite:///path/to/my.db
export MIGRATE_PATH=/path/to/migrate_files

Command: create

Create a empty directory structure with base.sql and migrations/up and migrations/down for migrations. This is useful for create from scratch a migration scheme.

Ex.

migrate create /path/to/sql 

Command: install

If you already have a database but it is not controlled by the migration system you can use this method for install the required tables for migration.

migrate install mysql://server/database

Command: update

Will apply all necessary migrations to keep your database updated.

migrate update mysql://server/database

Update command can choose if up or down your database depending on your current database version. You can also specify a version:

migrate update --up-to=34

Command: reset

Creates/replace a database with the "base.sql" and apply ALL migrations

migrate reset            # reset the database and apply all migrations scripts.
migrate reset --up-to=5  # reset the database and apply the migration from the 
                         # start up to the version 5.
migrate reset --yes      # reset the database without ask anything. Be careful!!

Note on reset: You can disable the reset command by setting the environment variable MIGRATE_DISABLE_RESET to true:

export MIGRATE_DISABLE_RESET=true

Related Projects


Open source ByJG

migration-cli's People

Contributors

byjg avatar mattschlosser avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

migration-cli's Issues

Deprecated: strpos(): Non-string needles will be interpreted as strings in the future.

I'm running php 7.3.9 and getting this:

Deprecated: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in C:\xampp\htdocs\wa-next-app\vendor\symfony\console\Command\Command.php on line 611

Call Stack:
    0.0002     417984   1. {main}() C:\xampp\htdocs\wa-next-app\vendor\byjg\migration-cli\scripts\migrate:0
    2.9629    1971912   2. ByJG\DbMigration\Console\InstallCommand->__construct() C:\xampp\htdocs\wa-next-app\vendor\byjg\migration-cli\scripts\migrate:21
    2.9629    1972072   3. ByJG\DbMigration\Console\InstallCommand->configure() C:\xampp\htdocs\wa-next-app\vendor\symfony\console\Command\Command.php:77
    2.9629    1972072   4. ByJG\DbMigration\Console\InstallCommand->configure() C:\xampp\htdocs\wa-next-app\vendor\byjg\migration-cli\src\InstallCommand.php:14
    3.3742    1975352   5. ByJG\DbMigration\Console\InstallCommand->addUsage() C:\xampp\htdocs\wa-next-app\vendor\byjg\migration-cli\src\ConsoleCommand.php:51
    3.3742    1975352   6. strpos() C:\xampp\htdocs\wa-next-app\vendor\symfony\console\Command\Command.php:611

I know it's the Symfony console dependency and not your repo, so my question is can you update the dependency to a version that might have fixed this?

Edit: I actually figured out it is already using v4.3.4 which seems to be the latest version.

installation of version 4.2

I try to run

$ composer require byjg/migration-cli
getting this result
Using version ^4.2 for byjg/migration-cli
./composer.json has been updated
Running composer update byjg/migration-cli
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Root composer.json requires byjg/migration-cli ^4.2 -> satisfiable by byjg/migration-cli[4.2.0].
- byjg/migration-cli 4.2.0 requires symfony/console ^5.4 -> found symfony/console[5.4.x-dev] but it does not match your minimum-stability.

Installation failed, reverting ./composer.json to its original content.

migrate is not recognized

Hi, Im really new to this
I've tried to install composer require "byjg/migration":"4.2.*"

and tried to run command migrate, the result is migrate not recognized

image

maybe something missing?
the same issue with vendor command and others

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.