{"id":16467169,"url":"https://github.com/spresnac/laravel-artisan-database-helper","last_synced_at":"2025-03-21T06:32:08.326Z","repository":{"id":34632146,"uuid":"180951498","full_name":"spresnac/laravel-artisan-database-helper","owner":"spresnac","description":"Some usefull helper to handle database backup \u0026 restores","archived":false,"fork":false,"pushed_at":"2024-04-08T13:46:22.000Z","size":38,"stargazers_count":8,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-01T03:42:19.132Z","etag":null,"topics":["backups","database","hacktoberfest","laravel","restore"],"latest_commit_sha":null,"homepage":"https://spresnac.github.io/laravel-artisan-database-helper","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/spresnac.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["spresnac"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"custom":["https://www.paypal.me/paladin","https://www.buymeacoffee.com/spresnac"]}},"created_at":"2019-04-12T07:11:20.000Z","updated_at":"2024-01-21T14:05:54.000Z","dependencies_parsed_at":"2024-04-08T14:48:35.397Z","dependency_job_id":"a5446f34-1200-412f-bfb6-5fe706a0c1d6","html_url":"https://github.com/spresnac/laravel-artisan-database-helper","commit_stats":{"total_commits":22,"total_committers":6,"mean_commits":"3.6666666666666665","dds":0.6363636363636364,"last_synced_commit":"84309e583f38f91a9afa3b8a6446edfd5e212e34"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spresnac%2Flaravel-artisan-database-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spresnac%2Flaravel-artisan-database-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spresnac%2Flaravel-artisan-database-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spresnac%2Flaravel-artisan-database-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spresnac","download_url":"https://codeload.github.com/spresnac/laravel-artisan-database-helper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244117640,"owners_count":20400743,"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":["backups","database","hacktoberfest","laravel","restore"],"created_at":"2024-10-11T11:46:22.257Z","updated_at":"2025-03-21T06:32:07.870Z","avatar_url":"https://github.com/spresnac.png","language":"PHP","funding_links":["https://github.com/sponsors/spresnac","https://www.paypal.me/paladin","https://www.buymeacoffee.com/spresnac"],"categories":[],"sub_categories":[],"readme":"# Laravel: Usefull Database helper\nThis package will provide you some helper for\n* Backup your database\n* Restore this backups\n* Drop all tables from a schema\n\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=for-the-badge\u0026logo=github)](LICENSE)\n[![PHP from Packagist](https://img.shields.io/packagist/php-v/spresnac/laravel-artisan-database-helper.svg?style=for-the-badge\u0026logo=php)](https://packagist.org/packages/spresnac/laravel-artisan-database-helper)\n[![Laravel Version](https://img.shields.io/badge/Laravel-%5E7%20|%20%5E8-important?style=for-the-badge\u0026logo=laravel)](https://laravel.com)\n\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)\n![Downloads](https://img.shields.io/packagist/dt/spresnac/laravel-artisan-database-helper.svg)\n\n# Installation\nFirst things first, so require the package:\n\n```\ncomposer require spresnac/laravel-artisan-database-helper\n```\n\nThat's all, you are ready to go now 😁\n\n# Usage\n## BackupDatabase\n### The 90% way\nTo backup your database, open up your console and type\n```\nphp artisan db:backup\n```\nand in most cases, you are done. You will find your backup in\n```\nstorage/app/backups\n```\nOk, with \"most cases\", i meant this:\n* your are using only one database\n* you want to backup everthing\n* you have set the path, so a call to `mysqldump` will work\n\nIf you have all of this, you are ready and good to go.\n\n### The other 10% ;)\nLet's say, you are not one of the 90%, perhaps because\n* you use more than database connection\n* you want to export only the structure\n* you have a `mysqldump` but it is not in your path\n\nI got you covered (like i had this problems too), so you can configure the way the backup is created with this options:\n\n#### Define the connection to be backuped\nWith the first parameter, you can define the connection that is beeing used. You can set the connection within your ``config/database.php``\n```\nphp artisan db:backup \u003cconnection_name\u003e\n```\n\n#### Define the path to your mysqldump binary\nReal world example needed for this option? Ok, short-format: I am using windows ... no more words needed ;)\n\nThe second parameter can be used to define a path that points to your ``mysqldump`` binary\n```\nphp artisan db:backup \u003cconnection_name\u003e \u003cpath_to_binary\u003e\n```\nHint: When you only need the path to be set, but use your default connection, use ``mysql`` as connection name:\n```\nphp artisan db:backup mysql \u003cpath_to_binary\u003e\n```\n\n#### Export only the structure\nUse the ``-S`` option to export only the structure of your database:\n```\nphp artisan db:backup -S\n```\n\n#### Export without options\nThis is one option that i personally need a lot. For details why, look in the 'How i use it for testing my apps' section.\n```\nphp artisan db:backup -O\n```\n\n#### Export with a date prefix\nYou can export with the actual date and time as a prefix to the export file name. It will look like `20190425153412_yourConnection.sql`. The date format is `YmdHis`.\n```\nphp artisan db:backup -D\n```\n\n#### Glueing it all together\nAll glued together (export a specific database, with a custom path, structure only with no options in it):\n```\nphp artisan db:backup foobardb d:/www/mysql/bin -SO\n```\n\n### Where is my backup?\nYou will find your backup in\n```\nstorage/app/backups/\u003cconnection\u003e_backup.sql\n```\nIf you set the `-S` option, it looks like this\n```\nstorage/app/backups/\u003cconnection\u003e_structure.sql\n```\nWhen used with `-D` it will look like\n```\nstorage/app/backups/\u003cYmd_\u003e\u003cconnection\u003e_backup.sql\n```\n\n## DropTable\nWith this command you can quickly \"emtpy\" a given database schema without deleting the schema itself. For short, all tables in the given connection will be deleted.\n```\nphp artisan db:drop-tables \u003cconnection\u003e\n```\n\nIf you want to use this in an automatic way, you can use the `--force` option to delete the tables without confirmation (you be warned!).\n```\nphp artisan db:drop-tables \u003cconnection\u003e --force\n```\n\n## RestoreDatabase\nTo restore a backup, simply use\n```\nphp artisan db:restore\n```\nYou can provide more options in case you need one of this:\n\n```\nphp artisan db:restore \u003cbackup_name\u003e \u003cconnection\u003e \u003cpath_to_mysql\u003e \u003cport\u003e\n```\n\nAll this options are similar to the ones described in `db:backup`, so you are able to seamlessly restore a backuped database.\n\n# How i use it for testing or bugfixing my apps\nWhen having complex setups for very complex bugs it may happen that you are in need of some very specific database entries you do not want to reproduce all the time.\n\nIn this case, i do use this package as a helper for me to bugfix faster.\n1. Create a backup from the database with `db:backup`.\n2. Rename this backup like the bugticket i have.\n3. Setup my unit-test for this bug in a special group, that is not executed by default.\n4. In my testscript, i do define a testschema.\n5. Before running my tests, execute `db:drop-tables` on the testschema.\n6. Right after that, execute `db:restore \u003cticketnumber\u003e`.\n\nWith this, everytime i execute my tests for bugfing my database is reset to this very specific point where i can reproduce the bug and fix it fast.\n\n# Finally\n... have fun 😉 and be productive with it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspresnac%2Flaravel-artisan-database-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspresnac%2Flaravel-artisan-database-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspresnac%2Flaravel-artisan-database-helper/lists"}