shisou / tpgii
0.3
2024-05-28 05:06 UTC
Requires
- php: >=7.4
- phpoffice/phpspreadsheet: ^1.21
- symfony/polyfill-php80: ^1.26
- topthink/think-helper: ^3.1
- topthink/think-migration: ^3.1
README
介绍
- tpgii:根据excel生成model和sql,需要在app目录下有model目录,生成的model继承AR类(AR类为自定义代码,文件存在则不生成)。
- 生成的类文件以
// ---------- Custom code below ----------
为分界线,上面是自动生成代码,下面为自定义代码
安装
composer require shisou/tpgii
使用
- 新建db.xlsx放入到think目录下,格式如下图:
命令自动生成
id,created_at,updated_at,status
,编写excel时请忽略字段
@表名
关联表名- 字段
@表名@
相互关联
- 字段
&表名,表名,表名
多态一对一关联 - 字段
&表名,表名,表名&
多态一对多关联 - 多态必须字段
表名_type
,表名_id
,表名_type字段存放对应的Model名称
- tpgii运行步骤如下:
- 到
think
根目录先运行命令:php think migrate:run
数据库会有一个migrations表,这个是工具使用的表,不要修改 如果想初次运行导入数据,到think/database
目录下新建init.php
文件:<?php return [// 系统配置 'setting' => [ [ "name" => "网站名称", "key" => "site_name", "value" => "MineAdmin", ], [ "name" => "网站关键词", "key" => "site_keywords", "value" => "关键词", ] ], ];
- 到
think
根目录运行命令:php think tpgii
会自动生成 model文件 和 迁移文件 - 到
think
根目录运行命令:php think migrate:run
- 可跟参数
dataSql
导入 database\data.sql文件 到数据库 - 可跟参数
model
只生成model - 可跟参数
sql
只生成db.sql
- 到
think
根目录运行命令:php think migrate:run 20240527114620
将数据库恢复到指定版本。
- 到