upstat icon indicating copy to clipboard operation
upstat copied to clipboard

feat: support sqlite

Open chamanbravo opened this issue 1 year ago • 11 comments

Sqlite support will make it faster and easier to setup. But don't replace postgres with sqlite. Some might want to add a external database. You can keep both like this.

https://github.com/create-go-app/fiber-go-template/blob/master/platform/database/open_db_connection.go

chamanbravo avatar Mar 06 '24 15:03 chamanbravo

hi can i take this?

jeyren95 avatar Mar 16 '24 02:03 jeyren95

hi can i take this?

Yeah sure. Please check out the link before adding. Try to keep both sqlite and postgres. Add a new env var db_type, keep sqlite default... And make sure migrations work properly for both. Thank you.

chamanbravo avatar Mar 16 '24 03:03 chamanbravo

the current migration script requires creating the pgcrypto extension, but i dont think sqlite has that

are you looking to maintain only 1 migration script for both DB types?

jeyren95 avatar Mar 17 '24 13:03 jeyren95

yeah, I think having only one migration script would be great.

chamanbravo avatar Mar 17 '24 13:03 chamanbravo

hmmm ok i need to dig deeper to see if this is possible

jeyren95 avatar Mar 17 '24 15:03 jeyren95

we can remove pgcrypto and use crypto library. So the script can work for both.

chamanbravo avatar Mar 17 '24 15:03 chamanbravo

ok yeah that works, i'll implement the crypto library in this PR too

jeyren95 avatar Mar 17 '24 15:03 jeyren95

There is another issue with trying to support both postgres and sqlite with the same script:

  • Postgres supports the "SERIAL" data type, but sqlite does not, making the id column difficult to synchronize between postgres and sqlite

Ways that i tried to resolve this but does not work:

  1. Using integer primary key autoincrement - does not work because postgres does not support autoincrement
  2. Using integer primary key generated always as identity - does not work because not supported by sqlite
  3. UUID extension - does not work because the not supported by sqlite

jeyren95 avatar Mar 24 '24 12:03 jeyren95

not sure if you might have seen a solution for this somewhere, but we might have to end up having separate scripts if you do want to support both database types

jeyren95 avatar Mar 24 '24 12:03 jeyren95

Hey thank you for trying, if having a single script for migration doesn't seem possible, we can create different scripts then...

chamanbravo avatar Mar 24 '24 12:03 chamanbravo

opened a PR to resolve this issue https://github.com/chamanbravo/upstat/pull/43

jeyren95 avatar Mar 31 '24 05:03 jeyren95