Skip to content

egon-orm-workspace / egon-orm/migration / AlterTableBuilder

Interface: AlterTableBuilder ​

Defined in: core/src/migration/builder.ts:791

The t of m.alterTable(name, (t) => …): adds columns with the same methods as createTable, and modifies, removes and renames them.

Example ​

ts
m.alterTable("users", (t) => {
  t.text("nickname");
  t.modify("age", "bigint");
  t.remove("legacy_flag");
  t.rename("name", "full_name");
});

Extends ​

Methods ​

add() ​

ts
add(name, type): ColumnBuilder;

Defined in: core/src/migration/builder.ts:522

A column of any type: t.add("price", { kind: "decimal", precision: 10, scale: 2 }).

Parameters ​

name ​

string

type ​

ColumnType

Returns ​

ColumnBuilder

Throws ​

TypeError when the name or the type is not valid.

Inherited from ​

ColumnAdder.add


array() ​

ts
array(name, of): ColumnBuilder;

Defined in: core/src/migration/builder.ts:604

An array of of: t.array("tags", "text").

Parameters ​

name ​

string

of ​

ColumnType

Returns ​

ColumnBuilder

Inherited from ​

ColumnAdder.array


bigint() ​

ts
bigint(name): ColumnBuilder;

Defined in: core/src/migration/builder.ts:533

bigint.

Parameters ​

name ​

string

Returns ​

ColumnBuilder

Inherited from ​

ColumnAdder.bigint


binary() ​

ts
binary(name): ColumnBuilder;

Defined in: core/src/migration/builder.ts:569

bytea on Postgres.

Parameters ​

name ​

string

Returns ​

ColumnBuilder

Inherited from ​

ColumnAdder.binary


boolean() ​

ts
boolean(name): ColumnBuilder;

Defined in: core/src/migration/builder.ts:549

boolean.

Parameters ​

name ​

string

Returns ​

ColumnBuilder

Inherited from ​

ColumnAdder.boolean


custom() ​

ts
custom(name, sql): ColumnBuilder;

Defined in: core/src/migration/builder.ts:613

A column of a type named by trusted program text: t.custom("email", "citext").

Parameters ​

name ​

string

sql ​

string

Returns ​

ColumnBuilder

Throws ​

TypeError when sql is not a plain type name.

Inherited from ​

ColumnAdder.custom


date() ​

ts
date(name): ColumnBuilder;

Defined in: core/src/migration/builder.ts:574

date.

Parameters ​

name ​

string

Returns ​

ColumnBuilder

Inherited from ​

ColumnAdder.date


decimal() ​

ts
decimal(name, options?): ColumnBuilder;

Defined in: core/src/migration/builder.ts:543

numeric, with an optional precision and scale.

Parameters ​

name ​

string

options? ​
precision? ​

number

scale? ​

number

Returns ​

ColumnBuilder

Inherited from ​

ColumnAdder.decimal


enumText() ​

ts
enumText(name, values): ColumnBuilder;

Defined in: core/src/migration/builder.ts:685

A text column that only takes the given values, enforced by a check constraint named <table>_<column>_check. The values are written into the constraint as SQL literals.

Parameters ​

name ​

string

values ​

readonly string[]

Returns ​

ColumnBuilder

Throws ​

TypeError when values is not a non-empty array of strings without NUL.

Inherited from ​

ColumnAdder.enumText


float() ​

ts
float(name): ColumnBuilder;

Defined in: core/src/migration/builder.ts:538

double precision on Postgres.

Parameters ​

name ​

string

Returns ​

ColumnBuilder

Inherited from ​

ColumnAdder.float


id() ​

Call Signature ​

ts
id(options?): ColumnBuilder;

Defined in: core/src/migration/builder.ts:625

A key the database generates: bigserial primary key named id by default, or serial with { type: "integer" }. The options can come first when the column is named id: t.id({ type: "integer" }) is t.id("id", { type: "integer" }).

Parameters ​
options? ​

IdOptions

Returns ​

ColumnBuilder

Throws ​

TypeError when an option is unknown or has the wrong type, or when options come first and a second argument is given too.

Inherited from ​

ColumnAdder.id

Call Signature ​

ts
id(name?, options?): ColumnBuilder;

Defined in: core/src/migration/builder.ts:626

A key the database generates: bigserial primary key named id by default, or serial with { type: "integer" }. The options can come first when the column is named id: t.id({ type: "integer" }) is t.id("id", { type: "integer" }).

