当前位置:网站首页>Golang migrate is easy to use
Golang migrate is easy to use
2022-07-24 10:19:00 【Not Lao Wang who lives next door】
For more convenient database operation , Constantly adapt to business development needs ,migrate Used for database operation . Use migrate Will create a schema_migrations surface , To record migrate Records of operation , Whenever running migrate When , I will check this form first , If the in the table is True, May be an error .
golang-migrate Address :
golang-migrate Address :
https://github.com/golang-migrate/migrate
install :
windows10:
cmd Command input :
scoop install migrate
After installation :
cmd Command line input :
migrate -version
When the version information appears, the installation is successful .
Create migration file
grammar :
create [-ext E] [-dir D] [-seq] [-digits N] [-format] [-tz] NAME
migrate create -ext sql -dir db/migrate -seq init_schema
After successful operation, it will be automatically in db/migrate The corresponding migration file is generated under the folder . Here's the picture
Insert picture description here 
Move up
The corresponding sql Statement write generated
000001_init_schema.up In file , And then execute the command
command :
migrate -path db/migration -database "mysql://root:[email protected](localhost:3306)/blog" -verbose up
Roll back
The corresponding sql Statement write generated
000001_init_schema.down In file , And then execute the command
migrate -path db/migration -database "mysql://root:[email protected](localhost:3306)/blog" -verbose down
After success in the database
边栏推荐
- Curse of knowledge
- Scaffold document directory description and document exposure
- WEB安全基础 - - -文件上传(文件上传绕过)
- The best time to buy and sell stocks includes handling charges (leetcode-714)
- CRC Coding in C language
- Simple parsing JSON strings with regular expressions
- Binary original code, inverse code, complement code
- Query about operating system security patch information
- Wechat applet
- error: field ‘XXX’ declared as a function
猜你喜欢

Ask you to build a small program server

The concept and representation of a tree

Analysis of Kube proxy IPVS mode

Add a love power logo to your website
![[STM32 learning] (12) STM32 realizes LCD1602 simple static reality](/img/78/954ebaae0cce5d9387e7032fa85e60.png)
[STM32 learning] (12) STM32 realizes LCD1602 simple static reality

Dynamic planning: robbing families and houses

ZOJ 2770 differential restraint system -- 2 -- May 20, 2022

高精尖中心论文入选国际顶会ACL 2022,进一步拓展长安链隐私计算能力
![[STM32 learning] (11) STM32 Mifare_ Use of one (S50) m1s50 (read, write, key modification, control bit interpretation)](/img/fd/4290525914b5146fe0eb653517fef9.png)
[STM32 learning] (11) STM32 Mifare_ Use of one (S50) m1s50 (read, write, key modification, control bit interpretation)

Deployment and analysis of coredns
随机推荐
2022, our small goal
图模型2--2022-5-13
Create a vertical seekbar from scratch
【机器人学习】机构运动学分析与matlab仿真(三维模型+word报告+matlab程序)
[STM32 learning] (13) STM32 realizes ultrasonic ranging (hc-sr04)
[STM32 learning] (15) STM32 realizes DHT11 temperature and humidity acquisition and display
2022, enterprise unified process platform design and integration specifications refer to thubierv0.1
高精尖中心论文入选国际顶会ACL 2022,进一步拓展长安链隐私计算能力
unity中物体z旋转同步面板上的数值
Exception: pyqtgraph requires Qt version >= 5.12 (your version is 5.9.5)
zoj-Swordfish-2022-5-6
Notes on using setupproxy
The concept and representation of a tree
Basic SQL operations
[robot learning] mechanism kinematics analysis and MATLAB simulation (3D model +word report +matlab program)
note: expected ‘void * (***)(void ***)’ but argument is of type ‘void (*)(void *)’
Tag the specified commit and submit the tag
[STM32 learning] (12) STM32 realizes LCD1602 simple static reality
Add a love power logo to your website
Do you really understand the concept of buffer? Take you to uncover the buffer zone~