@@ -113,3 +113,37 @@ precommit : fmt clippy test
113
113
114
114
hack :
115
115
cargo hack check --workspace --each-feature --all-targets
116
+
117
+ # Run database migrations using `diesel_cli`.
118
+ # Assumes `diesel_cli` is already installed.
119
+ #
120
+ # Usage :
121
+ # make migrate [database-url=<PSQL connection string>] [locked-schema=<yes|no>]
122
+
123
+ # This proceeds as follows:
124
+ # Creates a temporary migrations directory, cleans it up if it already exists
125
+ # Copies all migrations to the temporary migrations directory and runs migrations
126
+ # Cleans up migrations, removing tmp directory if empty, ignoring otherwise
127
+ migrate :
128
+ mkdir -p $(ROOT_DIR ) /tmp/migrations
129
+ find $(ROOT_DIR ) /tmp/migrations/ -mindepth 1 -delete
130
+
131
+ cp -r $(ROOT_DIR)/migrations/. $(ROOT_DIR)/v2_migrations/. $(ROOT_DIR)/tmp/migrations/
132
+ diesel migration run --migration-dir=$(ROOT_DIR)/tmp/migrations \
133
+ $(if $(strip $(database-url)),--database-url="$(database-url)",) \
134
+ $(if $(strip $(call eq,$(locked-schema),yes)),--locked-schema,)
135
+
136
+ rm -r $(ROOT_DIR)/tmp/migrations
137
+ rmdir $(ROOT_DIR)/tmp 2>/dev/null || true
138
+
139
+ redo_migrate :
140
+ mkdir -p $(ROOT_DIR ) /tmp/migrations
141
+ find $(ROOT_DIR ) /tmp/migrations/ -mindepth 1 -delete
142
+
143
+ cp -r $(ROOT_DIR)/migrations/. $(ROOT_DIR)/v2_migrations/. $(ROOT_DIR)/tmp/migrations/
144
+ diesel migration redo --all --migration-dir=$(ROOT_DIR)/tmp/migrations \
145
+ $(if $(strip $(database-url)),--database-url="$(database-url)",) \
146
+ $(if $(strip $(call eq,$(locked-schema),yes)),--locked-schema,)
147
+
148
+ rm -r $(ROOT_DIR)/tmp/migrations
149
+ rmdir $(ROOT_DIR)/tmp 2>/dev/null || true
0 commit comments