Skip to content

Commit

Permalink
Rebuild alias on column rename (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
krumft authored Sep 30, 2023
1 parent 589ce1a commit 42ca008
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export class ColRef implements _Column {
// === do nasty things to rename column
this.replaceExpression(to, this.expression.type);
this.table.db.onSchemaChange();
this.table.selection.rebuild();
this.name = to;
return this;
}
Expand Down Expand Up @@ -237,4 +238,4 @@ export class ColRef implements _Column {
}
}

}
}
7 changes: 7 additions & 0 deletions src/tests/alter-table.queries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,11 @@ describe('Alter table', () => {
alter table users alter column email type jsonb;
create unique index users_by_email on users ((email->>'sha256'));`)
});

it('can insert values referring to renamed column', () => {
none(`create table test("id" integer not null default 1, "col" character varying, constraint "PK" primary key ("id"));
alter table test RENAME column "col" TO "newcol";
insert into test(id, newcol) values (default, '1') RETURNING "id";
`);
});
});

0 comments on commit 42ca008

Please sign in to comment.