项目作者: 4lie

项目描述 :
How migrate / change your SQL data from production namespace to testing namespace
高级语言:
项目地址: git://github.com/4lie/datayar.git
创建时间: 2020-05-16T18:37:50Z
项目社区:https://github.com/4lie/datayar

开源协议:MIT License

下载


Datayar

Introduction

Consider an environment based on k8s with two separate namespaces for production and testing.
In the production environment, you have an PostgreSQL database that you want its data
on your testing environment even you need to change its structure and fields.
Datayar is here to help you.

Step by Step

First of all, we must export the production database:

  1. oc project <production-namespace>
  2. echo <database-password> | oc rsh -c <database-container> <database-pod> pg_dump -U <database-user> <database-name> > output.sql

You can use these exported data with the provided docker-compose to alter tables or remove redundant data.

e.g.

  • Remove rows that have not-null deleted_at.
  1. delete from <table> where deleted_at is not null;

In the end, we export insert-only SQL files and load them into the testing environment using pgsl.

  1. oc project <testing-namespace>
  2. echo <database-password> | oc rsh -c <database-container> <database-pod> psql -U <database-user> <database-name> -f - < <table-1>.sql
  3. echo <database-password> | oc rsh -c <database-container> <database-pod> psql -U <database-user> <database-name> -f - < <table-2>.sql
  4. echo <database-password> | oc rsh -c <database-container> <database-pod> psql -U <database-user> <database-name> -f - < <table-3>.sql

Also, you can do this on your system as follow:

  1. pg_dump -U <database-user> -W -h 127.0.0.1 -d <database-name> -a -f output.sql
  1. psql -U <database-user> -h 127.0.0.1 -f - < output.sql