This sample shows how to create and use a very simple Cloud Spanner database with ActiveRecord. The database consists of two tables:
- Singers
- Albums
Albums references Singers with a foreign key.
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.
This sample will:
- Create the sample database by calling
rake db:migrate
. This will execute the migrations in the folderdb/migrate
. - Fill the sample database with some data by calling
rake db:seed
. This will execute the script indb/seeds.rb
. The seed script fills the database with 10 random singers and 30 random albums. - Run the
application.rb
file. This application will:- List all known singers and albums.
- Select a random singer and update the name of this singer.
- Select all singers whose last names start with an 'A'.
Run the application with the command
bundle exec rake run