1
votes

Would like to be able to move (copy and replace) views from one project to another.

Suppose we have Dev GCP Project 1, along with an Integrated and Production GCP project. I would like to be able to move individual views or specific datasets only (Not tables) from Dev to Int, then Int to Prod.

I know i can use the following Google Cloud Shell command for moving tables.

bq cp ProjectNumberDev.DatasetDev.TableDev ProjectNumberInt.DatasetInt.TableInt

However, this command only works with tables and not views, is there a way to do this with views? Or is a Table Insert / Post API script the only way?

1

1 Answers

3
votes

Per documentation:

Currently, there is no supported method for copying a view from one dataset to another. You must recreate the view in the target dataset.

You can copy the SQL query from the old view:

Issue the bq show command.
The --format flag can be used to control the output. If you are getting information about a view in a project other than your default project, add the project ID to the dataset in the following format: [PROJECT_ID]:[DATASET]. To write the view properties to a file, add > [PATH_TO_FILE] to the command.

bq show --format=prettyjson [PROJECT_ID]:[DATASET].[VIEW] > [PATH_TO_FILE]

Meantime, if you can script all your views during the development then you can use CREATE VIEW statement in all environments

See more for Data Definition Language

You can apply same approach for tables creation, etc.