Parameters ​
name? ​

string

options? ​

IdOptions

Returns ​

ColumnBuilder

Throws ​

TypeError when an option is unknown or has the wrong type, or when options come first and a second argument is given too.

Inherited from ​

ColumnAdder.id


integer() ​

ts
integer(name): ColumnBuilder;

Defined in: core/src/migration/builder.ts:528

integer.

Parameters ​

name ​

string

Returns ​

ColumnBuilder

Inherited from ​

ColumnAdder.integer


json() ​

ts
json(name): ColumnBuilder;

Defined in: core/src/migration/builder.ts:594

json.

Parameters ​

name ​

string

Returns ​

ColumnBuilder

Inherited from ​

ColumnAdder.json


jsonb() ​

ts
jsonb(name): ColumnBuilder;

Defined in: core/src/migration/builder.ts:599

jsonb. (The schema field builder t.json() is stored as jsonb.)

Parameters ​

name ​

string

Returns ​

ColumnBuilder

Inherited from ​

ColumnAdder.jsonb


modify() ​

ts
modify(
   name, 
   type, 
   options?
): void;

Defined in: core/src/migration/builder.ts:812

Changes a column's type and, optionally, its nullability and default.

Parameters ​

name ​

string

type ​

ColumnType

options? ​

ModifyOptions

Returns ​

void

Throws ​

TypeError when an argument is not valid.


references() ​

ts
references(
   name, 
   table, 
   options?
): ColumnBuilder;

Defined in: core/src/migration/builder.ts:651

A column that references another table's key, with a foreign key constraint named <table>_<column>_fkey: t.references("author_id", "users").

Parameters ​

name ​

string

table ​

string

options? ​

ReferencesOptions

Returns ​

ColumnBuilder

Throws ​

TypeError when an option is unknown or has the wrong type.

Inherited from ​

ColumnAdder.references


remove() ​

ts
remove(name): void;

Defined in: core/src/migration/builder.ts:835

Drops a column.

Parameters ​

name ​

string

Returns ​

void

Throws ​

TypeError when the name is not valid.


rename() ​

ts
rename(from, to): void;

Defined in: core/src/migration/builder.ts:845

Renames a column.

Parameters ​

from ​

string

to ​

string

Returns ​

void

Throws ​

TypeError when a name is not valid.


string() ​

ts
string(name): ColumnBuilder;

Defined in: core/src/migration/builder.ts:559

text (another name for ColumnAdder.text, as the schema field builder calls it).

Parameters ​

name ​

string

Returns ​

ColumnBuilder

Inherited from ​

ColumnAdder.string


text() ​

ts
text(name): ColumnBuilder;

Defined in: core/src/migration/builder.ts:554

text.

Parameters ​

name ​

string

Returns ​

ColumnBuilder

Inherited from ​

ColumnAdder.text


time() ​

ts
time(name, options?): ColumnBuilder;

Defined in: core/src/migration/builder.ts:579

time, with an optional fractional-second precision.

Parameters ​

name ​

string

options? ​
precision? ​

number

Returns ​

ColumnBuilder

Inherited from ​

ColumnAdder.time


timestamp() ​

ts
timestamp(name, options?): ColumnBuilder;

Defined in: core/src/migration/builder.ts:584

A timestamp without a time zone, with an optional fractional-second precision.

Parameters ​

name ​

string

options? ​
precision? ​

number

Returns ​

ColumnBuilder

Inherited from ​

ColumnAdder.timestamp


timestamps() ​

ts
timestamps(options?): void;

Defined in: core/src/migration/builder.ts:711

created_at and updated_at: timestamptz not null default now().

Parameters ​

options? ​

TimestampsColumnsOptions

Returns ​

void

Throws ​

TypeError when an option is unknown or has the wrong type.

Inherited from ​

ColumnAdder.timestamps


timestamptz() ​

ts
timestamptz(name, options?): ColumnBuilder;

Defined in: core/src/migration/builder.ts:589

A timestamp with a time zone, with an optional fractional-second precision.

Parameters ​

name ​

string

options? ​
precision? ​

number

Returns ​

ColumnBuilder

Inherited from ​

ColumnAdder.timestamptz


uuid() ​

ts
uuid(name): ColumnBuilder;

Defined in: core/src/migration/builder.ts:564

uuid.

Parameters ​

name ​

string

Returns ​

ColumnBuilder

Inherited from ​

ColumnAdder.uuid