【发布时间】:2021-12-04 10:55:04
【问题描述】:
我有几个表,其列类型为 UUID。
我想将这些列转换为String 而不是UUID,因为调试很麻烦(例如,使用 DB Browser for SQLite 浏览 sqlite 文件> 要求我执行 SQL 查询只是为了将 UUID 对象转换为 Strings 以查看 id 值。
回到这个问题,最实用的方法是什么?
我正在考虑,并且即将做,但我想先问这个:
- 在
registerMigration中,创建一个新表。 - 新表现在有字符串列。
- 循环遍历旧表中的行,并将这些行移动到新表中,但请确保 ID 现在位于
Strings 而不是UUIDs 中。 - 删除旧表
- 将新表重命名为旧表的名称。
registerMigration("UUIDMigrationToString") { db in
try db.create(table: "new_table") { table in
table.autoIncrementedPrimaryKey("id")
table.column("someIdStuff", .text).notNull()
}
// loop through the old table...
// move the rows from the old table to the new table but with string Ids.
// drop old table, and rename new table.
}
【问题讨论】: