django - 如何在 Google Cloud Platform 上进行 Django 迁移?

标签 django google-app-engine google-cloud-platform google-cloud-sql

我想在 Google App Engine 上托管我的应用程序,并拥有一个用于数据库的 Google SQL 实例。该应用程序的主要部分是使用 Django Rest Framework 构建的 API。当我需要修改数据库的架构时,我向 Google Cloud 支持人员询问了在生产中进行迁移的最佳实践。由于我是 Web 开发的新手,也许这里的任何专家都有类似的经验,并且可以验证建议的过程是否是我真正可以遵循的?

For database migration best practice, you could create a separate development/test/backup instance of your Cloud SQL database. Let's say for example your DB instance for production is DB1, create a dev instance namely DB2 that has all the tables of DB1. After that, configure your app to point DB2 instance temporarily. Please make sure that both instances are in sync and updated. Then, deploy a new version of your app that points to DB2 so you can update DB1 (add new tables, columns) as your official database instance in the production environment. Then you can point it again to DB1 and update DB2.

最佳答案

使用第二个 CloudSQL 来执行迁移确实是一个很好的做法。我建议:

  • 部署新的 App Engine 版本,该版本使用新的 db 架构但尚未将流量定向到它(使用 gcloud app deploy --no-promote)
  • 克隆您的 CloudSQL 实例以创建一个新实例,您将在其中运行迁移
  • 在本地机器上,配置 Cloud SQL Proxy指向这个新的 CloudSQL 实例并运行 python manage.py migrate
  • 迁移完成后,将流量定向到新的 App Engine 版本。

  • 在生产环境中,您的新 CloudSQL 实例将缺少在您执行步骤 2 到 4 时写入第一个实例的数据。完全避免这种情况的最简单解决方案是在迁移期间停止您的 App Engine 应用程序。但是,如果您无法承受一些停机时间,则需要在克隆第一个实例后跟踪对它所做的更改,并将这些更改手动应用于新实例。

    关于django - 如何在 Google Cloud Platform 上进行 Django 迁移?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48825154/

    相关文章:

    java - 这是服务器或客户端上的 Google Endpoints 错误吗?

    firebase - 如何从 Google 表格访问 Cloud Firestore?

    python - 具有多个网址的站点地图和对象

    javascript - 使用 Ajax 驱动的进度条上传 Django 文件

    sql-server - 无法使用 django-pyodbc-azure 2.1.0.0 连接到 MSSQL

    javascript - 无法在 Internet Explorer 10 上加载 Google Cloud Endpoints

    django - 虚拟环境 : cannot access lib: No such virtualenv or site directory

    node.js - OAuth 2.0 Playground 错误 403 : access_denied

    node.js - 如何使用 Node.js 连接到 Cloud SQL?

    python - Django 数据库查询往返