Skip to content

Handle data migration in docker-entrypoint.sh #712

Closed
@codeReader52

Description

@codeReader52

Hi docker postgres experts,
I was wondering if it's worth to expose a way to execute a bash script every time the container spins up after executing the current logic in docker-entrypoint.sh script. The example usage could be for data-migration. The desired execution would be along the line of:

  1. Execute current logic in docker-entrypoint.sh
  2. Additional logic to perform data migration:
    If database version is 1, then perform migration 1, migration 2, migration 3
    Else if database version is 2, then perform migration 2, migration 3
    Else if database version is 3, then perform migration 3
    Else do nothing

Step 2 can probably be executed by a bash script. Hence, in general, I think it's worth it to expose a way to specify a bash script every time the container spins up rather than just initialisation logic in folder docker-entrypoint-initdb.d. Currently, the scripts in docker-entrypoint-initdb.d only gets executed if the file $PGDATA/PG_VERSION doesn't exists or has size 0. Meaning that if a database already exists, there is no way to perform any data-migration (that I know of).

Propose: we could specify another folder such as docker-data-migration.d similar to docker-entrypoint-initdb.d but any bash scripts in it will get run every time the container spins up.

Metadata

Metadata

Assignees

No one assigned

    Labels

    RequestRequest for image modification or feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions