当前位置: 首页 > 软件库 > 数据库相关 > >

laravel-db-snapshots

Quickly dump and load databases
授权协议 MIT License
开发语言 C/C++
所属分类 数据库相关
软件类型 开源软件
地区 不详
投 递 者 微生新翰
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Quickly dump and load databases

This package provides Artisan commands to quickly dump and load databases in a Laravel application.

# Create a dump
php artisan snapshot:create my-first-dump

# Make some changes to your db
# ...

# Create another dump
php artisan snapshot:create my-second-dump

# Load up the first dump
php artisan snapshot:load my-first-dump

# Load up the latest dump
php artisan snapshot:load --latest

# List all snapshots
php artisan snapshot:list

# Remove old snapshots. Keeping only the most recent
php artisan snapshot:cleanup --keep=2

This package supports MySQL, PostgreSQL and SQLite.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

For PHP 7.x and/or Laravel 6.x, use v1.x of this package.

You can install the package via Composer:

composer require spatie/laravel-db-snapshots

You should add a disk named snapshots to app/config/filesystems.php on which the snapshots will be saved. This would be a typical configuration:

// ...
'disks' => [
    // ...
    'snapshots' => [
        'driver' => 'local',
        'root' => database_path('snapshots'),
    ],
// ...    

Optionally, you may publish the configuration file with:

php artisan vendor:publish --provider="Spatie\DbSnapshots\DbSnapshotsServiceProvider" --tag="config"

This is the content of the published file:

return [

    /**
     * The name of the disk on which the snapshots are stored.
     */
    'disk' => 'snapshots',

    /**
     * The connection to be used to create snapshots. Set this to null
     * to use the default configured in `config/database.php`
     */
    'default_connection' => null,

    /**
     * The directory where temporary files will be stored.
     */
    'temporary_directory_path' => storage_path('app/laravel-db-snapshots/temp'),

    /*
     * Create dump files that are gzipped
     */
    'compress' => false,
];

Usage

To create a snapshot (which is just a dump from the database) run:

php artisan snapshot:create my-first-dump

Giving your snapshot a name is optional. If you don't pass a name the current date time will be used:

# Creates a snapshot named something like `2017-03-17 14:31`
php artisan snapshot:create

When creating snapshots, you can optionally create compressed snapshots. To do this either pass the --compress option on the command line, or set the db-snapshots.compress configuration option to true:

# Creates a snapshot named my-compressed-dump.sql.gz
php artisan snapshot:create my-compressed-dump --compress

After you've made some changes to the database you can create another snapshot:

php artisan snapshot:create my-second-dump

To load a previous dump issue this command:

php artisan snapshot:load my-first-dump

To load a previous dump to another DB connection:

php artisan snapshot:load my-first-dump --connection=connectionName

To list all the dumps run:

php artisan snapshot:list

A dump can be deleted with:

php artisan snapshot:delete my-first-dump

To remove all backups except the most recent 2

php artisan snapshot:cleanup --keep=2

If you need to pass extra options to the underlying db-dumper, add a dump key to the database connection with a key of addExtraOptions and a value of the option. For example, to prevent the Postgres db dumper from setting the owner, you'd add:

'dump' => [
    'addExtraOption' => '--no-owner',
],

To the pgsql connection in database.php

Events

There are several events fired which can be used to perform some logic of your own:

  • Spatie\DbSnapshots\Events\CreatingSnapshot: will be fired before a snapshot is created
  • Spatie\DbSnapshots\Events\CreatedSnapshot: will be fired after a snapshot has been created
  • Spatie\DbSnapshots\Events\LoadingSnapshot: will be fired before a snapshot is loaded
  • Spatie\DbSnapshots\Events\LoadedSnapshot: will be fired after a snapshot has been loaded
  • Spatie\DbSnapshots\Events\DeletingSnapshot: will be fired before a snapshot is deleted
  • Spatie\DbSnapshots\Events\DeletedSnapshot: will be fired after a snapshot has been deleted

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

 相关资料
  • 最近在本地主机上安装了Laravel,并在PhPMyadmin中创建了一个DB。正在尝试创建测试用户,但注册时出现以下错误: Illumb\Database\QueryException数据库主机阵列为空。(SQL:从中选择count(*)作为聚合,其中 这是迁移、. env还是配置错误? . env 配置 以前使用过php,但对Laravel框架来说是新的。请问我该如何更正? 谢谢你:)

  • 问题内容: 我们都使用多个插入查询。这样做时,应该将其放置在内部还是包裹起来?甚至有必要在交易出现问题时自动将交易失败的情况包括在内吗? 包装交易的样本: 相反,包装try … catch: 或只是一笔没有交易的交易…抓住 问题答案: 如果您需要通过代码手动“退出”交易(通过异常还是只是检查错误状态),则不应使用,而是将代码包装在and /中: 请参阅交易文档。

  • 我有一个问题,而更新数据到laravel数据库。通常情况下,数据通过存储功能(POST请求)插入到数据库中。但是更新POST请求不会对数据库进行更新。我的密码是 routes.php 定制etail.php 控制器CustomerDetailController。php 当我发出存储为的后请求时,数据会被插入 带输出 但是当我尝试用PUT或PATCH请求更新相同的数据时 输入 我得到JSON响应作

  • 我正在使用Laravel8开发我的项目,现在我想从DB中删除一个数据,所以我添加了这个表单: 下面是实现这一目标的途径: 这是控制器方法: 现在的问题是,它没有工作,我的意思是它抓取正确,但它显示404未找到页面不知怎么的! 而且我也测试了这个: 但仍然显示404 NOT FOUND页面,这意味着进程没有到达控制器方法! 那么我该如何解决这个问题呢? 我非常感谢你们的任何想法或建议... 多谢了。

  • 我是Laravel的新手。当我试图从表中填充下拉列表时,我有一个“找不到变量”的问题:表名称是猫(类别),模型名称是“猫”,看起来像这样: 一个项目可以有一个类别。类别名称可以位于多个项目中。我现在想在表格中填充一个下拉列表,在其中插入一个新项目:为了实现这一点, 我走了一条路线: 我在我的HomeController中创建了一个函数,在那里我将(我确实这样认为)变量$cat传递给我的视图: 或其

  • 我在文件中的迁移中添加了一个新表。。 这是代码: 当我运行时,我的数据库中只有默认的laravel用户(和迁移)表。没有货币。 原因可能是什么? 编辑 迁移一切都很顺利。问题是: SQLSTATE[42000]:语法错误或访问冲突:1071指定的密钥太长;最大密钥长度为767字节(SQL:更改表用户添加唯一users_email_unique(电子邮件)) SQLSTATE[42000]:语法错误