You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+121Lines changed: 121 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -98,6 +98,127 @@ DevGuard is divided into two projects: A frontend (DevGuard Web) and a backend (
98
98
99
99
<palign="right">(<ahref="#readme-top">back to top</a>)</p>
100
100
101
+
## Database Migrations
102
+
103
+
DevGuard uses [golang-migrate](https://github.com/golang-migrate/migrate) for database schema management. All migrations are embedded in the binary and run automatically on startup.
104
+
105
+
### How Database Migrations Work
106
+
107
+
1.**Automatic Migration**: By default, migrations run automatically when the application starts
108
+
2.**Environment Control**: Set `AUTO_MIGRATE=false` to disable automatic migrations
109
+
3.**Embedded Migrations**: Migration files are embedded in the binary for easy deployment
110
+
4.**Idempotent**: Migrations can be run multiple times safely
111
+
112
+
### Creating New Migrations
113
+
114
+
#### 1. Install the Migration Tool
115
+
116
+
The project includes golang-migrate as a tool dependency. Install it using:
117
+
118
+
```bash
119
+
go get -tool github.com/golang-migrate/migrate/v4/cmd/migrate
120
+
```
121
+
122
+
#### 2. Create a New Migration
123
+
124
+
```bash
125
+
# Create a new migration file pair (.up.sql and .down.sql)
126
+
go tool migrate create -ext sql -dir internal/database/migrations your_migration_name
127
+
128
+
# Example: Adding a new table
129
+
go tool migrate create -ext sql -dir internal/database/migrations add_user_preferences_table
0 commit comments