-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
59 lines (48 loc) · 1.47 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# 格式化所有 Rust 代码
fmt:
cargo fmt --all
# 运行服务器
run-server:
cargo run --bin server
# 运行数据库迁移
# 注意:不带参数时,默认执行 "up" 操作
run-migration:
cargo run --bin migration
# 执行向上迁移(应用所有未应用的迁移)
migrate-up:
cargo run --bin migration -- up
# 执行向下迁移(回滚最后一次迁移)
migrate-down:
cargo run --bin migration -- down
# 构建项目
build:
cargo build
# 运行测试
test:
cargo test
# 清理构建产物
clean:
cargo clean
# 默认任务:格式化代码并运行服务器
.PHONY: default
default: fmt run-server
# 声明所有任务为伪目标
.PHONY: fmt run-server run-migration migrate-up migrate-down build test clean generate-migration
# 生成表结构迁移文件
# 用法: make generate-migration name=table_name
# 例如: make generate-migration name=sys_role
generate-schema-migration:
@if [ -z "$(name)" ]; then \
echo "Error: Please provide a name for the schema migration."; \
echo "Usage: make generate-schema-migration name=table_name"; \
exit 1; \
fi
sea-orm-cli migrate generate --migration-dir migration/src/schemas create_$(name)
# 生成数据迁移文件
generate-data-migration:
@if [ -z "$(name)" ]; then \
echo "Error: Please provide a name for the data migration."; \
echo "Usage: make generate-data-migration name=insert_default_data"; \
exit 1; \
fi
sea-orm-cli migrate generate --migration-dir migration/src/datas insert_$(name)