节点正确运行迁移文件,但表未在 postgresql 中显示

问题描述 投票:0回答:0

我有一个非常简单的迁移文件。它包括

exports.up = (pgm) => {
    pgm.sql(`
        CREATE TABLE public.comments (
            id SERIAL PRIMARY KEY,
            created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
            updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
            contents VARCHAR(240) NOT NULL
            );
        `);
};

exports.down = (pgm) => {
    pgm.sql(`
        DROP TABLE comments; 
    `);
};

当我运行迁移时,它运行成功

% DATABASE_url=postgres://hrushi@localhost:5432/socialnetwork npm run migrate up  

> [email protected] migrate
> node-pg-migrate up

> Migrating files:
> - 1679060101968_table-comments
### MIGRATION 1679060101968_table-comments (UP) ###

        CREATE TABLE comments (
            id SERIAL PRIMARY KEY,
            created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
            updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
            contents VARCHAR(240) NOT NULL
            );
        ;
INSERT INTO "public"."pgmigrations" (name, run_on) VALUES ('1679060101968_table-comments', NOW());


Migrations complete!

上面这个命令的一个非常奇怪的事情是即使我们输入一些乱码它仍然有效:

DATABASE_url=postgres://hrushi@localhostssssss:5432/socialnetafafafwork npm run migrate up

> [email protected] migrate
> node-pg-migrate up

> Migrating files:
> - 1679060101968_table-comments
### MIGRATION 1679060101968_table-comments (UP) ###

        CREATE TABLE public.comments (
            id SERIAL PRIMARY KEY,
            created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
            updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
            contents VARCHAR(240) NOT NULL
            );
        ;
INSERT INTO "public"."pgmigrations" (name, run_on) VALUES ('1679060101968_table-comments', NOW());


Migrations complete!

但是没有创建表。当我 psql 进入我的数据库并检查我没有找到的表时。同样,我也没有在 pgadmin 中找到它们。:

% psql -U hrushi -h localhost -d socialnetwork
SELECT current_schema();
 current_schema 
----------------
 public
(1 row)

socialnetwork=# \dn
      List of schemas
  Name  |       Owner       
--------+-------------------
 public | pg_database_owner
(1 row)

socialnetwork=# \connect socialnetwork
You are now connected to database "socialnetwork" as user "hrushi".
socialnetwork=# \dt
Did not find any relations.

跑步

SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';

给我

"table_catalog" "table_schema"  "table_name"    "table_type"
"hrushi"    "public"    "comments"  "BASE TABLE"
node.js postgresql database-migration
© www.soinside.com 2019 - 2024. All rights reserved.