• 请不要在回答技术问题时复制粘贴 AI 生成的内容
SpiderShrimp
V2EX  ›  程序员

go xorm reverse sqlite3 有误

  •  
  •   SpiderShrimp · Oct 23, 2019 · 1883 views
    This topic created in 2428 days ago, the information mentioned may be changed or developed.

    我要将数据库从 sqlite3 自动迁移到 mysql,因为二者关键字有些细微的差别,这也是我为什么不用 dump 文件的原因。所以我打算用 xorm 工具读取 sqlite3 数据库生成映射结构体,然后用结构体在代码里同步表结构和数据到 mysql 去。 但是生成的时候居然生成出错误的结构体,我没有 NOT 这个字段的,给我生成出来了,我去掉表字段的 not null 约束后恢复正常,但是怎样保证没去掉的时候也是正常的。 type _usersOld20191023 struct { Id string xorm:"varchar(32)" Not string xorm:"not null NULL" PrivateKey string xorm:"varchar(100)" Not string xorm:"not null NULL" PublicKey string xorm:"varchar(100)" Not string xorm:"not null NULL" PrivateIpId string xorm:"varchar(32)" Not string xorm:"not null NULL" CreateTime int64 xorm:"not null bigint" }

    type Boxes struct { Id string xorm:"varchar(32)" Not string xorm:"not null NULL" PrivateKey string xorm:"varchar(100)" Not string xorm:"not null NULL" PublicKey string xorm:"varchar(100)" Not string xorm:"not null NULL" AllowIps string xorm:"varchar(200)" Not string xorm:"not null NULL" PrivateIpId string xorm:"varchar(100)" Not string xorm:"not null NULL" CreateTime int64 xorm:"not null bigint" }

    7 replies    2019-10-24 15:58:03 +08:00
    SpiderShrimp
        1
    SpiderShrimp  
    OP
       Oct 23, 2019
    type _usersOld20191023 struct {
    Id string `xorm:"varchar(32)"`
    Not string `xorm:"not null NULL"`
    PrivateKey string `xorm:"varchar(100)"`
    Not string `xorm:"not null NULL"`
    PublicKey string `xorm:"varchar(100)"`
    Not string `xorm:"not null NULL"`
    PrivateIpId string `xorm:"varchar(32)"`
    Not string `xorm:"not null NULL"`
    CreateTime int64 `xorm:"not null bigint"`
    }
    SpiderShrimp
        2
    SpiderShrimp  
    OP
       Oct 23, 2019
    小白不太会编辑,后面的代码可以无视,只看上面这个就好了。
    zunceng
        3
    zunceng  
       Oct 23, 2019
    xorm reverse 这个工具做的 。。。一言难尽
    记得 postgres 用 xorm,schema 不能选 还需要魔改 reverse 代码才行
    zunceng
        4
    zunceng  
       Oct 23, 2019
    就 mysql 是好用的 其他数据库 步步为营吧
    reus
        5
    reus  
       Oct 23, 2019
    bug 多的包就不要用了
    SpiderShrimp
        6
    SpiderShrimp  
    OP
       Oct 24, 2019
    @zunceng 是的,我测试了下 mysql 的 reverse,确实无错误
    SpiderShrimp
        7
    SpiderShrimp  
    OP
       Oct 24, 2019
    @reus 是呀,后来放弃 reverse 方案了。不过用 xorm 读取数据库表结构确实方便。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4838 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 09:48 · PVG 17:48 · LAX 02:48 · JFK 05:48
    ♥ Do have faith in what you're doing.