1

I have a database for my master branch. I want to keep my master branch the same as the release version so I can't alter the database for updates.

Because I work at different updates at the same time, switching databases is a lot of work so I want to automate this. I already have a function that checks on what branch I am working and changes my database settings to the correct database.

I was thinking of automating the creation of the database when I create a new branch. But I do not know if this is possible within GitLab.

Is it possible to copy the master database to a new database when I create a new branch? If so, is there any documention I can look at?

  • https://stackoverflow.com/search?q=%5Bgit%5D+branch+database Esp. see https://stackoverflow.com/q/846659/7976758 , https://stackoverflow.com/q/6409204/7976758 , https://stackoverflow.com/q/15171996/7976758 – phd Nov 12 '21 at 12:36
  • @phd Thanks for your comment. Unfortunately this does not answer my question. I do not want to version control my database. I want to copy the database to a new database automatically when I create a new branch so the branch has its own databse apart from the Master. –  Nov 12 '21 at 12:40

1 Answers1

1

if database name is git branch name you can used gitlab predefined variables with some shell script to do it.

.gitlab-ci.yml structure look like this:

// .gitlab-ci.yml

stages:
  - prepare

create_database:
  stage:
    prepare
  script:
    - ./common_shell_script.sh
    - if databse_exist then; $CI_COMMIT_BRANCH; exit 0; if;
    - copy_database $CI_DEFAULT_BRANCH $CI_COMMIT_BRANCH

// common_shell_script.sh

function database_exist() {
    // check database exist
    // if exist then;
    //     return true;
    // fi
    // return false;
}

function copy_database()  {
    // copy from $1 to $2
}
Mouson Chen
  • 926
  • 7
  • 14