aws / aws-sdk-ruby-record

Official repository for the aws-record gem, an abstraction for Amazon DynamoDB.
Apache License 2.0
318 stars 41 forks source link

Table Migrations? #45

Closed fullyallocated closed 7 years ago

fullyallocated commented 7 years ago

Hi Alex! I'm back again with another question, this time regarding table migrations. Let's say that I have a model defined called Student with a grade_level (integer, partition key) and a user_uuid (string, range_key):

class Student
  include Aws::Record
  integer_attr :grade_level, hash_key: true
  string_attr :user_uuid, range_key: true
end

I want to add a list of classes to each student, but I can't do so! Lets say I want to update a student:

student = Student.find(grade_level: 10, user_uuid: abfag-1234-fhasdf)
student.classes = ["Spanish", "English"]
student.update!

returns an error: undefined method 'classes='

This makes sense, of course, as the point of the ORM abstraction is a way to bring some structure to models so they aren't random sets of key value pairs all over the tables. My guess is that I'm supposed to migrate the Students table to add an attribute? I went to check the documentation and the #update method said to defer to the AWS-SDK V2 documentation, which brought me this:

#update_table(options = {}) ⇒ Types::UpdateTableOutput

Modifies the provisioned throughput settings, global secondary indexes, or DynamoDB Streams settings for a given table. 

source: (https://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Client.html#update_table-instance_method)

I can't find anywhere that tells me I can add/remove attributes from a table! It looks to me that the attribution CRUD operations rest in #update_item, as detailed:

#update_item(options = {}) ⇒ Types::UpdateItemOutput

Edits an existing item's attributes, or adds a new item to the table if it does not already exist. You can put, delete, or add attribute values. You can also perform a conditional update on an existing item (insert a new attribute name-value pair if it doesn't exist, or replace an existing name-value pair if it has certain expected attribute values). 

source: (https://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Client.html#update_item-instance_method).

I must be confused, because from my perspective, CRUD operations on models are handled on a per-item basis from the aws-sdk, but there's no setter method for models on the aws-record abstraction? Your help is greatly appreciated.