Skip to content

Commit b5215b5

Browse files
committed
Added the DEV sql
1 parent 50cc7fe commit b5215b5

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,25 @@ For example: 00002.sql is the script for move the database from version '1' to '
6666
For example: 00001.sql is the script for move the database from version '2' to '1'.
6767
The "down" folder is optional.
6868

69+
### Multi Development environment
70+
71+
If you work with multiple developers and multiple branches it is to difficult to determine what is the next number.
72+
73+
In that case you have the suffix "-dev" after the version number.
74+
75+
See the scenario:
76+
77+
- Developer 1 create a branch and the most recent version in e.g. 42.
78+
- Developer 2 create a branch at the same time and have the same database version number.
79+
80+
In both case the developers will create a file called 43-dev.sql. Both developers will migrate UP and DOWN with
81+
no problem and your local version will be 43.
82+
83+
But developer 1 merged your changes and created a final version 43.sql (`git mv 43-dev.sql 43.sql`). If the developer 2
84+
update your local branch he will have a file 43.sql (from dev 1) and your file 43-dev.sql.
85+
If he is try to migrate UP or DOWN
86+
the migration script will down and alert him there a TWO versions 43. In that case, developer 2 will have to update your
87+
file do 44-dev.sql and continue to work until merge your changes and generate a final version.
6988

7089
## Running in the command line
7190

@@ -76,9 +95,12 @@ Usage:
7695
command [options] [arguments]
7796
7897
Available commands:
98+
create Create the directory structure FROM a pre-existing database
99+
install Install or upgrade the migrate version in a existing database
79100
down Migrate down the database version.
80101
reset Create a fresh new database
81102
up Migrate Up the database version
103+
version Get the current database version
82104
83105
Arguments:
84106
connection The connection string. Ex. mysql://root:password@server/database [default: false]
@@ -91,7 +113,7 @@ Example:
91113
migrate down --up-to=3 --path=/somepath mysql://root:password@server/database
92114
```
93115

94-
## Suportted databases:
116+
## Supported databases:
95117

96118
* Sqlite
97119
* Mysql / MariaDB
@@ -101,7 +123,7 @@ Example:
101123
## Installing Globally
102124

103125
```bash
104-
composer global require 'byjg/migration=1.1.*'
126+
composer global require 'byjg/migration=2.0.*'
105127
sudo ln -s $HOME/.composer/vendor/bin/migrate /usr/local/bin
106128
```
107129

src/Migration.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,15 @@ public function getMigrationSql($version, $increment)
102102
$this->_folder
103103
. "/migrations"
104104
. "/" . ($increment < 0 ? "down" : "up")
105-
. "/*$version.sql"
105+
. "/*\{$version,{$version}-dev\}.sql",
106+
GLOB_BRACE
106107
);
107108

109+
// Valid values are 0 or 1
110+
if (count($result) > 1) {
111+
throw new \InvalidArgumentException("You have two files with the same version $version number");
112+
}
113+
108114
foreach ($result as $file) {
109115
if (intval(basename($file)) == $version) {
110116
return $file;
@@ -170,8 +176,8 @@ protected function canContinue($currentVersion, $upVersion, $increment)
170176
{
171177
$existsUpVersion = ($upVersion !== null);
172178
$compareVersion = strcmp(
173-
str_pad($currentVersion, 5, '0', STR_PAD_LEFT),
174-
str_pad($upVersion, 5, '0', STR_PAD_LEFT)
179+
str_pad($currentVersion, 10, '0', STR_PAD_LEFT),
180+
str_pad($upVersion, 10, '0', STR_PAD_LEFT)
175181
) == $increment;
176182

177183
return !($existsUpVersion && $compareVersion);

0 commit comments

Comments
 (0)