如何使用 django-tenant-schema 将数据从共享模式迁移到 Multi-Tenancy 模式?
我们有一个 saas,最初没有使用 django-tenant-schema,而是使用共享数据库、共享模式方法。我们现在发现了 django-tenant-schemas 并认为这是正确的方法。
现在的问题是如何从单个 public
迁移数据架构到独立租户架构。django-tenant-schemas
文档说明如下:
Note: your database should be empty if this is the first time you’re running this command.
在我现有的应用程序中,我有一个租户表,所有其他模型都有 ForeignKey,但所有内容都在公共(public)模式中。我用
south
移民。现在我需要将所有这些租户数据迁移到单独的模式。如何做同样的事情?
最佳答案
这样做有一个技巧。首先,您应该了解 psql 转储和加载命令。
脚步:
public
中架构。将其转储到 pgsql
文件使用 pg_dump
命令。可以说database.pgsql
. temp_db
. tenant_xyz
. tenant_xyz
至tenant_xyz.pgsql
. tenant_xyz
模式转储到租户模式实现的数据库,比方说 postgres
. postgres
中使用已加载转储的tenant_xyz 模式首选模式中的数据库。 脚本如下:
psql -U postgres -c "DROP DATABASE IF EXISTS temp_db"
psql -U postgres -c "CREATE DATABASE temp_db"
psql -U postgres temp_db < database.pgsql
psql -U postgres -d temp_db -c "ALTER SCHEMA public RENAME TO teanat_xyz"
pg_dump -U postgres -d temp_db -n tenant_xyz > tenant_xyz.pgsql
psql -U postgres -c "DROP DATABASE temp_db"
psql -U postgres -c "DROP SCHEMA IF EXISTS tenant_xyz CASCADE"
psql -U postgres postgres < tenant_xyz.pgsql
关于python - django-租户模式 : Migrate data from shared schema to multi tenant schema,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35132316/