Skip to content

Commit 01e4c86

Browse files
authored
Merge pull request #1 from byjg/1.1
1.1
2 parents 56e2708 + f23c89a commit 01e4c86

36 files changed

+807
-83
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
55

66
# User-specific stuff:
7+
.idea
78
.idea/workspace.xml
89
.idea/tasks.xml
910
.idea/dictionaries

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
language: php
22
php:
3+
- "7.1"
34
- "7.0"
45
- "5.6"
5-
- "5.5"
6-
- "5.4"
76

87
install:
98
- composer install
109

1110
script:
12-
- phpunit
11+
- phpunit tests/SqliteCommandTest.php
1312

README.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Database Migrations
22
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/byjg/migration/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/byjg/migration/?branch=master)
33
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/571cb412-7018-4938-a4e5-0f9ce44956d7/mini.png)](https://insight.sensiolabs.com/projects/571cb412-7018-4938-a4e5-0f9ce44956d7)
4+
[![Build Status](https://travis-ci.org/byjg/migration.svg?branch=master)](https://travis-ci.org/byjg/migration)
45

56
A micro framework in PHP for managing a set of database migrations using pure Sql.
67

@@ -18,8 +19,8 @@ The basic usage is
1819
See an example:
1920

2021
```php
21-
$connection = new ConnectionManagement('mysql://migrateuser:migratepwd@localhost/migratedatabase');
22-
$migration = new Migration($connection, '.');
22+
$connectionUri = new \ByJG\Util\Uri('mysql://migrateuser:migratepwd@localhost/migratedatabase');
23+
$migration = new Migration($connectionUri, '.');
2324

2425
// Restore the database using the "base.sql" script and run ALL existing scripts for up the database version
2526
// and run the up() method to maintain the database updated;
@@ -90,9 +91,29 @@ Example:
9091
migrate down --up-to=3 --path=/somepath mysql://root:password@server/database
9192
```
9293

94+
## Suportted databases:
95+
96+
* Sqlite
97+
* Mysql / MariaDB
98+
* Postgres
99+
* SqlServer
100+
93101
## Installing Globally
94102

95103
```bash
96-
composer global require 'byjg/migration=1.0.*'
104+
composer global require 'byjg/migration=1.1.*'
97105
sudo ln -s $HOME/.composer/vendor/bin/migrate /usr/local/bin
98106
```
107+
108+
## Unit Tests
109+
110+
This library has integrated tests and need to be setup for each database you want to test.
111+
112+
Basiclly you have the follow tests:
113+
114+
```
115+
phpunit tests/SqliteCommandTest.php
116+
phpunit tests/MysqlCommandTest.php
117+
phpunit tests/PostgresCommandTest.php
118+
phpunit tests/SqlServerCommandTest.php
119+
```

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
"email": "joao@byjg.com.br"
88
}
99
],
10+
"minimum-stability": "dev",
11+
"prefer-stable": true,
1012
"require": {
11-
"byjg/anydataset": "2.1.*",
13+
"byjg/anydataset": "3.0.*",
14+
"byjg/uri": "1.0.*",
1215
"symfony/console": "3.1.*"
1316
},
1417
"autoload": {

example/mysql/test_mysql.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<?php
22

3-
require "../../vendor/autoload.php";
3+
require __DIR__ . "/../../vendor/autoload.php";
44

55
/**
66
* Make sure you have a database with the user 'migrateuser' and password 'migratepwd'
77
*
88
* This user need to have grant for DDL commands;
99
*/
1010

11-
$connection = new \ByJG\AnyDataset\ConnectionManagement('mysql://migrateuser:migratepwd@localhost/migratedatabase');
11+
$uri = new \ByJG\Util\Uri('mysql://root:password@mysql-container/migratedatabase');
1212

13-
$migration = new \ByJG\DbMigration\Migration($connection, '.');
13+
$migration = new \ByJG\DbMigration\Migration($uri, __DIR__);
1414

1515
$migration->prepareEnvironment();
1616

example/postgres/base.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
-- --------------------------------------------------------
3+
-- THIS IS THE BASE FILE . The version '0'
4+
-- --------------------------------------------------------
5+
6+
-- Create the demo table USERS and populate it
7+
8+
create table users (
9+
10+
id SERIAL NOT NULL PRIMARY KEY,
11+
name varchar(50) NOT NULL,
12+
createdate VARCHAR(8)
13+
14+
);
15+
16+
insert into users (name, createdate) values ('John Doe', '20160110');
17+
insert into users (name, createdate) values ('Jane Doe', '20151230');
18+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
-- --------------------------------------------------------
3+
-- This is the script for migrate DOWN
4+
-- from version '1' to version '0'
5+
--
6+
-- This is the reverse operation of the script up/00001
7+
-- --------------------------------------------------------
8+
9+
ALTER TABLE users
10+
ADD COLUMN createdate_old VARCHAR(8) NULL;
11+
12+
update users
13+
set createdate_old = TO_CHAR(createdate,'YYYYMMDD');
14+
15+
ALTER TABLE users
16+
DROP COLUMN createdate;
17+
18+
ALTER TABLE users
19+
RENAME COLUMN createdate_old TO createdate;
20+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
-- --------------------------------------------------------
3+
-- This is the script for migrate DOWN
4+
-- from version '2' to version '1'
5+
--
6+
-- This is the reverse operation of the script up/00002
7+
-- --------------------------------------------------------
8+
9+
drop table roles;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
-- --------------------------------------------------------
3+
-- This is the script for migrate up
4+
-- from version '0' to version '1'
5+
-- --------------------------------------------------------
6+
7+
8+
ALTER TABLE users
9+
ADD COLUMN createdate_new DATE NULL;
10+
11+
update users
12+
set createdate_new = TO_DATE(createdate, 'YYYYMMDD');
13+
14+
ALTER TABLE users
15+
DROP COLUMN createdate;
16+
17+
ALTER TABLE users
18+
RENAME COLUMN createdate_new TO createdate;
19+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
-- --------------------------------------------------------
3+
-- This is the script for migrate up
4+
-- from version '1' to version '2'
5+
-- --------------------------------------------------------
6+
7+
create table roles
8+
(
9+
id SERIAL NOT NULL PRIMARY KEY,
10+
rolename char(1) NOT NULL,
11+
userid int not null
12+
)

0 commit comments

Comments
 (0)