Sha256: 66acfe8ce76ee80841914e419a7c2f0bdf87b7846904fef22aec799ae2a8b0fe

Contents?: true

Size: 1.36 KB

Versions: 24

Compression:

Stored size: 1.36 KB

Contents

# Sample - Migrations

This example shows the best way to execute migrations with the Spanner ActiveRecord adapter.

It is [strongly recommended](https://cloud.google.com/spanner/docs/schema-updates#best-practices) that you limit the
frequency of schema updates in Cloud Spanner, and that schema changes are batched together whenever possible. The
Spanner ActiveRecord adapter supports batching DDL statements together using the `connection.ddl_batch` method. This
method accepts a block of DDL statements that will be sent to Cloud Spanner as one batch. It is recommended that
migrations are grouped together in one or in a limited number of batches for optimal performance.

This example shows how to create three tables in one batch:

```ruby
# Execute the entire migration as one DDL batch.
connection.ddl_batch do
  create_table :singers do |t|
    t.string :first_name
    t.string :last_name
  end

  create_table :albums do |t|
    t.string :title
    t.references :singers
  end

  create_table :tracks do |t|
    t.string :title
    t.numeric :duration
    t.references :albums
  end
end
```

## Running the Sample

The sample will automatically start a Spanner Emulator in a docker container and execute the sample
against that emulator. The emulator will automatically be stopped when the application finishes.

Run the application with the command

```bash
bundle exec rake run
```

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
activerecord-spanner-adapter-2.1.0 examples/snippets/migrations/README.md
activerecord-spanner-adapter-2.0.0 examples/snippets/migrations/README.md
activerecord-spanner-adapter-1.8.0 examples/snippets/migrations/README.md
activerecord-spanner-adapter-1.6.3 examples/snippets/migrations/README.md
activerecord-spanner-adapter-1.6.2 examples/snippets/migrations/README.md
activerecord-spanner-adapter-1.6.1 examples/snippets/migrations/README.md
activerecord-spanner-adapter-1.6.0 examples/snippets/migrations/README.md
activerecord-spanner-adapter-1.5.1 examples/snippets/migrations/README.md
activerecord-spanner-adapter-1.5.0 examples/snippets/migrations/README.md
activerecord-spanner-adapter-1.4.4 examples/snippets/migrations/README.md
activerecord-spanner-adapter-1.4.3 examples/snippets/migrations/README.md
activerecord-spanner-adapter-1.4.2 examples/snippets/migrations/README.md
activerecord-spanner-adapter-1.4.1 examples/snippets/migrations/README.md
activerecord-spanner-adapter-1.4.0 examples/snippets/migrations/README.md
activerecord-spanner-adapter-1.3.1 examples/snippets/migrations/README.md
activerecord-spanner-adapter-1.2.2 examples/snippets/migrations/README.md
activerecord-spanner-adapter-1.2.1 examples/snippets/migrations/README.md
activerecord-spanner-adapter-1.2.0 examples/snippets/migrations/README.md
activerecord-spanner-adapter-1.1.0 examples/snippets/migrations/README.md
activerecord-spanner-adapter-1.0.1 examples/snippets/migrations/README.md