Skip to content

Commit f6c2331

Browse files
committed
Added the SqliteCommand and examples for migrate using Sqlite;
1 parent f5a493d commit f6c2331

File tree

20 files changed

+254
-54
lines changed

20 files changed

+254
-54
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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)
44

5-
A micro project in PHP for managing a set of database migrations using pure Sql.
5+
A micro framework in PHP for managing a set of database migrations using pure Sql.
66

77
Database Migration is a set of commands for upgrade or downgrade a database.
88
This library uses only SQL commands.
@@ -21,7 +21,8 @@ See an example:
2121
$connection = new ConnectionManagement('mysql://migrateuser:migratepwd@localhost/migratedatabase');
2222
$migration = new Migration($connection, '.');
2323

24-
// Create the database from "base.sql" script and run ALL existing scripts for up the database version;
24+
// Restore the database using the "base.sql" script and run ALL existing scripts for up the database version
25+
// and run the up() method to maintain the database updated;
2526
$migration->reset();
2627

2728
// Run ALL existing scripts for up the database version from the current version to the last version;

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "byjg/migration",
3-
"description": "A micro project in PHP for managing a set of database migrations using pure Sql.",
3+
"description": "A micro framework in PHP for managing a set of database migrations using pure Sql.",
44
"authors": [
55
{
66
"name": "jg",

example/base.sql renamed to example/mysql/base.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ create table users (
1313

1414
);
1515

16-
insert into users (name, createdate) value ('John Doe', '20160110');
17-
insert into users (name, createdate) value ('Jane Doe', '20151230');
16+
insert into users (name, createdate) values ('John Doe', '20160110');
17+
insert into users (name, createdate) values ('Jane Doe', '20151230');
1818

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

example/mysql/test_mysql.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
require "../../vendor/autoload.php";
4+
5+
/**
6+
* Make sure you have a database with the user 'migrateuser' and password 'migratepwd'
7+
*
8+
* This user need to have grant for DDL commands;
9+
*/
10+
11+
$connection = new \ByJG\AnyDataset\ConnectionManagement('mysql://migrateuser:migratepwd@localhost/migratedatabase');
12+
13+
$migration = new \ByJG\DbMigration\Migration($connection, '.');
14+
15+
$migration->prepareEnvironment();
16+
17+
$migration->reset();
18+

example/sqlite/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 INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT ,
11+
name varchar(50) NOT NULL,
12+
createdate VARCHAR(8)
13+
14+
);
15+
16+
insert into users (name, createdate) values ('John Doe 2', '20160110');
17+
insert into users (name, createdate) values ('Jane Doe 2', '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 AFTER `createdate`;
11+
12+
update users
13+
set createdate_old = DATE_FORMAT(createdate,'%Y%m%d');
14+
15+
ALTER TABLE `users`
16+
DROP COLUMN `createdate`;
17+
18+
ALTER TABLE `users`
19+
CHANGE COLUMN `createdate_old` `createdate` VARCHAR(8) NOT NULL ;
20+

0 commit comments

Comments
 (0)