{"id":15290854,"url":"https://github.com/envor/laravel-schema-macros","last_synced_at":"2025-04-13T10:43:01.183Z","repository":{"id":220709784,"uuid":"752373100","full_name":"envor/laravel-schema-macros","owner":"envor","description":"Some helpful (database level) macros for laravel's schema builder. Requires Laravel 11.","archived":false,"fork":false,"pushed_at":"2025-02-03T19:03:21.000Z","size":102,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-05T17:46:50.450Z","etag":null,"topics":["laravel","mysql","sqlite"],"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/envor.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","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},"funding":{"github":"envor"}},"created_at":"2024-02-03T18:35:07.000Z","updated_at":"2025-02-03T19:03:18.000Z","dependencies_parsed_at":"2024-03-05T22:28:19.896Z","dependency_job_id":"d84a96ca-9888-45a1-9652-0d2fade9780a","html_url":"https://github.com/envor/laravel-schema-macros","commit_stats":null,"previous_names":["envor/laravel-schema-macros"],"tags_count":11,"template":false,"template_full_name":"spatie/package-skeleton-laravel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envor%2Flaravel-schema-macros","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envor%2Flaravel-schema-macros/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envor%2Flaravel-schema-macros/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envor%2Flaravel-schema-macros/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/envor","download_url":"https://codeload.github.com/envor/laravel-schema-macros/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248701975,"owners_count":21148111,"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":["laravel","mysql","sqlite"],"created_at":"2024-09-30T16:09:45.976Z","updated_at":"2025-04-13T10:43:01.159Z","avatar_url":"https://github.com/envor.png","language":"PHP","funding_links":["https://github.com/sponsors/envor"],"categories":[],"sub_categories":[],"readme":"# laravel-schema-macros\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/envor/laravel-schema-macros.svg?style=flat-square)](https://packagist.org/packages/envor/laravel-schema-macros)\n[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/envor/laravel-schema-macros/run-tests.yml?branch=main\u0026label=tests\u0026style=flat-square)](https://github.com/envor/laravel-schema-macros/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/envor/laravel-schema-macros/fix-php-code-style-issues.yml?branch=main\u0026label=code%20style\u0026style=flat-square)](https://github.com/envor/laravel-schema-macros/actions?query=workflow%3A\"Fix+PHP+code+style+issues\"+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/envor/laravel-schema-macros.svg?style=flat-square)](https://packagist.org/packages/envor/laravel-schema-macros)\n\nSome helpful (database level) macros for laravel's schema builder. Requires Laravel 11.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require envor/laravel-schema-macros\n```\n\n## Usage\n\n[databaseExists()](#databaseexists)    \n[createDatabaseIfNotExists()](#createdatabaseifnotexists)   \n[trashDatabase()](#trashdatabase)    \n[emptyTrash()](#emptytrash)    \n[copyTable()](#copytable)\n\n\n### #`databaseExists()`\n\nThe `databaseExists()` method determines if the given database exists:\n\n```php\nuse Illuminate\\Support\\Facades\\Schema;\n\n$database = database_path('my-new-database.sqlite');\n\nSchema::connection('sqlite')-\u003edatabaseExists($database);\n\n// false\n\ntouch($database);\n\nSchema::connection('sqlite')-\u003edatabaseExists($database);\n\n// true\n\nSchema::connection('mysql')-\u003edatabaseExists('abc');\n\n// false\n\nSchema::connection('mysql')-\u003ecreateDatabase('abc');\n\n\nSchema::connection('mysql')-\u003edatabaseExists('abc');\n\n// true\n\n```\n\n### #`createDatabaseIfNotExists()`\n\nThe `createDatabaseIfNotExists()` method creates the given database if it does not exist:\n\n```php\nuse Illuminate\\Support\\Facades\\Schema;\n\n$default = database_path('database.sqlite');\n\ntouch($default);\n\nSchema::connection('sqlite')-\u003ecreateDatabaseIfNotExists($default);\n\n// false\n\nSchema::connection('sqlite')-\u003ecreateDatabaseIfNotExists(database_path('another_database'));\n\n// true\n\n\nSchema::connection('mysql')-\u003ecreateDatabaseIfNotExists('brand_new_database');\n\n// true\n\n```\n\nThe `createDatabaseIfNotExists()` method will also create `sqlite` database files recursively:\n\n```php\n\n$newFile = database_path('/new/directories/will/be/created/recursively/db.sqlite');\n\nSchema::connection('sqlite')-\u003ecreateDatabaseIfNotExists($newFile);\n\n// true\n```\n\n### #`trashDatabase()`\n\nThe `trashDatabase()` method will move the database to the `trash` and timestamp it:\n\n\u003e [!TIP]\n\u003e Sqlite databases are moved to a `.trash` directory on the local storage disk by default.    \n\u003e You may optionally pass the name of another storage disk as a second argument.\n\n```php\n$database = database_path('database.sqlite');\n\nSchema::connection('sqlite')-\u003etrashDatabase($database);\n\n// /home/forge/mysite.com/storage/app/.trash/2024-02-04_06-29-11_database.sqlite\n\nSchema::connection('mariadb')-\u003etrashDatabase('schema_demo');\n\n// trashed_2024-02-04_06-44-42_schema_demo\n```\n\n### #`emptyTrash()`\n\nThe `emptyTrash()` method will erase all `trashed` databases from disk which are reachable from the current connection:\n\n\u003e [!TIP]\n\u003e To only permanently erase databases trashed later than a given age and keep those which are newer,    \n\u003e you may pass the maximum age in days for the databases you want to keep. \n\n```php\n$database = database_path('database.sqlite');\n\nSchema::connection('sqlite')-\u003etrashDatabase($database);\n\n// /home/forge/mysite.com/storage/app/.trash/2024-02-04_06-29-11_database.sqlite\n\nSchema::connection('sqlite')-\u003eemptyTrash();\n\n// 1\n\nSchema::connection('mysql')-\u003etrashDatabase('schema_demo');\n\n// trashed_2024-02-04_06-44-42_schema_demo\n\nSchema::connection('mysql')-\u003eemptyTrash();\n\n// 1\n```\n\n### #`copyTable()`\n\nThe `copyTable()` method will copy the given table:\n\n\n```php\n$database = database_path('database.sqlite');\n\nSchema::connection('sqlite')-\u003ecopyTable('users');\n\n// users_copy\n\nSchema::connection('sqlite')-\u003ecopyTable('users', 'users_snapshot_1');\n\n// users_snapshot_1\n```\n\n## Testing\n\n\u003e [!IMPORTANT]  \n\u003e Tests use [spatie/docker](https://github.com/spatie/docker) for testing against various database servers.   \n\u003e Docker is required for running tests locally!\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [inmanturbo](https://github.com/envor)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenvor%2Flaravel-schema-macros","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fenvor%2Flaravel-schema-macros","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenvor%2Flaravel-schema-macros/lists"}