{"id":13560155,"url":"https://github.com/rougin/refinery","last_synced_at":"2025-07-26T00:34:18.186Z","repository":{"id":33360982,"uuid":"37005817","full_name":"rougin/refinery","owner":"rougin","description":"\"Ready-to-eat\" Codeigniter 3 migrations.","archived":false,"fork":false,"pushed_at":"2024-10-21T16:15:59.000Z","size":169,"stargazers_count":18,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-30T12:16:56.130Z","etag":null,"topics":["codeigniter-library","database-migrations","generator","php-library","refinery"],"latest_commit_sha":null,"homepage":"https://roug.in/refinery/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rougin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-07T05:31:30.000Z","updated_at":"2024-12-30T13:34:19.000Z","dependencies_parsed_at":"2022-09-03T23:32:01.840Z","dependency_job_id":null,"html_url":"https://github.com/rougin/refinery","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/rougin/refinery","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rougin%2Frefinery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rougin%2Frefinery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rougin%2Frefinery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rougin%2Frefinery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rougin","download_url":"https://codeload.github.com/rougin/refinery/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rougin%2Frefinery/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267093849,"owners_count":24034952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-25T02:00:09.625Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codeigniter-library","database-migrations","generator","php-library","refinery"],"created_at":"2024-08-01T13:00:38.462Z","updated_at":"2025-07-26T00:34:18.155Z","avatar_url":"https://github.com/rougin.png","language":"PHP","readme":"# Refinery\n\n[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Software License][ico-license]][link-license]\n[![Build Status][ico-build]][link-build]\n[![Coverage Status][ico-coverage]][link-coverage]\n[![Total Downloads][ico-downloads]][link-downloads]\n\n`Refinery` is a console-based package of [Migrations Class](https://www.codeigniter.com/userguide3/libraries/migration.html) for the [Codeigniter 3](https://codeigniter.com/userguide3). It uses the [Describe](https://roug.in/describe/) package for retrieving the database tables for creating database migrations.\n\n## Installation\n\nFrom an existing `Codeigniter 3` project, the `Refinery` package can be installed through [Composer](https://getcomposer.org/):\n\n``` bash\n$ composer require rougin/refinery --dev\n```\n\n``` json\n// ciacme/composer.json\n\n{\n  // ...\n\n  \"require-dev\":\n  {\n    \"mikey179/vfsstream\": \"1.6.*\",\n    \"phpunit/phpunit\": \"4.* || 5.* || 9.*\",\n    \"rougin/refinery\": \"~0.4\"\n  }\n}\n```\n\nThen configure the project's database connectivity settings:\n\n``` php\n// ciacme/application/config/database.php\n\n// ...\n\n$db['default'] = array(\n    'dsn'   =\u003e '',\n    'hostname' =\u003e 'localhost',\n    'username' =\u003e '',\n    'password' =\u003e '',\n    'database' =\u003e '',\n    'dbdriver' =\u003e 'mysqli',\n    \n    // ...\n);\n```\n\n\u003e [!NOTE]\n\u003e Although using database connection is not required in using `Refinery`, this is only applicable when creating migration files based on an existing database. Please see [Creating from database](https://github.com/rougin/refinery?tab=readme-ov-file#creating-from-database) below for its usage.\n\n## Basic Usage\n\n### Creating migration files\n\nTo create a new database migration, kindly run the `create` command:\n\n``` bash\n$ vendor/bin/refinery create create_users_table\n[PASS] \"20241019044009_create_users_table.php\" successfully created!\n```\n\n``` php\n// ciacme/application/migrations/20241019044009_create_users_table.php\n\nuse Rougin\\Refinery\\Migration;\n\nclass Migration_create_users_table extends Migration\n{\n    /**\n     * @return void\n     */\n    public function up()\n    {\n        $data = array('id' =\u003e array());\n        $data['id']['type'] = 'integer';\n        $data['id']['auto_increment'] = true;\n        $data['id']['constraint'] = 10;\n        $this-\u003edbforge-\u003eadd_field($data);\n        $this-\u003edbforge-\u003eadd_key('id', true);\n\n        $this-\u003edbforge-\u003ecreate_table('users');\n    }\n\n    /**\n     * @return void\n     */\n    public function down()\n    {\n        $this-\u003edbforge-\u003edrop_table('users');\n    }\n}\n```\n\n\u003e [!NOTE]\n\u003e * The `Migration` class under `Refinery` is directly extended on `CI_Migration`.\n\u003e * The created file will be in `migrations` directory under `application`. If it does not exists, `Refinery` will automatically create the specified directory.\n\nWhen creating database migrations, `Refinery` will try to guess the expected output of `up` and `down` methods of a migration file based on its name (e.g., `add_name_in_users_table`):\n\n```bash\n$ vendor/bin/refinery create add_name_in_users_table\n\"20241019044035_add_name_in_users_table.php\" has been created.\n```\n\n``` php\n// ciacme/application/migrations/20241019044035_add_name_in_users_table.php\n\nuse Rougin\\Refinery\\Migration;\n\nclass Migration_add_name_in_users_table extends Migration\n{\n    /**\n     * @return void\n     */\n    public function up()\n    {\n        $data = array('name' =\u003e array());\n        $data['name']['type'] = 'varchar';\n        $data['name']['auto_increment'] = false;\n        $data['name']['constraint'] = 100;\n        $data['name']['default'] = null;\n        $data['name']['null'] = true;\n        $data['name']['unsigned'] = false;\n        $this-\u003edbforge-\u003eadd_column('users', $data);\n    }\n\n    /**\n     * @return void\n     */\n    public function down()\n    {\n        $this-\u003edbforge-\u003edrop_column('users', 'name');\n    }\n}\n```\n\nPlease see the accepted keywords below when creating database migration files:\n\n| Keyword  | Description                                    | Example                      |\n|----------|------------------------------------------------|------------------------------|\n| `add`    | Adds new column to a table                     | `add_name_in_users_table`    |\n| `create` | Creates new table with `id` as the primary key | `create_users_table`         |\n| `delete` | Deletes a column from a table                  | `delete_name_in_users_table` |\n| `modify` | Updates a column of a table                    | `modify_name_in_users_table` |\n\n### Running the migrations\n\nKindly use the `migrate` command to use the files for database migrations:\n\n``` bash\n$ vendor/bin/refinery migrate\n[INFO] Migrating \"create_users_table\"...\n[PASS] \"create_users_table\" migrated!\n[INFO] Migrating \"add_name_in_users_table\"...\n[PASS] \"add_name_in_users_table\" migrated!\n```\n\nWhen running this command, the target timestamp (`--target`) will always be the latest file in the `migrations` directory if not specified (e.g., `add_name_in_users_table`). Use the `--target` option to migrate to a specific version:\n\n``` bash\n$ vendor/bin/refinery migrate --target=20241019044009\n[INFO] Migrating \"create_users_table\"...\n[PASS] \"create_users_table\" migrated!\n```\n\nTo rollback a database, kindly use the `rollback` command:\n\n``` bash\n$ vendor/bin/refinery rollback\n[INFO] Rolling back \"add_name_in_users_table\"...\n[PASS] \"add_name_in_users_table\" rolled back!\n```\n\n\u003e [!NOTE]\n\u003e Without a `--target` option, the `rollback` will only revert to its previous version (e.g., `create_users_table`).\n\nTo reset back the database schema to version `0`, the `reset` command can be used:\n\n``` bash\n$ vendor/bin/refinery migrate\n[INFO] Migrating \"add_name_in_users_table\"...\n[PASS] \"add_name_in_users_table\" migrated!\n\n$ vendor/bin/refinery reset\n[INFO] Rolling back \"add_name_in_users_table\"...\n[PASS] \"add_name_in_users_table\" rolled back!\n[INFO] Rolling back \"create_users_table\"...\n[PASS] \"create_users_table\" rolled back!\n```\n\n## Creating from database\n\n`Refinery` also allows to create a database migration based on the existing database table. Prior in creating its database migration, kindly ensure that the specified table already exists in the database schema:\n\n``` sql\nCREATE TABLE IF NOT EXISTS `users` (\n  `id` int NOT NULL AUTO_INCREMENT,\n  `name` varchar(100) DEFAULT NULL,\n  PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;\n```\n\nAfter checking the database table exists, run the same `create` command with the `--from-database` option:\n\n``` bash\n$ vendor/bin/refinery create create_users_table --from-database\n\"20241019044729_create_users_table.php\" has been created.\n```\n\n``` php\n// ciacme/application/migrations/20241019044729_create_users_table.php\n\nuse Rougin\\Refinery\\Migration;\n\nclass Migration_create_users_table extends Migration\n{\n    /**\n     * @return void\n     */\n    public function up()\n    {\n        $data = array('id' =\u003e array());\n        $data['id']['type'] = 'integer';\n        $data['id']['auto_increment'] = true;\n        $data['id']['constraint'] = 10;\n        $this-\u003edbforge-\u003eadd_field($data);\n        $this-\u003edbforge-\u003eadd_key('id', true);\n\n        $data = array('name' =\u003e array());\n        $data['name']['type'] = 'varchar';\n        $data['name']['auto_increment'] = false;\n        $data['name']['constraint'] = 100;\n        $data['name']['default'] = null;\n        $data['name']['null'] = true;\n        $data['name']['unsigned'] = false;\n        $this-\u003edbforge-\u003eadd_field($data);\n\n        $this-\u003edbforge-\u003ecreate_table('users');\n    }\n\n    /**\n     * @return void\n     */\n    public function down()\n    {\n        $this-\u003edbforge-\u003edrop_table('users');\n    }\n}\n```\n\n\u003e [!NOTE]\n\u003e The `--from-database` option only exists when creating files under the `create_*_table` prefix.\n\n## Creating sequential migrations\n\nBy default, `Refinery` uses a timestamp prefix as its numbering style when creating migration files. To change it to a sequential numbering, kindly update the value of `migration_type` in the `config/migration.php` to `sequential`:\n\n``` php\n// ciacme/application/config/migration.php\n\n/*\n|--------------------------------------------------------------------------\n| Migration Type\n|--------------------------------------------------------------------------\n|\n| Migration file names may be based on a sequential identifier or on\n| a timestamp. Options are:\n|\n|   'sequential' = Sequential migration naming (001_add_blog.php)\n|   'timestamp'  = Timestamp migration naming (20121031104401_add_blog.php)\n|                  Use timestamp format YYYYMMDDHHIISS.\n|\n| Note: If this configuration value is missing the Migration library\n|       defaults to 'sequential' for backward compatibility with CI2.\n|\n*/\n$config['migration_type'] = 'sequential';\n```\n\nThen run the `create` command to generate a migration file in sequential migration:\n\n``` bash\n$ vendor/bin/refinery create create_users_table\n[PASS] \"001_create_users_table.php\" successfully created!\n```\n\nAlternatively, the `--sequential` option can also be added in the `create` command to update the said configuration:\n\n``` bash\n$ vendor/bin/refinery create add_name_in_users_table --sequential\n[PASS] \"002_add_name_in_users_table.php\" successfully created!\n```\n\n\u003e [!NOTE]\n\u003e When using the `--sequential` option, the `migration_type` in the `config/migration.php` is also set as `sequential`.\n\n## Using `refinery.yml`\n\n`Refinery` currently works out of the box after the configuration based on `Installation`. However, using a `refinery.yml` can be used for complex setups like specifying the new application path:\n\n``` yaml\n# refinery.yml\n\napp_path: %%CURRENT_DIRECTORY%%\n```\n\nTo create a `refinery.yml`, simply run the `initialize` command:\n\n``` bash\n$ vendor/bin/refinery initialize\n[PASS] \"refinery.yml\" added successfully!\n```\n\n\u003e [!NOTE]\n\u003e `%%CURRENT_DIRECTORY%%` is a placeholder variable which is the current directory of `refinery.yml`.\n\n### `app_path`\n\nThis property specifies the `application` directory. It may updated to any directory (e.g., `ciacme/application`, `ciacme/config`, etc.) as long it can detect the `config/config.php` file from the defined directory:\n\n``` yaml\n# refinery.yml\n\napp_path: %%CURRENT_DIRECTORY%%/Sample\n\n# ...\n```\n\n\u003e [!NOTE]\n\u003e `Refinery` will try to check the path specified in `app_path` if it is a valid `Codeigniter 3` project. Then it will perform another check if the `application` directory exists or if the `config` directory can be accessed directly from the directory defined in `app_path`.\n\n## Changelog\n\nPlease see [CHANGELOG][link-changelog] for more information what has changed recently.\n\n## Testing\n\n``` bash\n$ composer test\n```\n\n## Credits\n\n- [All contributors][link-contributors]\n\n## License\n\nThe MIT License (MIT). Please see [LICENSE][link-license] for more information.\n\n[ico-build]: https://img.shields.io/github/actions/workflow/status/rougin/refinery/build.yml?style=flat-square\n[ico-coverage]: https://img.shields.io/codecov/c/github/rougin/refinery?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/rougin/refinery.svg?style=flat-square\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\n[ico-version]: https://img.shields.io/packagist/v/rougin/refinery.svg?style=flat-square\n\n[link-build]: https://github.com/rougin/refinery/actions\n[link-changelog]: https://github.com/rougin/refinery/blob/master/CHANGELOG.md\n[link-contributors]: https://github.com/rougin/refinery/contributors\n[link-coverage]: https://app.codecov.io/gh/rougin/refinery\n[link-downloads]: https://packagist.org/packages/rougin/refinery\n[link-license]: https://github.com/rougin/refinery/blob/master/LICENSE.md\n[link-packagist]: https://packagist.org/packages/rougin/refinery\n[link-upgrading]: https://github.com/rougin/refinery/blob/master/UPGRADING.md","funding_links":[],"categories":["Libraries"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frougin%2Frefinery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frougin%2Frefinery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frougin%2Frefinery/lists"}