Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DCV-2572 dbt-coves blue-green #482

Merged
merged 17 commits into from
Jul 17, 2024

Conversation

BAntonellini
Copy link
Collaborator

This PR implements dbt-coves blue-green command

It's basically a reimplementation of Balboa's blue_green_run script, with the main difference here we use pure Python instead of Python + dbt macros

WARNING: use testing databases like BRUNO_TEST, as data can be lost during swap/drop.

A dbt blue-green run consists of copying a blue (production) database into a green (staging one), making sure dbt builds correctly, swapping them and dropping the old production one.

This process runs the following:

  • Create staging database
  • Clone schemas and schema-grants from prod to staging
  • Run dbt build
  • Clone database grants from prod to staging
  • Swap prod and staging (staging becomes prod and viceversa)
  • Drop staging database (ex production)

proc.join()


# if __name__ == "__main__":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we avoid keeping this commented out and test this differently?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ssassi I agree, it belongs to the code Coldbore sent us, and its testing case. I'd like to discuss how all this should be tested.

"""
green_exists = self._check_if_database_exists()
if green_exists and self.drop_staging_db:
if self.drop_staging_db_after:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should also validate that it's a valid int?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f"Green database {self.staging_database} exists."
f"Waiting {self.drop_staging_db_after} minutes before dropping it"
)
for i in range(self.drop_staging_db_after):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this raise an exception if the number of loops ended and the database still exists?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, if you explicitly set it to drop, and give it X minutes to try and drop, something might've happened and blue-green cannot continue

Done.

@BAntonellini BAntonellini merged commit 99697b3 into main Jul 17, 2024
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants