前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >依托illuminate组件实现数据库迁移(后续)

依托illuminate组件实现数据库迁移(后续)

作者头像
魔王卷子
发布2020-02-17 07:40:55
7540
发布2020-02-17 07:40:55
举报
文章被收录于专栏:魔王卷子的专栏

这段时间一直在思考,想着把迁移功能给独立出来。所以还是按照Laravel的模式重新写了一版并提交到了 GitHub 中,另外 Packagist 也发布了。

下面简单介绍一下。

首先创建项目使用如下命令:

代码语言:javascript
复制
composer create-project wowangjuanzi/migrate

创建好后查看文件目录

代码语言:javascript
复制
$ tree ./migrate/ -L 3
./migrate/
├── README.md
├── artisan -> console.php
├── composer.json
├── composer.lock
├── config
│   ├── app.php
│   └── database.php
├── console.php
├── database
│   └── migrations
├── helper.php
└── vendor
    ├── autoload.php
    ├── bin
    │   ├── carbon -> ../nesbot/carbon/bin/carbon
    │   └── var-dump-server -> ../symfony/var-dumper/Resources/bin/var-dump-server
    ├── composer
    │   ├── ClassLoader.php
    │   ├── LICENSE
    │   ├── autoload_classmap.php
    │   ├── autoload_files.php
    │   ├── autoload_namespaces.php
    │   ├── autoload_psr4.php
    │   ├── autoload_real.php
    │   ├── autoload_static.php
    │   └── installed.json
    ├── doctrine
    │   └── inflector
    ├── illuminate
    │   ├── config
    │   ├── console
    │   ├── container
    │   ├── contracts
    │   ├── database
    │   ├── events
    │   ├── filesystem
    │   └── support
    ├── nesbot
    │   └── carbon
    ├── phpoption
    │   └── phpoption
    ├── psr
    │   ├── container
    │   └── simple-cache
    ├── symfony
    │   ├── console
    │   ├── finder
    │   ├── polyfill-ctype
    │   ├── polyfill-mbstring
    │   ├── polyfill-php72
    │   ├── polyfill-php73
    │   ├── process
    │   ├── service-contracts
    │   ├── translation
    │   ├── translation-contracts
    │   └── var-dumper
    └── vlucas
        └── phpdotenv

38 directories, 20 files

config文件夹包含的是相关配置文件,比如app.php中就是指定运行的环境。database.php指定的是数据库的相关配置信息。

console.php是我自己定义的,类似Laravel中的artisan,不过我也创建了一个软链artisan->console.php。方便进行适应。

还有一个文件是.env,该文件内容如下:

代码语言:javascript
复制
APP_NAME=Migrate
APP_ENV=local

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

这里的配置跟Laravel相同,这里我就不过多描述了。

操作命令主要如下:

代码语言:javascript
复制
$ php artisan 
Migrate 0.0.3

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
      --env[=ENV]       The environment the command should run under
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  help              Displays help for a command
  list              Lists commands
  migrate           Run the database migrations
 db
  db:wipe           Drop all tables, views, and types
 make
  make:migration    Create a new migration file
 migrate
  migrate:fresh     Drop all tables and re-run all migrations
  migrate:install   Create the migration repository
  migrate:refresh   Reset and re-run all migrations
  migrate:reset     Rollback all database migrations
  migrate:rollback  Rollback the last database migration

比如创建迁移文件:

代码语言:javascript
复制
$ php artisan make:migration create_users_table
Created Migration: 2019_11_24_135530_create_users_table

具体其他的可以参考Laravel文档:

最后

欢迎大家来尝试我写的这个工具,如果有什么疑问,可以跟我留言提issus。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-11-242,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 最后
相关产品与服务
数据传输服务
腾讯云数据传输服务(Data Transfer Service,DTS)可帮助用户在业务不停服的前提下轻松完成数据库迁移上云,利用实时同步通道轻松构建高可用的数据库多活架构,通过数据订阅来满足商业数据挖掘、业务异步解耦等场景需求。同时,DTS 还提供私有化独立输出版本 DTS-DBbridge,支持异构数据库和同构数据库之间迁移和同步,可以帮助企业实现完整数据库迁移(如 Oracle)。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档