[**Documentation**](../../../../README)

***

[Documentation](../../../../README) / [@zerotal/orm](../../README) / [index](../README) / Schema

# Variable: Schema

> `const` **Schema**: `object`

Defined in: [packages/orm/src/schema/Schema.ts:60](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/orm/src/schema/Schema.ts#L60)

The schema-builder facade — the entry point used inside migration `up()`/`down()`
methods to issue DDL against the active `Bun.sql` connection.

Each mutating helper constructs a [Blueprint](../classes/Blueprint), runs the caller's callback to
record the desired columns/indexes/constraints, compiles the blueprint to SQL,
and executes the statements. Introspection helpers ([Schema.hasTable](#hastable),
[Schema.hasColumn](#hascolumn)) are dialect-aware and use bound parameters.

## Type Declaration

### create()

> **create**(`table`, `callback`): `Promise`\<`void`\>

Create a table: `CREATE TABLE table_name ( … )`.

#### Parameters

##### table

`string`

Table name.

##### callback

(`bp`) => `void`

Receives a [Blueprint](../classes/Blueprint) to define columns/indexes/constraints.

#### Returns

`Promise`\<`void`\>

#### Throws

Rejects if the table already exists — use [Schema.createIfNotExists](#createifnotexists)
for idempotent runs.

### createIfNotExists()

> **createIfNotExists**(`table`, `callback`): `Promise`\<`void`\>

Idempotent create: `CREATE TABLE IF NOT EXISTS table_name ( … )` followed by
each index statement. Safe to run repeatedly.

#### Parameters

##### table

`string`

##### callback

(`bp`) => `void`

#### Returns

`Promise`\<`void`\>

### table()

> **table**(`name`, `callback`): `Promise`\<`void`\>

Modify an existing table: `ALTER TABLE ADD COLUMN / DROP COLUMN /
RENAME COLUMN` plus `CREATE INDEX IF NOT EXISTS`. The blueprint is compiled
for the connection's active dialect (see [Blueprint.toAlterSQL](../classes/Blueprint#toaltersql)).

#### Parameters

##### name

`string`

##### callback

(`bp`) => `void`

#### Returns

`Promise`\<`void`\>

### drop()

> **drop**(`table`): `Promise`\<`void`\>

`DROP TABLE table_name`

#### Parameters

##### table

`string`

#### Returns

`Promise`\<`void`\>

### dropIfExists()

> **dropIfExists**(`table`): `Promise`\<`void`\>

`DROP TABLE IF EXISTS table_name`

#### Parameters

##### table

`string`

#### Returns

`Promise`\<`void`\>

### rename()

> **rename**(`from`, `to`): `Promise`\<`void`\>

`ALTER TABLE from RENAME TO to`

#### Parameters

##### from

`string`

##### to

`string`

#### Returns

`Promise`\<`void`\>

### hasTable()

> **hasTable**(`table`): `Promise`\<`boolean`\>

Returns true if the table exists in the current schema.
Dialect-aware: sqlite_master on SQLite, information_schema on
PostgreSQL/MySQL.

#### Parameters

##### table

`string`

#### Returns

`Promise`\<`boolean`\>

### hasColumn()

> **hasColumn**(`table`, `column`): `Promise`\<`boolean`\>

Returns true if `column` exists in `table`.
Dialect-aware: pragma_table_info() on SQLite, information_schema on
PostgreSQL/MySQL. All inputs are bound parameters — never inlined.

#### Parameters

##### table

`string`

##### column

`string`

#### Returns

`Promise`\<`boolean`\>

## Example

```ts
// Create
await Schema.create('users', (table) => {
  table.id();
  table.string('email').unique();
  table.timestamps();
});

// Alter
await Schema.table('users', (table) => {
  table.string('name').nullable();
});

// Drop
await Schema.drop('users');
```
