Skip to content

Commit

Permalink
Adds auto_increment_id_pkey
Browse files Browse the repository at this point in the history
  • Loading branch information
oss92 committed Mar 24, 2017
1 parent 21195ba commit 49da2bf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ types. An example collection map might be:
:meta:
:table: blog_posts
:timestamps: true
# :auto_increment_id_pkey: true
:extra_props: true
:filter:
category: travel
Expand Down Expand Up @@ -120,6 +121,9 @@ collection will be mapped to.

`:timestamps` adds the current timestamps to inserted data.

`:auto_increment_id_pkey:` add an auto increment id public key but COMPROMISES
uniqueness of data.

`:extra_props` determines the handling of
unknown fields in MongoDB objects -- more about that later.

Expand Down
14 changes: 12 additions & 2 deletions lib/mosql/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ def create_schema(db, drop_table=false)
end
end

primary_key keys
if meta[:auto_increment_id_pkey]
primary_key :id
else
primary_key keys
end

if meta[:timestamps]
column 'created_at', 'TIMESTAMP'
column 'updated_at', 'TIMESTAMP'
Expand Down Expand Up @@ -374,7 +379,12 @@ def primary_sql_key_for_ns(ns)
if ns[:meta][:composite_key]
keys = ns[:meta][:composite_key]
else
keys << ns[:columns].find {|c| c[:source] == '_id'}[:name]
key_fetcher = ns[:columns].find {|c| c[:source] == '_id'}
if key_fetcher
keys << key_fetcher[:name]
else
keys = [:id]
end
end

return keys
Expand Down
2 changes: 2 additions & 0 deletions lib/mosql/streamer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ def import_collection(ns, collection, filter)
end
end

log.info("[#{collection.name} (#{filter}) DONE] Imported #{total_count} rows")

unless batch.empty?
bulk_upsert(table, ns, batch)
end
Expand Down

0 comments on commit 49da2bf

Please sign in to comment.