{"id":21726541,"url":"https://github.com/virdiggg/seeder-ci3","last_synced_at":"2025-07-20T08:05:04.555Z","repository":{"id":192972592,"uuid":"687851709","full_name":"virdiggg/seeder-ci3","owner":"virdiggg","description":"Migration and Seeder from Existing Database for CodeIgniter 3","archived":false,"fork":false,"pushed_at":"2025-05-24T04:12:00.000Z","size":99,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-27T17:23:51.928Z","etag":null,"topics":["codeigniter","codeigniter-library","codeigniter3","migrations","php","seeder-generator"],"latest_commit_sha":null,"homepage":"","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/virdiggg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-09-06T06:24:59.000Z","updated_at":"2025-02-03T02:49:26.000Z","dependencies_parsed_at":"2024-08-19T04:24:11.226Z","dependency_job_id":"58a86cbb-8874-4a7a-820a-8a773c962b67","html_url":"https://github.com/virdiggg/seeder-ci3","commit_stats":null,"previous_names":["virdiggg/seeder-ci3"],"tags_count":27,"template":false,"template_full_name":null,"purl":"pkg:github/virdiggg/seeder-ci3","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virdiggg%2Fseeder-ci3","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virdiggg%2Fseeder-ci3/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virdiggg%2Fseeder-ci3/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virdiggg%2Fseeder-ci3/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/virdiggg","download_url":"https://codeload.github.com/virdiggg/seeder-ci3/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virdiggg%2Fseeder-ci3/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266087790,"owners_count":23874519,"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","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","codeigniter-library","codeigniter3","migrations","php","seeder-generator"],"created_at":"2024-11-26T03:36:49.067Z","updated_at":"2025-07-20T08:05:04.507Z","avatar_url":"https://github.com/virdiggg.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A Simple Library Seeder from Existing Database for CodeIgniter 3\n\n\u003cimg src=\"https://img.shields.io/packagist/php-v/virdiggg/seeder-ci3\" /\u003e \u003cimg src=\"https://img.shields.io/badge/codeigniter--version-3-green\" /\u003e \u003cimg src=\"https://img.shields.io/github/license/virdiggg/seeder-ci3\" /\u003e\n\n## Inspired from Laravel Artisan and [orangehill/iseed](https://github.com/orangehill/iseed) for Laravel.\n\n### UPGRADE FROM 1.x to 2.x\n- Modify your controller that host all the function from this library to something like this:\n```php\n\u003c?php defined('BASEPATH') or exit('No direct script access allowed');\n\nuse Virdiggg\\SeederCi3\\MY_AppController;\nuse Virdiggg\\SeederCi3\\Config\\MigrationConfig;\n\nclass App extends MY_AppController\n{\n    /**\n     * Hooks for migrate() function.\n     * If you want to run a callback after migrating a table,\n     * ex.: create a log file after migration or run grant privileges query for a role.\n     * \n     * @return bool $this\n     */\n    private $migrateCalled = false;\n    public function __construct()\n    {\n        /**\n         * You can pass argument here\n         * @param string $migrationType  Type of migration, sequential or timestamp. Default to 'sequential'.\n         * @param array  $dateTime       List of additional table rows with datetime data type.\n         *                               Default to \"['created_at', 'updated_at', 'approved_at', 'deleted_at']\".\n         * @param string $dbConn         Name of database connection. Default to 'default'.\n         * @param string $migrationPath  Path of migration file. Default to 'ROOT/application/migrations'.\n         * @param array  $constructors   List of additional function to be called in constructor. Default to [].\n         * */\n        $config = new MigrationConfig();\n\n        parent::__construct($config);\n    }\n\n    public function migrate()\n    {\n        parent::migrate();\n        $this-\u003emigrateCalled = true;\n    }\n\n    // If you don't wish to have rollback function\n    public function rollback() {\n        return;\n    }\n\n    // The rest of your code\n\n    public function __destruct()\n    {\n        if ($this-\u003emigrateCalled) {\n            // $this-\u003edb-\u003equery(\"GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO myrole\");\n            // $this-\u003edb-\u003equery(\"GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO myrole\");\n            // log_message('error', 'PREVILEGES GRANTED');\n        }\n    }\n}\n```\n\n### HOW TO USE\n- Install this library with composer\n```bash\ncomposer require virdiggg/seeder-ci3 --dev\n```\n- Create a controller to host all the function from this library. Example is `application/controller/App.php`\n```php\n\u003c?php defined('BASEPATH') or exit('No direct script access allowed');\n\nuse Virdiggg\\SeederCi3\\MY_AppController;\nuse Virdiggg\\SeederCi3\\Config\\MigrationConfig;\n\nclass App extends MY_AppController\n{\n    /**\n     * Hooks for migrate() function.\n     * If you want to run a callback after migrating a table,\n     * ex.: create a log file after migration or run grant privileges query for a role.\n     * \n     * @return bool $this\n     */\n    private $migrateCalled = false;\n    public function __construct()\n    {\n        /**\n         * You can pass argument here\n         * @param string $migrationType  Type of migration, sequential or timestamp. Default to 'sequential'.\n         * @param array  $dateTime       List of additional table rows with datetime data type.\n         *                               Default to \"['created_at', 'updated_at', 'approved_at', 'deleted_at']\".\n         * @param string $dbConn         Name of database connection. Default to 'default'.\n         * @param string $migrationPath  Path of migration file. Default to 'ROOT/application/migrations'.\n         * @param array  $constructors   List of additional function to be called in constructor. Default to [].\n         * */\n        $config = new MigrationConfig();\n        // $config-\u003edbConn = 'default2';\n        $config-\u003emigrationType = 'timestamp';\n        // Append 'create_date', 'change_date', 'last_access' to the list of $dateTime\n        $config-\u003edateTime = ['create_date', 'change_date', 'last_access'];\n        $config-\u003econstructors = [\n            'controller' =\u003e [\n                '$this-\u003eauthenticated-\u003eisAuthenticated();',\n            ],\n            'model' =\u003e [\n                '$this-\u003eload-\u003ehelper(\"string\");',\n            ],\n            'seed' =\u003e [\n                '$this-\u003eload-\u003ehelper(\"string\");',\n            ],\n            'migration' =\u003e [\n                '$this-\u003eload-\u003ehelper(\"string\");',\n            ],\n        ];\n\n        parent::__construct($config);\n    }\n\n    public function migrate()\n    {\n        parent::migrate();\n        $this-\u003emigrateCalled = true;\n    }\n\n    // If you don't wish to have rollback function\n    public function rollback() {\n        return;\n    }\n\n    public function __destruct()\n    {\n        if ($this-\u003emigrateCalled) {\n            // $this-\u003edb-\u003equery(\"GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO myrole\");\n            // $this-\u003edb-\u003equery(\"GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO myrole\");\n            // log_message('error', 'PREVILEGES GRANTED');\n        }\n    }\n}\n```\n\n#### Help options: `php index.php \u003cyour controller name\u003e help`.\n```bash\ncd c:/xampp/htdocs/codeigniter \u0026\u0026 php index.php app help\n```\n#### How to run migration: `php index.php \u003cyour controller name\u003e migrate`.\n```bash\ncd c:/xampp/htdocs/codeigniter \u0026\u0026 php index.php app migrate\n```\n#### How to run rollback migration: `php index.php \u003cyour controller name\u003e rollback [--args]`.\n- Add `--to=1` to run migration number \u003cargs\u003e. Optional. Default is the latest number in your database min 1.\n```bash\ncd c:/xampp/htdocs/codeigniter \u0026\u0026 php index.php app rollback --to=1\n```\n#### How to create Seeder file: `php index.php \u003cyour controller name\u003e \u003cyour function name\u003e seed [--args]`.\n- Add `--limit=5` to limit the query result. Optional.\n```bash\ncd c:/xampp/htdocs/codeigniter \u0026\u0026 php index.php app seed users --limit=10\n```\n#### How to create Migration file: `php index.php \u003cyour controller name\u003e \u003cyour function name\u003e migration [--args]`.\n- Add `--soft-delete` to add soft delete parameter. Optional.\n```bash\ncd c:/xampp/htdocs/codeigniter \u0026\u0026 php index.php app migration users --soft-delete\n```\n#### How to create Controller file: `php index.php \u003cyour controller name\u003e controller \u003cfilename\u003e [--args]`.\n- Add `--r` to generate resources. Optional.\n```bash\ncd c:/xampp/htdocs/codeigniter \u0026\u0026 php index.php app controller Admin/Dashboard/Table --r\n```\n#### How to create Model file: `php index.php \u003cyour controller name\u003e model \u003cfilename\u003e [--args]`.\n- Add `--r` to generate resources. Optional.\nWhen using [--r], you will have a function to create or update a row (storeOrUpdate), please read the comment before you decide to use them. Example:\n```php\n// In this code, we will insert a new user $param,\n// only if there is no user with $conditions in the table\n// So, insert into table when there is no row with name = 'myname'\n// and username = 'myusername'\n$param = [\n    'name' =\u003e 'myname',\n    'username' =\u003e 'myusername',\n    'password' =\u003e password_hash('password1', PASSWORD_BCRYPT),\n    'created_at' =\u003e date('Y-m-d H:i:s'),\n    'updated_at' =\u003e date('Y-m-d H:i:s'),\n    'created_by' =\u003e 'admin',\n    'updated_by' =\u003e 'admin',\n];\n$conditions = [\n    'name' =\u003e 'myname',\n    'username' =\u003e 'myusername',\n];\n$res = $this-\u003emymodel-\u003estoreOrUpdate($param, $conditions);\n// In this code, we will insert a new user $param,\n// but since we don't pass the second parameters,\n// then we will use the first parameters as $conditions\n// but only if they're not in list of $this-\u003eexceptions\n// So, insert into table when there is no row with name = 'myname'\n// and username = 'myusername' and password = hashed string, etc...\n$param = [\n    'name' =\u003e 'myname',\n    'username' =\u003e 'myusername',\n    'password' =\u003e password_hash('password1', PASSWORD_BCRYPT),\n    'created_at' =\u003e date('Y-m-d H:i:s'),\n    'updated_at' =\u003e date('Y-m-d H:i:s'),\n    'created_by' =\u003e 'admin',\n    'updated_by' =\u003e 'admin',\n];\n$res = $this-\u003emymodel-\u003estoreOrUpdate($param);\n```\n- Add `--c` to generate its controller file as well. Optional.\n- Add `--m` to generate its migration file as well. Optional.\n- Add `--soft-delete` if your model using soft delete. Optional. When used along with `--m`, migration will have soft delete fields too.\n```bash\ncd c:/xampp/htdocs/codeigniter \u0026\u0026 php index.php app model Admin/Users --r --c --m --soft-delete\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvirdiggg%2Fseeder-ci3","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvirdiggg%2Fseeder-ci3","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvirdiggg%2Fseeder-ci3/lists"}