简体   繁体   English

更改架构内的表 - postgres + sequelize

[英]Alter table inside schema - postgres + sequelize

I am using postgres + sequelize我正在使用 postgres + sequelize

const db = //db connection stuffs....

db.authenticate().then((err) => {
  if (err) {
    console.log('There is connection in ERROR.');
  } else {
    console.log('Postgres Client App Connection has been established successfully');
  }
});

db.sync().then(() => {
  console.log('Psql Client App Missing Table Created');
}, (err) => {
  console.log('An error occurred while creating postgres client app table:', err.message);
});

For example i have multiple schemas例如我有多个模式

  1. Public (default schema)公共(默认架构)
  2. tenant1租户 1
  3. tenant2 .租户2。 . . . . . .
  4. tenant100租户100

I have table called users in my all schemas including public schema我的所有架构中都有名为 users 的表,包括公共架构

I want to add extra column in my user table我想在我的用户表中添加额外的列

After adding column using添加列后使用

ALTER TABLE ADD COLUMN.. more from postgres docs. ALTER TABLE ADD COLUMN .. 更多来自 postgres 文档。

inside my code, i run my project with the help of this below code:在我的代码中,我在以下代码的帮助下运行我的项目:

db.sync({ force: true }).then(() => {
  console.log('Psql Client App Missing Table Created');
}, (err) => {
  console.log('An error occurred while creating postgres client app table:', err.message);
});

//This will successfully added my column on the table inside public schema, without data loss. //这将成功地将我的列添加到公共架构内的表中,而不会丢失数据。

But my tables inside other schemas does not changed.但是我在其他模式中的表没有改变。

How to change that to all schemas?如何将其更改为所有模式?

By postgres i can do Alter table tenant1.users ...bla..bla , but how to do with sequelize?通过 postgres 我可以做 Alter table tenant1.users ...bla..bla ,但是如何处理 sequelize 呢?

Also i dont want to lose my datas.我也不想丢失我的数据。

I finally did this using migrations in sequelize我终于在 sequelize 中使用迁移来做到这一点

http://docs.sequelizejs.com/manual/tutorial/migrations.html http://docs.sequelizejs.com/manual/tutorial/migrations.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM