运行 在 typeorm 中迁移到 slave
Run migrations on slave in typeorm
我在 typeorm 中使用副本,当 运行 使用 migrate:run 命令迁移时,只有主服务器接收更改。我想知道我是否可以 运行 迁移并反映副本。
我的配置
{
type: 'mysql',
logging: true,
replication: {
master: {
host: 'localhost',
port: 3306,
username: 'root',
password: 'secret@contents',
database: 'ps-contents',
},
slaves: [{
host: 'localhost',
port: 3307,
username: 'root',
password: 'secret@contents',
database: 'ps-contents',
}],
},
migrations: [join(__dirname, '..', 'database/migrations/*.{ts,js}')],
cli: {
migrationsDir: 'src/infra/database/migrations',
},
entities: [join(__dirname, '..', 'database/entities/*.{ts,js}')],
synchronize: true,
}
文档没有直接说明这一点,但似乎您必须自己在数据库级别处理复制机制。 TypeORM 提供 load-balancing 机制,允许使用 slave-servers.
我推断from:
All schema update and write operations are performed using master server. All simple queries performed by find methods or select query builder are using a random slave instance. [...]
我可能是错的,所以请遵循 issue report。
我在 typeorm 中使用副本,当 运行 使用 migrate:run 命令迁移时,只有主服务器接收更改。我想知道我是否可以 运行 迁移并反映副本。 我的配置
{
type: 'mysql',
logging: true,
replication: {
master: {
host: 'localhost',
port: 3306,
username: 'root',
password: 'secret@contents',
database: 'ps-contents',
},
slaves: [{
host: 'localhost',
port: 3307,
username: 'root',
password: 'secret@contents',
database: 'ps-contents',
}],
},
migrations: [join(__dirname, '..', 'database/migrations/*.{ts,js}')],
cli: {
migrationsDir: 'src/infra/database/migrations',
},
entities: [join(__dirname, '..', 'database/entities/*.{ts,js}')],
synchronize: true,
}
文档没有直接说明这一点,但似乎您必须自己在数据库级别处理复制机制。 TypeORM 提供 load-balancing 机制,允许使用 slave-servers.
我推断from:
All schema update and write operations are performed using master server. All simple queries performed by find methods or select query builder are using a random slave instance. [...]
我可能是错的,所以请遵循 issue report。