# Database: Schema Builder

- [Introduction](#introduction)
- [Tables](#tables)
    - [Creating tables](#creating-tables)
    - [Changing tables](#changing-tables)
    - [Renaming and dropping tables](#renaming-and-dropping-tables)
    - [Table options](#table-options)
- [Columns](#columns)
    - [Column types](#column-types)
    - [Column modifiers](#column-modifiers)
    - [Defaults](#defaults)
    - [Generated columns](#generated-columns)
    - [Changing columns](#changing-columns)
    - [Renaming and dropping columns](#renaming-and-dropping-columns)
- [Indexes](#indexes)
    - [Creating indexes](#creating-indexes)
    - [Renaming and dropping indexes](#renaming-and-dropping-indexes)
- [Foreign keys](#foreign-keys)
    - [Turning foreign key checks off](#turning-foreign-key-checks-off)
- [Check constraints](#check-constraints)
- [Vector columns](#vector-columns)
- [Changing large tables](#changing-large-tables)
- [Inspecting the schema](#inspecting-the-schema)

<a name="introduction"></a>

## Introduction


데이터베이스 엔진마다 `CREATE TABLE`과 `ALTER TABLE`의 DDL 문법이 조금씩 다르므로 PostgreSQL용 원시 스키마 SQL이 로컬 테스트의 SQLite에서는 실패할 수 있습니다. Laravel 스키마 빌더는 Rust로 테이블, 컬럼, 인덱스를 한 번 정의하면 PostgreSQL, MySQL, MariaDB, SQLite에 맞는 SQL을 생성합니다.


대부분의 스키마 변경은 [migrations](/rust/docs/migrations) 안에 둡니다. 마이그레이션의 트랜잭션에서 `schema()`를 호출해 테이블을 생성하거나 변경할 수 있습니다.

```rust
// database/migrations/2026_10_27_143000_create_posts_table.rs
use laravel::db::AnyTransaction;

pub async fn migrate(tx: &mut AnyTransaction<'_>) -> laravel::Result<()> {
    tx.schema()
        .create("posts", |table| {
            table.id();
            table.foreign_id("user_id").constrained().cascade_on_delete();
            table.string("title");
            table.string("slug").unique();
            table.text("body").nullable();
            table.timestamp("published_at").nullable();
            table.timestamps();

            table.index(["user_id", "published_at"]);
        })
        .await
}
```


각 스키마 작업은 `.await`할 때 실행되므로 마이그레이션의 `migrate` 함수에서 구문을 추가할 때마다 `tx.schema()`를 다시 호출하세요.

```rust
tx.schema().drop_if_exists("drafts").await?;
tx.schema().rename("articles", "posts").await?;
```


스키마 작업을 실행하지 않고 SQL만 확인하려면 await 대신 `to_sql()`을 호출하세요.

<a name="tables"></a>

## Tables

<a name="creating-tables"></a>

### Creating tables


새 데이터베이스 테이블을 만들려면 `create`에 테이블 이름과 클로저를 전달하세요. 클로저가 받는 `Blueprint` 인스턴스로 컬럼, 인덱스, 제약 조건을 정의할 수 있습니다.

```rust
tx.schema()
    .create("flights", |table| {
        table.id();
        table.string("name");
        table.string("airline");
        table.timestamps();
    })
    .await?;
```

<a name="changing-tables"></a>

### Changing tables


기존 테이블을 변경하려면 테이블 이름과 `Blueprint` 클로저로 `alter`를 호출하세요. `alter` 안에서 컬럼을 정의하면 테이블에 추가하며, `rename_column`이나 `drop_column`은 기존 컬럼을 수정합니다.

```rust
tx.schema()
    .alter("users", |table| {
        table.integer("votes").default(0);
        table.rename_column("bio", "about");
        table.drop_column("legacy_flags");
    })
    .await?;
```


SQLite는 컬럼 타입 변경이나 외래 키 추가 같은 일부 작업을 제자리에서 수행할 수 없습니다. 이 경우 Laravel이 행과 인덱스를 보존하면서 테이블을 자동으로 재구성합니다.

<a name="renaming-and-dropping-tables"></a>

### Renaming and dropping tables


테이블 이름 변경은 `rename`, 테이블과 데이터 삭제는 `drop`이나 `drop_if_exists`를 사용하세요.

```rust
tx.schema().rename("posts", "articles").await?;
tx.schema().drop("articles").await?;
tx.schema().drop_if_exists("drafts").await?;
```


테이블이 없으면 `drop`은 오류를 반환하지만 `drop_if_exists`는 별도 알림 없이 성공합니다. 테이블 이름을 바꿔도 `posts_user_id_foreign` 같은 기존 인덱스나 외래 키 이름은 바뀌지 않으므로 나중에 삭제할 때 원래 이름으로 참조하세요.

<a name="table-options"></a>

### Table options


`create` 안에서 다음 테이블 옵션을 설정할 수 있습니다. MySQL과 MariaDB는 모두 적용하고, 다른 데이터베이스는 지원하지 않는 옵션을 무시합니다.

| 메서드 | 효과 |
| --- | --- |
| `table.temporary()` | 현재 데이터베이스 세션에만 보이는 임시 테이블 생성 |
| `table.engine("InnoDB")` | MySQL과 MariaDB의 저장 엔진 설정 |
| `table.charset("utf8mb4")` | MySQL과 MariaDB의 기본 문자 집합 설정 |
| `table.collation("utf8mb4_unicode_ci")` | MySQL과 MariaDB의 기본 정렬 규칙 설정 |
| `table.comment("Blog posts")` | PostgreSQL, MySQL, MariaDB에서 주석 추가. `alter`에서도 사용 가능 |

<a name="columns"></a>

## Columns

<a name="column-types"></a>

### Column types


스키마 빌더는 테이블 블루프린트에 일반적인 모든 컬럼 타입을 추가하는 메서드를 제공합니다. `()`로 표시한 경우를 제외하면 각 메서드는 컬럼 이름을 받습니다.

| 메서드 | 컬럼 |
| --- | --- |
| `id()` | `id`라는 자동 증가 큰 정수 기본 키 |
| `increments`, `big_increments`, `medium_increments`, `small_increments`, `tiny_increments` | 해당 크기의 자동 증가 정수 기본 키 |
| `integer`, `big_integer`, `medium_integer`, `small_integer`, `tiny_integer` | 해당 크기의 정수 |
| `float`, `double` | 부동소수점 수 |
| `decimal(name, total, places)` | 전체 `total`자리 중 소수점 아래 `places`자리인 정확한 십진수 |
| `boolean` | 불리언 |
| `char`, `string` | 최대 255자 텍스트. `.length(n)`으로 다른 길이 지정 |
| `tiny_text`, `text`, `medium_text`, `long_text` | 긴 텍스트. MySQL과 MariaDB만 크기를 구분 |
| `enumeration(name, ["draft", "published"])` | 나열한 허용값으로 제한한 텍스트 |
| `set(name, values)` | MySQL과 MariaDB의 `set` |
| `json`, `jsonb` | JSON 문서. PostgreSQL만 `jsonb`를 구분 |
| `date`, `time`, `time_tz` | 달력 날짜 또는 하루 중 시각. PostgreSQL만 `time_tz`의 시간대 저장 |
| `date_time` | 어디서든 9시에 하는 약속처럼 시간대 없는 현지 날짜와 시각 |
| `timestamp` | Laravel이 UTC로 쓰는 한 시점. PostgreSQL은 `timestamp`, MySQL·MariaDB·SQLite는 `datetime` |
| `timestamps()` | nullable인 `created_at`과 `updated_at` 타임스탬프 |
| `soft_deletes()` | nullable인 `deleted_at` 타임스탬프 |
| `year` | 연도 |
| `binary` | 이진 데이터 |
| `uuid`, `ulid` | UUID 또는 ULID |
| `foreign_id`, `foreign_uuid`, `foreign_ulid` | 외래 키에 사용할 다른 테이블의 키([a foreign key](#foreign-keys)) |
| `ip_address`, `mac_address` | 텍스트로 저장한 네트워크 주소 |
| `geometry`, `geography` | 공간 값. PostgreSQL에는 PostGIS 확장 필요 |
| `vector(name, dimensions)` | [vector columns](#vector-columns)용 고정 길이 임베딩 |
| `morphs`, `uuid_morphs`, `ulid_morphs`와 각각의 `nullable_` 형태 | 두 컬럼을 함께 인덱싱하는 `{name}_type`과 `{name}_id` 컬럼 |
| `remember_token()` | nullable인 100자 `remember_token` |


각 컬럼은 [model](/rust/docs/models)이나 [`db::FromRow`](/rust/docs/database#mapping-rows-to-structs) 구조체에 매핑하든 지원하는 모든 데이터베이스에서 같은 Rust 타입으로 디코딩됩니다.

| 컬럼 | Rust 타입 |
| --- | --- |
| `id`, `foreign_id`와 정수 타입 | `i64` 또는 `i32` 같은 작은 정수 |
| `float`, `double` | `f64` |
| `decimal` | `laravel::numeric::Decimal` |
| `boolean` | `bool` |
| `char`, `string`, 텍스트 타입, `enumeration`, `set`, `mac_address` | `String` |
| `json`, `jsonb` | `serde_json::Value` 또는 `db::Json<T>`로 감싼 사용자 정의 타입 |
| `date` | `laravel::time::civil::Date` |
| `time`, `time_tz` | `laravel::time::civil::Time` |
| `timestamps()`, `soft_deletes()`와 그 밖의 날짜·시각 타입 | `laravel::time::Timestamp` 또는 현지 시각용 `civil::DateTime` |
| `year` | `i32` |
| `binary` | `Vec<u8>` |
| `uuid`, `foreign_uuid` | `laravel::str::Uuid` |
| `ulid`, `foreign_ulid` | `laravel::str::Ulid` |
| `ip_address` | `std::net::IpAddr` |
| `vector` | `laravel::db::Vector` |


컬럼에 `.nullable()`을 지정하면 해당 Rust 필드 타입을 `Option<T>`로 감싸세요.

<a name="column-modifiers"></a>

### Column modifiers


컬럼은 기본적으로 `NOT NULL`입니다. 컬럼 수정자를 연결해 정의를 조정하세요.

```rust
tx.schema()
    .alter("users", |table| {
        table.string("nickname").length(50).nullable().comment("Shown next to posts");
    })
    .await?;
```

| 수정자 | 효과 |
| --- | --- |
| `.nullable()` | NULL 허용 |
| `.default(value)` | 삽입 시 생략된 컬럼의 [default value](#defaults) 설정 |
| `.use_current()` | 날짜·시각 컬럼의 기본값을 현재 시각으로 지정 |
| `.use_current_on_update()` | MySQL과 MariaDB에서 행이 바뀔 때마다 타임스탬프를 현재 시각으로 설정 |
| `.stored_as(expr)`, `.virtual_as(expr)` | [generated column](#generated-columns) 정의 |
| `.unsigned()` | MySQL과 MariaDB에서 정수를 부호 없는 타입으로 지정 |
| `.auto_increment()` | 정수를 자동 증가로 지정하며 기본 키로도 설정 |
| `.starting_value(1000)` | PostgreSQL, MySQL, MariaDB에서 자동 증가 컬럼의 첫 값 지정 |
| `.length(n)` | `string`, `char`, `binary` 컬럼의 길이 설정 |
| `.precision(n)` | 연결의 [time precision](/rust/docs/database#time-precision)을 재정의해 시각 컬럼의 초 소수 자릿수를 지정하거나 부동소수점 비트 수 설정 |
| `.comment(text)` | PostgreSQL, MySQL, MariaDB에서 주석 추가 |
| `.charset(name)`, `.collation(name)` | MySQL과 MariaDB에서 텍스트 컬럼의 문자 집합 설정 또는 정렬 규칙 설정 |
| `.after(column)`, `.first()` | MySQL과 MariaDB에서 새 컬럼 위치 지정 |
| `.invisible()` | MySQL과 MariaDB에서 `select *` 대상에서 컬럼 제외 |
| `.instant()`, `.lock(Lock::None)` | MySQL과 MariaDB에서 행을 복사하거나 쓰기를 차단하지 않고 [large tables](#changing-large-tables) 변경 |
| `.primary()`, `.unique()`, `.index()`, `.full_text()`, `.spatial_index()` | 컬럼에 [index](#indexes) 추가 |


MySQL과 MariaDB에서 특정 컬럼 뒤에 여러 컬럼을 추가하려면 `table.after(column, |table| { .. })` 안에 정의하세요. 각 컬럼은 바로 앞 컬럼 뒤에 배치됩니다.

```rust
table.after("password", |table| {
    table.string("address_line1");
    table.string("address_line2").nullable();
    table.string("city");
});
```

<a name="defaults"></a>

### Defaults


삽입할 때 컬럼을 생략하면 기본값이 채워집니다. `.default`는 리터럴 값이나 원시 표현식을 받습니다. `0`, `false`, `"draft"` 같은 리터럴 값은 현재 데이터베이스에 맞게 이스케이프하고, `db::raw!` 표현식은 그대로 출력합니다.

```rust
use laravel::db;

tx.schema()
    .create("flights", |table| {
        table.id();
        table.string("status").default("scheduled");
        table.integer("seats").default(180);
        table.boolean("international").default(false);
        table.json("movies").default("[]");
        table.date("booked_on").default(db::raw!("current_date"));
    })
    .await?;
```


필드에 [`#[default]`](/rust/docs/models#table-and-column-names)를 붙이면 모델이 컬럼의 데이터베이스 기본값을 읽습니다.

<a name="generated-columns"></a>

### Generated columns


생성 컬럼은 같은 행의 다른 컬럼에서 값을 자동 계산합니다. `col`로 만든 표현식을 `stored_as` 또는 `virtual_as`에 전달하세요.

```rust
use laravel::db::col;

tx.schema()
    .create("line_items", |table| {
        table.id();
        table.integer("price");
        table.integer("quantity");
        table.integer("total").stored_as(col("price") * col("quantity"));
    })
    .await?;
```


`stored_as`는 행을 삽입하거나 갱신할 때 값을 계산하고 저장합니다. `virtual_as`는 읽을 때 계산하며 PostgreSQL에서는 18 이상이 필요합니다.

<a name="changing-columns"></a>

### Changing columns


기존 컬럼의 타입이나 속성을 바꾸려면 `alter` 안에서 다시 정의하고 `.change()`를 연결하세요.

```rust
tx.schema()
    .alter("users", |table| {
        table.string("name").length(100).nullable().change();
    })
    .await?;
```


`.change()`는 컬럼의 전체 정의를 대체하므로 유지할 모든 수정자를 포함해야 합니다. 생략한 수정자는 제거됩니다. 예를 들어 `.nullable()`을 생략하면 nullable 컬럼이 `NOT NULL`로 돌아갑니다.


PostgreSQL에서 컬럼 타입 변경에 명시적 cast가 필요하면 `.using(...)`을 연결해 기존 값을 변환하세요.

```rust
use laravel::db;

table.date("birthday").change().using(db::raw!("birthday::date"));
```

<a name="renaming-and-dropping-columns"></a>

### Renaming and dropping columns


기존 컬럼의 이름을 바꾸거나 삭제하려면 `alter` 안에서 `rename_column`과 `drop_column`을 사용하세요.

```rust
tx.schema()
    .alter("users", |table| {
        table.rename_column("bio", "about");
        table.drop_column(["legacy_flags", "legacy_notes"]);
    })
    .await?;
```


`drop_column`은 컬럼 이름 하나 또는 이름 목록을 받습니다. 복합 인덱스에서 컬럼을 삭제하면 MySQL과 MariaDB는 나머지 컬럼의 인덱스를 유지할 수 있습니다. 모든 데이터베이스에서 제거하려면 먼저 인덱스를 삭제하세요.


`drop_timestamps`, `drop_soft_deletes`, `drop_remember_token`, `drop_morphs`로 대응하는 헬퍼가 생성한 컬럼을 삭제할 수도 있습니다.

<a name="indexes"></a>

## Indexes

<a name="creating-indexes"></a>

### Creating indexes


인덱스를 사용하면 데이터베이스가 테이블 전체를 훑지 않고 일치하는 행을 찾으며, 고유 인덱스는 중복 값도 막습니다. 컬럼 수정자로 단일 컬럼에 인덱스를 추가하거나 블루프린트에서 여러 컬럼의 복합 인덱스를 정의할 수 있습니다.

```rust
tx.schema()
    .create("users", |table| {
        table.id();
        table.string("email").unique();
        table.foreign_id("team_id");
        table.timestamps();

        table.index(["team_id", "created_at"]);
    })
    .await?;
```

| 메서드 | 인덱스 |
| --- | --- |
| `primary(columns)` | 기본 키 |
| `unique(columns)` | 고유 인덱스 |
| `index(columns)` | 인덱스 |
| `full_text(columns)` | PostgreSQL, MySQL, MariaDB에서 [`db::search`](/rust/docs/queries#full-text-search)용 전문 검색 인덱스 |
| `spatial_index(columns)` | SQLite를 제외한 공간 인덱스 |
| `vector_index(column)` | [vector columns](#vector-columns)용 코사인 거리 인덱스 |


Laravel은 `users_email_unique`나 `users_team_id_created_at_index`처럼 `{table}_{columns}_{kind}` 규칙으로 인덱스 이름을 생성합니다. `.name(..)`으로 직접 이름을 지정할 수 있습니다.

```rust
table.unique(["team_id", "email"]).name("users_team_email_unique");
```


PostgreSQL의 `jsonb` 컬럼용 `gin`처럼 특정 인덱스 알고리즘을 선택하려면 `.algorithm(..)`을 연결하세요.

```rust
table.index("attributes").algorithm("gin");
```


PostgreSQL의 전문 검색 인덱스는 기본적으로 `english` 텍스트 검색 설정을 사용합니다. 다른 설정을 사용하려면 인덱스에 `.language("simple")`을 연결하고 [`db::search`](/rust/docs/queries#full-text-search)에도 같은 언어를 전달해 쿼리가 인덱스를 사용할 수 있게 하세요.

<a name="renaming-and-dropping-indexes"></a>

### Renaming and dropping indexes


인덱스를 삭제하려면 명시적 이름이나 Laravel이 규칙에 따라 이름을 추론할 수 있도록 인덱스 컬럼 목록을 전달하세요.

```rust
tx.schema()
    .alter("users", |table| {
        table.drop_unique(["email"]);
        table.drop_index("users_team_id_created_at_index");
        table.rename_index("users_name_index", "users_display_name_index");
    })
    .await?;
```


블루프린트는 `drop_index`, `drop_unique` 외에 `drop_full_text`, `drop_spatial_index`, `drop_vector_index`, `drop_primary()`도 제공합니다. 테이블의 기본 키는 하나뿐이므로 마지막 메서드는 인수를 받지 않습니다.

<a name="foreign-keys"></a>

## Foreign keys


외래 키 제약 조건은 테이블 간 참조 무결성을 강제합니다. `constrained`는 컬럼 이름으로 참조 테이블을 추론하므로 `user_id`는 자동으로 `users`의 `id`를 참조합니다.

```rust
tx.schema()
    .create("posts", |table| {
        table.id();
        table.foreign_id("user_id").constrained().cascade_on_delete();
    })
    .await?;
```


특정 테이블은 `references`, `id` 외의 컬럼은 `.column(..)`, 복합 키는 `foreign`으로 지정합니다. `constrained`와 `references`는 빌더를 외래 키 제약 조건으로 전환하므로 `.nullable()` 같은 컬럼 수정자는 그 전에 연결하세요.

```rust
table.foreign_id("author_id").nullable().references("users").null_on_delete();
table.foreign_uuid("team_uuid").references("teams").column("uuid");
table.foreign(["order_number"]).references("orders", ["number"]).cascade_on_update();
```


다음 메서드로 삭제와 갱신 동작을 설정합니다.

| 메서드 | 효과 |
| --- | --- |
| `cascade_on_delete()`, `cascade_on_update()` | 행을 삭제하거나 키 변경 |
| `restrict_on_delete()`, `restrict_on_update()` | 변경 거부 |
| `null_on_delete()`, `null_on_update()` | 키를 NULL로 설정 |
| `no_action_on_delete()`, `no_action_on_update()` | 구문 종료 시 검사하여 변경 거부 |


Laravel은 `posts_user_id_foreign`처럼 `{table}_{columns}_foreign` 규칙으로 외래 키 이름을 생성하며 `.name(..)`으로 직접 지정할 수도 있습니다. 이름이나 컬럼으로 외래 키를 삭제하거나 `drop_constrained_foreign_id`로 제약 조건과 컬럼을 한 번에 삭제할 수 있습니다.

```rust
table.drop_foreign("posts_user_id_foreign");
table.drop_foreign(["user_id"]);
table.drop_constrained_foreign_id("author_id");
```

<a name="turning-foreign-key-checks-off"></a>

### Turning foreign key checks off


연관된 테이블을 비우거나 시딩할 때 외래 키 제약 조건으로 실행 순서가 까다로워질 수 있습니다. `without_foreign_key_constraints`는 외래 키 검사를 끈 트랜잭션에서 콜백을 실행하고, 콜백이 오류를 반환해도 트랜잭션이 끝나면 검사를 자동 복원합니다. 시더나 콘솔 명령어에서처럼 연결의 스키마에 호출하세요.

```rust
use laravel::db;

db::default_connection()?
    .schema()
    .without_foreign_key_constraints(async |_| {
        db::table("posts").truncate().await?;
        db::table("users").truncate().await
    })
    .await?;
```


PostgreSQL과 SQLite에서는 커밋 전에 모든 외래 키 참조가 다시 유효해야 합니다. SQLite는 커밋 시 모든 참조를 검사하고 PostgreSQL은 `.deferrable()`로 생성한 외래 키의 검사만 미룹니다.

<a name="check-constraints"></a>

## Check constraints


체크 제약 조건은 제품 가격이 음수가 될 수 없다는 것처럼 테이블에 쓰는 모든 행에 조건을 강제합니다. 이를 위반하는 삽입이나 갱신은 데이터베이스가 거부합니다. [query builder condition API](/rust/docs/queries#conditions)로 표현식을 작성하세요.

```rust
use laravel::db::col;

tx.schema()
    .create("products", |table| {
        table.id();
        table.decimal("price", 8, 2);
        table.check("products_price_check", col("price").ge(0));
    })
    .await?;
```


기존 체크 제약 조건을 제거하려면 `table.drop_check("products_price_check")`를 호출하세요.

<a name="vector-columns"></a>

## Vector columns


벡터 컬럼은 [vector similarity](/rust/docs/queries#vector-similarity) 쿼리용 고정 길이 임베딩을 저장합니다. PostgreSQL(`pgvector` 확장 필요)과 MariaDB 11.7 이상에서 지원합니다. PostgreSQL 서버에 `pgvector`를 설치한 뒤 `ensure_vector_extension`으로 데이터베이스에 활성화하세요. MariaDB는 벡터를 기본 지원하므로 이 호출을 생략합니다.

```rust
use laravel::db::Driver;

if tx.driver() == Driver::Postgres {
    tx.schema().ensure_vector_extension().await?;
}

tx.schema()
    .create("documents", |table| {
        table.id();
        table.string("title");
        table.vector("embedding", 3).index();
    })
    .await?;
```


임베딩 모델이 반환하는 차원 수를 사용하세요. 이 예제는 [vector similarity example](/rust/docs/queries#vector-similarity)의 3차원 임베딩을 사용합니다.


`vector` 컬럼에 `.index()`를 직접 연결하면 코사인 거리 벡터 인덱스를 자동 생성합니다. PostgreSQL에서는 `vector_cosine_ops`를 사용하는 HNSW, MariaDB에서는 `VECTOR INDEX ... DISTANCE=cosine`입니다. `alter`에서 기존 컬럼에 벡터 인덱스를 추가하려면 `table.index("embedding")` 대신 `table.vector_index("embedding")`을 호출하세요. MariaDB는 테이블당 벡터 컬럼 하나까지만 인덱싱하며 해당 컬럼은 `NOT NULL`이어야 합니다.

<a name="changing-large-tables"></a>

## Changing large tables


새 테이블에서 즉시 끝나는 변경도 데이터베이스가 행을 다시 쓰거나 쓰기를 잠그면 사용량이 많은 운영 테이블을 몇 분 동안 차단할 수 있습니다. 각 데이터베이스 엔진은 변경 중에도 테이블을 사용할 수 있도록 전용 옵션을 제공합니다.


PostgreSQL의 일반적인 인덱스 생성은 완료될 때까지 테이블 쓰기를 차단합니다. `.online()`을 연결하면 `CREATE INDEX CONCURRENTLY`를 생성해 쓰기를 계속할 수 있습니다. PostgreSQL은 트랜잭션 안에서 동시 인덱스 생성을 허용하지 않으므로 `&AnyConnection`을 받는 [non-transactional migration](/rust/docs/migrations#running-a-migration-without-a-transaction)에 두세요. 다른 데이터베이스는 `.online()`을 무시합니다.

```rust
use laravel::db::AnyConnection;

pub async fn migrate(db: &AnyConnection) -> laravel::Result<()> {
    db.schema()
        .alter("users", |table| {
            table.index("last_seen_at").online();
        })
        .await
}
```


MySQL과 MariaDB에서 `.instant()`를 연결하면 행을 복사하지 않고 테이블 메타데이터만 갱신해 컬럼을 추가·수정·삭제합니다. 컬럼, 인덱스, 외래 키에 `.lock(..)`을 연결하면 구문이 허용하는 잠금 수준을 제한합니다. `Lock::None`은 동시 읽기와 쓰기를, `Lock::Shared`는 동시 읽기를 허용합니다. 이 조건으로 작업할 수 없으면 테이블을 복사하거나 잠그는 대신 구문이 실패합니다. 다른 데이터베이스는 두 옵션을 무시합니다.

```rust
use laravel::db::schema::Lock;

tx.schema()
    .alter("orders", |table| {
        table.string("coupon").nullable().instant();
        table.index("coupon").lock(Lock::None);
    })
    .await?;
```

<a name="inspecting-the-schema"></a>

## Inspecting the schema


마이그레이션이나 콘솔 명령어에서 기존 테이블, 컬럼, 인덱스를 검사할 수 있습니다.

```rust
if !tx.schema().has_table("flights").await? {
    // ...
}

if tx.schema().has_column("users", "email").await? {
    // ...
}
```

| 메서드 | 반환값 |
| --- | --- |
| `has_table(table)` | 테이블 존재 여부 |
| `has_column(table, column)`, `has_columns(table, columns)` | 해당 컬럼 또는 지정한 모든 컬럼의 존재 여부 |
| `has_index(table, index)`, `has_unique(table, index)` | 해당 이름 또는 해당 컬럼에 인덱스나 고유 인덱스가 있는지 여부 |
| `has_view(view)` | 뷰 존재 여부 |
| `tables()`, `views()`, `types()` | 데이터베이스의 테이블, 뷰, PostgreSQL 타입 |
| `columns(table)`, `indexes(table)`, `foreign_keys(table)` | 테이블의 컬럼, 인덱스, 외래 키 |


컬럼 타입 이름과 기본값 표현식은 각 엔진의 고유 형식으로 반환하므로 PostgreSQL, MySQL, MariaDB, SQLite마다 다릅니다.