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
types.varchar primary_key: true --> character varying(255) NOT NULL PRIMARY KEY
1170
1214
types.real array: true --> real[]
1171
1215
types.text array: 2 --> text[][]
1172
-
```
1216
+
]]}
1173
1217
1174
1218
> MySQL has a complete different type set than PostgreSQL, see [MySQL types](https://github.com/leafo/lapis/blob/master/lapis/db/mysql/schema.moon#L162)
1175
1219
@@ -1183,6 +1227,7 @@ We define migrations in our code as a table of functions where the key of each
1183
1227
function in the table is the name of the migration. You are free to name the
1184
1228
migrations anything but it's suggested to give them Unix timestamps as names:
1185
1229
1230
+
1186
1231
$dual_code{
1187
1232
moon=[[
1188
1233
import add_column, create_index, types from require "lapis.db.schema"
@@ -1228,7 +1273,8 @@ migrations in the format described above.
1228
1273
1229
1274
Let's create this file with a single migration as an example.
1230
1275
1231
-
```lua
1276
+
$dual_code{
1277
+
lua=[[
1232
1278
-- migrations.lua
1233
1279
1234
1280
local schema = require("lapis.db.schema")
@@ -1245,9 +1291,8 @@ return {
1245
1291
})
1246
1292
end
1247
1293
}
1248
-
```
1249
-
1250
-
```moon
1294
+
]],
1295
+
moon=[[
1251
1296
-- migrations.moon
1252
1297
1253
1298
import create_table, types from require "lapis.db.schema"
@@ -1262,7 +1307,7 @@ import create_table, types from require "lapis.db.schema"
1262
1307
"PRIMARY KEY (id)"
1263
1308
}
1264
1309
}
1265
-
```
1310
+
]]}
1266
1311
1267
1312
After creating the file, ensure that it is compiled to Lua and run `lapis
1268
1313
migrate`. The command will first create the migrations table if it doesn't
@@ -1274,15 +1319,15 @@ Read more about [the migrate command](command_line.html#command-reference/lapis-
1274
1319
1275
1320
We can manually create the migrations table using the following code:
1276
1321
1277
-
```lua
1322
+
$dual_code{
1323
+
lua=[[
1278
1324
local migrations = require("lapis.db.migrations")
1279
1325
migrations.create_migrations_table()
1280
-
```
1281
-
1282
-
```moon
1326
+
]],
1327
+
moon=[[
1283
1328
migrations = require "lapis.db.migrations"
1284
1329
migrations.create_migrations_table!
1285
-
```
1330
+
]]}
1286
1331
1287
1332
It will execute the following SQL:
1288
1333
@@ -1296,15 +1341,15 @@ CREATE TABLE IF NOT EXISTS "lapis_migrations" (
1296
1341
Then we can manually run migrations with the following code:
1297
1342
1298
1343
1299
-
```lua
1344
+
$dual_code{
1345
+
lua=[[
1300
1346
local migrations = require("lapis.db.migrations")
1301
1347
migrations.run_migrations(require("migrations"))
1302
-
```
1303
-
1304
-
```moon
1348
+
]],
1349
+
moon=[[
1305
1350
import run_migrations from require "lapis.db.migrations"
1306
1351
run_migrations require "migrations"
1307
-
```
1352
+
]]}
1308
1353
1309
1354
## Database Helpers
1310
1355
@@ -1317,7 +1362,6 @@ Returns a date string formatted properly for insertion in the database.
1317
1362
1318
1363
The `time` argument is optional, will default to the current UTC time.
1319
1364
1320
-
1321
1365
$dual_code{[[
1322
1366
date = db.format_date!
1323
1367
db.query "update things set published_at = ?", date
0 commit comments