1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

RubyonJets×DynamoDBでstaging環境なのにテーブル名にstagというprefixが付かない

Posted at

現象

JETS_ENV=stagingの環境でmigrateを実行したところテーブル名が<project_name>-stag-<table_name>になるはずが、
prefixを付けずにテーブルを作成しようとしていた。
既にあるテーブルだったので作成できなかった。

$ jets dynamodb:migrate dynamodb/migrate/20210307142215-create_users_migration.rb
=>
Running database migrations
Calling create_table with params:
{:table_name=>"users", # ここがproject-stag-usersになっていない
 :key_schema=>
  [{:attribute_name=>"id", :key_type=>"HASH"},
   {:attribute_name=>"created_at", :key_type=>"RANGE"}],
 :attribute_definitions=>
  [{:attribute_name=>"id", :attribute_type=>"S"},
   {:attribute_name=>"created_at", :attribute_type=>"S"}],
 :billing_mode=>"PROVISIONED",
 :provisioned_throughput=>{:read_capacity_units=>5, :write_capacity_units=>5}}
Unable to create table: Table already exists: users

環境

dynamiteはRubyonJetsでDynamoDBを操作するためのgemです。

  • Ruby: 2.7.2
  • RubyonJets: 3.0.3
  • dynomite: 1.2.6

対応

config/dynamodb.ymlにstagingを追加してあげる

development:
  table_namespace: <%= Jets.config.table_namespace %>
  endpoint: http://localhost:8000

test:
  endpoint: http://localhost:8000
  table_namespace: <%= Jets.config.table_namespace %>

# ここに追加
staging:
  table_namespace: <%= Jets.config.table_namespace %>

production:
  table_namespace: <%= Jets.config.table_namespace %>

実行結果

prefixが付いて<project_name>-stag-<table_name>のようなテーブル名を作成することができました。

$ jets dynamodb:migrate dynamodb/migrate/20210307142215-create_users_migration.rb
=>
Running database migrations
Calling create_table with params:
{:table_name=>"project-stag-users",
 :key_schema=>
  [{:attribute_name=>"id", :key_type=>"HASH"},
   {:attribute_name=>"created_at", :key_type=>"RANGE"}],
 :attribute_definitions=>
  [{:attribute_name=>"id", :attribute_type=>"S"},
   {:attribute_name=>"created_at", :attribute_type=>"S"}],
 :billing_mode=>"PROVISIONED",
 :provisioned_throughput=>{:read_capacity_units=>5, :write_capacity_units=>5}}
DynamoDB Table: users Status: CREATING
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?