pglite icon indicating copy to clipboard operation
pglite copied to clipboard

Already planed? : about preparing schema and migration

Open roccho-dev opened this issue 2 years ago • 2 comments

From reading the documentation, it is assumed that the schema is defined after the application is launched.

If I don't use 'electricSQL', is there an option planned for this Repository or project to provide the files after the schema definition or migration in advance? (I assume this is not a solution of the nature I am asking, but I am sure there will be developers who will have the same question) (apologies if this has already been answered)

roccho-dev avatar Aug 15 '24 05:08 roccho-dev

I'm not sure I understand what you are asking but if you are asking, can you predefine the schema and data and load pglite directory onto an existing database, then yes, at least according to the documentation!

https://pglite.dev/docs/api#dumpdatadir

With this you can create a postgres datadir and then just supply a tar.gz of that to your new instance.

AntonOfTheWoods avatar Aug 15 '24 08:08 AntonOfTheWoods

Hey @PorcoRosso85

Good question, we don't have any standard schema migration tooling built in (yet). The easers is to just run you migrations immediately after starting PGLite:

const pg = await PGlite.create()

pg.exec(`
  CREATE TABLE IF NOT EXIST my_table (
    -- ... schema
  )  
  
  CREATE TABLE IF NOT EXIST my_other_table (
    -- ... schema
  )  
`)

// Now you can use the db

There are many tools that do schema migration in different ways, and with ORMd such a Drizzle supporting PGlite, using their migration tooling is likely to be preferred in most cases.

However, I am considering a basic migration plugin modelled on @databases/pg-migrations, but this is fairly low down the priority list. It is like better served by the community.

samwillis avatar Aug 15 '24 11:08 samwillis