x7media/laravel-planetscale
最新稳定版本:v1.1.0
Composer 安装命令:
composer require x7media/laravel-planetscale
包简介
A package for managing Laravel database migrations with Planetscale databases.
README 文档
README
This package adds a php artisan pscale:migrate command to your Laravel app which can be used instead of the normal php artisan migrate command when using a PlanetScale database.
Installation
Via Composer
composer require x7media/laravel-planetscale
Configuration & Usage
-
Login to your PlanetScale account and get your Service Token and Service Token ID from the organaization settings. Also take a note of your organization name and production branch name as well for the next steps.
-
Add the following database level permissions to your Service Token for your app's database:
- create_branch - Create a database branch
- delete_branch - Delete a database branch
- connect_branch - Connect to, or create passwords and certificates for a database branch
- create_deploy_request - Create a database deploy request
- read_deploy_request - Read database deploy requests
-
From the database settings screen on PlanetScale, click the checkmark to enable the "Automatically copy migration data" settings. Select "Laravel" from the migration framework dropdown and it should fill it "migrations" for the migration table name. Then save the database settings. This will allow migration status to be synced across PlanetScale database branches.
-
Setup the following enviroment variables in your app with the appropriate values:
PLANETSCALE_ORGANIZATION=
PLANETSCALE_PRODUCTION_BRANCH=
PLANETSCALE_SERVICE_TOKEN_ID=
PLANETSCALE_SERVICE_TOKEN=
Additonally yuou'll need to make sure your database name is set under:
DB_DATABASE=
OR
Optionally you can publish the config:
php artisan vendor:publish --tag=laravel-planetscale-config
Then customize the values in the config. NOTE: If you take this approach we STRONGLY RECOMMEND that you still use enviroment variables or some other secrets storage at least for your service token and service token ID for security.
- Replase the
php artisan migratecommand in your deployment script or process with this:
php artisan pscale:migrate
NOTE: The pscale:migrate command supports the same options are Laravel's built in migration command, and will pass those options along to it when it gets to that step in the process.
FAQ's
Why is this necessary?
PlanetScale has a lot of advantages when using it as your application's production database. When safe migrations are enabled, you cannot run direct schema changes against your production database branch. Instead, you use the branching flow and Vitess's non-blocking schema migration tooling to run your database migrations safely.
This is accomplished by creating a branch of your schema, running your migrations against that branch and then opening a deploy request to have PlanetScale manage the schema migration for you in production.
This package uses PlanetScale's Public API to automate the process of creating a new development branch, connecting your app to the development branch, running your Laravel migrations on the development branch, merging that back into your production branch, and deleting the development branch. You end up with the best of both, the migration flow you are used to while also taking advantage of PlanetScale's schema migration tools.
Are there any notable limitations to PlanetScale's branching?
Yes, there is one BIG caveat. That is branching and merging is for schema only. So you will need to separate your schema migrations from your data migrations. Use this to run your schema migrations and run your data migrations separately against your production branch.
An alternative method is to disable safe migrations on your production branch, then you can mix schema and data migrations. Then when that is finished re-enable safe migrations to return to using the safe schema change tools.
Change log
Please see the changelog for more information on what has changed recently.
Testing
$ composer test
Contributing
Please see the contributing guidelines.
Note: X7 Media is no longer using PlanetScale for any internal or client databases anymore, as such we will not be making any changes to or activly supporting this package. However, since some of you are still relying on this in production, we will occassionaly review PR's to merge as necessary to add support for future versions of Laravel or to add features or bug fixes.
Security
If you discover any security related issues, please email info@x7media.com instead of using the issue tracker.
Credits
License
MIT. Please see the license file for more information.
x7media/laravel-planetscale 适用场景与选型建议
x7media/laravel-planetscale 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.55k 次下载、GitHub Stars 达 58, 最近一次更新时间为 2023 年 03 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「LaravelPlanetscale」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 x7media/laravel-planetscale 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 x7media/laravel-planetscale 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 x7media/laravel-planetscale 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Alfabank REST API integration
Laravel package for Accurate Online API integration.
Shared RCX Laravel DataTables UI and configuration helpers.
Boot a Laravel project on any machine with one command: app:serve installs missing tools (PHP, Node, Composer, Herd, Docker), creates .env, sets up the database, runs migrations, builds assets, starts a queue worker and serves via Herd, Sail or artisan serve; app:down cleanly stops everything it sta
Branded, diagnostic error pages (500, 403, 404, 419, 503) for Filament — native Filament UI, dark mode and translations out of the box.
Turn any PDF into a Pingen-ready A4 letter (generated address cover page + A4 normalisation + safe margins) and send it through the Pingen print & mail API. Laravel-first.
统计信息
- 总下载量: 1.55k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 58
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-23