PHP Classes

PHP Database Migration: Run database schema database migration operations

Recommend this page to a friend!
  Info   View files Example   View files View files (11)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2023-04-28 (10 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 62 All time: 10,378 This week: 79Up
Version License PHP version Categories
phpmigration 1.0Custom (specified...7Databases, PHP 7
Description 

Author

This package can run database schema database migration operations.

It provides a class that can generate SQL database queries that can be used to perform database schema migrations.

Currently, it can:

- Create a database with the given name

- Create a table with given column definitions

- Add a primary key field to a table

- Change the auto-increment field of a table

- Add a unique key column to a table

- Add a column to a table

- Alter the type of a table column

- Alter the name of a table

- Insert a row with given column values in a table

- Set the value of the column of all rows as a table

- Delete rows of a table that have a given column value

- Drop a given table

- Drop a table column

- Drop a database table

- Drop a database

- Create a table index on a given column

Picture of Faris AL-Otabi
  Performance   Level  
Name: Faris AL-Otabi <contact>
Classes: 13 packages by
Country: Saudi Arabia Saudi Arabia
Age: 26
All time rank: 303815 in Saudi Arabia Saudi Arabia
Week rank: 36 Up2 in Saudi Arabia Saudi Arabia Up
Innovation award
Innovation award
Nominee: 3x

Example

<?php

include_once __DIR__ . '/../src/Database.php';
include_once
__DIR__ . '/../src/Utils.php';
include_once
__DIR__ . '/../src/Migration.php';
include_once
__DIR__ . '/config.php';


use
Farisc0de\PhpMigration\Database;
use
Farisc0de\PhpMigration\Options\Options;
use
Farisc0de\PhpMigration\Options\Types;
use
Farisc0de\PhpMigration\Utils;
use
Farisc0de\PhpMigration\Migration;

$obj = new Migration(new Database($config), new Utils());

if (
$_SERVER['REQUEST_METHOD'] == 'POST') {
   
$obj->createTable(
       
"users",
        [
"id", Types::Integer(), Options::AutoIncrement(), Options::NotNull()],
        [
"username", Types::String(255), Options::NotNull()],
        [
"password", Types::String(255), Options::NotNull()],
        [
"email", Types::String(255), Options::NotNull()],
        [
"created_at", Types::TimeStamp(), Options::CurrentTimeStamp()],
        [
"updated_at", Types::TimeStamp(), Options::CurrentTimeStamp()]
    );

   
$obj->setPrimary("users", "id");

   
$obj->insertValue(
       
"users",
        [
           
"username" => "admin",
           
"password" => password_hash("admin", PASSWORD_DEFAULT),
           
"email" => "admin@gmail.com",
        ]
    );

   
$msg = "Database installed successfully!";
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Install Website</title>
</head>

<body>

    <form method="POST">
        <button type="submit">Install Database</button>
    </form>
</body>

</html>


Details

PhpMigration

Migration Library for PHP

How to use

include_once __DIR__ . '/src/Database.php';
include_once __DIR__ . '/src/Utils.php';
include_once __DIR__ . '/src/Migration.php';
include_once __DIR__ . '/config.php';

use Farisc0de\PhpMigration\Database;
use Farisc0de\PhpMigration\Options\Options;
use Farisc0de\PhpMigration\Options\Types;
use Farisc0de\PhpMigration\Utils;
use Farisc0de\PhpMigration\Migration;

$obj = new Migration(new Database($config), new Utils());

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

    // Create a new table
    $obj->createTable(
        "users",
        ["id", Types::Integer(), Options::AutoIncrement(), Options::NotNull()],
        ["username", Types::String(255), Options::NotNull()],
        ["password", Types::String(255), Options::NotNull()],
        ["email", Types::String(255), Options::NotNull()],
        ["created_at", Types::TimeStamp(), Options::CurrentTimeStamp()],
        ["updated_at", Types::TimeStamp(), Options::CurrentTimeStamp()]
    );

    // Create Primary Key
    $obj->setPrimary("users", "id");

    // Add a new record
    $obj->insertValue(
        "users",
        [
            "username" => "admin",
            "password" => password_hash("admin", PASSWORD_DEFAULT),
            "email" => "admin@gmail.com",
        ]
    );

    $msg = "Database installed successfully!";

Copyright

FarisCode


  Files folder image Files  
File Role Description
Files folder imageexample (2 files)
Files folder imagesrc (3 files, 1 directory)
Accessible without login Plain text file .phpcs.xml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  example  
File Role Description
  Accessible without login Plain text file config.php Aux. Auxiliary script
  Accessible without login Plain text file install.php Example Example script

  Files folder image Files  /  src  
File Role Description
Files folder imageOptions (2 files)
  Plain text file Database.php Class Class source
  Plain text file Migration.php Class Class source
  Plain text file Utils.php Class Class source

  Files folder image Files  /  src  /  Options  
File Role Description
  Plain text file Options.php Class Class source
  Plain text file Types.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:62
This week:0
All time:10,378
This week:79Up