bigbroda 0.0.7 → 0.1.0.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +15 -0
  3. data/Gemfile +1 -0
  4. data/README.md +39 -21
  5. data/Rakefile +5 -2
  6. data/{google_bigquery.gemspec → bigbroda.gemspec} +2 -2
  7. data/gemfiles/rails_3.gemfile +20 -0
  8. data/gemfiles/rails_4.0.3.gemfile +20 -0
  9. data/gemfiles/rails_4.0.3.gemfile.lock +176 -0
  10. data/gemfiles/rails_4.1.gemfile +20 -0
  11. data/gemfiles/rails_4.1.gemfile.lock +182 -0
  12. data/gemfiles/rails_4.2.gemfile +20 -0
  13. data/gemfiles/rails_4.2.gemfile.lock +202 -0
  14. data/gemfiles/rails_4.gemfile +20 -0
  15. data/gemfiles/rails_4.gemfile.lock +176 -0
  16. data/lib/active_record/connection_adapters/bigquery_adapter.rb +32 -601
  17. data/lib/active_record/connection_adapters/rails_41.rb +607 -0
  18. data/lib/active_record/connection_adapters/rails_42.rb +628 -0
  19. data/lib/{google_bigquery → bigbroda}/auth.rb +3 -3
  20. data/lib/{google_bigquery → bigbroda}/client.rb +3 -3
  21. data/lib/{google_bigquery → bigbroda}/config.rb +1 -1
  22. data/lib/{google_bigquery → bigbroda}/dataset.rb +23 -23
  23. data/lib/{google_bigquery → bigbroda}/engine.rb +4 -4
  24. data/lib/{google_bigquery → bigbroda}/jobs.rb +28 -28
  25. data/lib/bigbroda/project.rb +16 -0
  26. data/lib/{google_bigquery → bigbroda}/railtie.rb +3 -3
  27. data/lib/{google_bigquery → bigbroda}/table.rb +19 -19
  28. data/lib/{google_bigquery → bigbroda}/table_data.rb +7 -7
  29. data/lib/bigbroda/version.rb +3 -0
  30. data/lib/bigbroda.rb +27 -0
  31. data/lib/generators/{google_bigquery → bigbroda}/install/install_generator.rb +2 -2
  32. data/lib/generators/templates/{bigquery.rb.erb → bigbroda.rb.erb} +1 -1
  33. data/spec/dummy/config/application.rb +1 -1
  34. data/spec/functional/adapter/adapter_spec.rb +40 -38
  35. data/spec/functional/auth_spec.rb +3 -3
  36. data/spec/functional/config_spec.rb +5 -5
  37. data/spec/functional/dataset_spec.rb +19 -19
  38. data/spec/functional/project_spec.rb +4 -4
  39. data/spec/functional/table_data_spec.rb +13 -13
  40. data/spec/functional/table_spec.rb +30 -30
  41. data/spec/spec_helper.rb +2 -2
  42. metadata +32 -20
  43. data/lib/google_bigquery/project.rb +0 -16
  44. data/lib/google_bigquery/version.rb +0 -3
  45. data/lib/google_bigquery.rb +0 -27
@@ -3,7 +3,21 @@ require 'active_record/connection_adapters/statement_pool'
3
3
  require 'active_record/connection_adapters/abstract/schema_statements'
4
4
  require 'arel/visitors/bind_visitor'
5
5
 
6
+
6
7
  module ActiveRecord
8
+ module BigQueryRailsHelpers
9
+ def self.rails40?
10
+ ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 0
11
+ end
12
+
13
+ def self.rails41?
14
+ ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 1
15
+ end
16
+
17
+ def self.rails42?
18
+ ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 2
19
+ end
20
+ end
7
21
 
8
22
  module Error
9
23
  class Standard < StandardError; end
@@ -26,14 +40,14 @@ module ActiveRecord
26
40
  end
27
41
 
28
42
  module ConnectionHandling # :nodoc:
29
- # bigquery adapter reuses GoogleBigquery::Auth.
43
+ # bigquery adapter reuses BigBroda::Auth.
30
44
  def bigquery_connection(config)
31
45
 
32
46
  # Require database.
33
47
  unless config[:database]
34
48
  raise ArgumentError, "No database file specified. Missing argument: database"
35
49
  end
36
- db = GoogleBigquery::Auth.authorized? ? GoogleBigquery::Auth.client : GoogleBigquery::Auth.new.authorize
50
+ db = BigBroda::Auth.authorized? ? BigBroda::Auth.client : BigBroda::Auth.new.authorize
37
51
  #db #quizas deberia ser auth.api o auth.client
38
52
 
39
53
  #In case we are using a bigquery adapter as standard config in database.yml
@@ -61,6 +75,7 @@ module ActiveRecord
61
75
  extend ActiveSupport::Concern
62
76
  module ClassMethods
63
77
  def establish_bq_connection(path)
78
+ #raise "Rails Version not supported, please use Rails <= 4.1" if self.rails42?
64
79
  self.send :include, ActiveRecord::BigQueryPersistence
65
80
  self.send :include, ActiveRecord::BigQueryRelation
66
81
  self.send :include, ActiveRecord::BigQuerying
@@ -99,7 +114,7 @@ module ActiveRecord
99
114
  }]
100
115
  }
101
116
  conn_cfg = self.class.connection_config
102
- result = GoogleBigquery::TableData.create(conn_cfg[:project],
117
+ result = BigBroda::TableData.create(conn_cfg[:project],
103
118
  conn_cfg[:database],
104
119
  self.class.table_name ,
105
120
  @rows )
@@ -327,7 +342,7 @@ module ActiveRecord
327
342
  def bigquery_export(bucket_location = nil)
328
343
  bucket_location = bucket_location.nil? ? "#{table_name}.json" : bucket_location
329
344
  cfg = connection_config
330
- GoogleBigquery::Jobs.export(cfg[:project],
345
+ BigBroda::Jobs.export(cfg[:project],
331
346
  cfg[:database],
332
347
  table_name,
333
348
  "#{cfg[:database]}/#{bucket_location}")
@@ -337,7 +352,7 @@ module ActiveRecord
337
352
  bucket_location = bucket_location.empty? ? ["#{cfg[:database]}/#{table_name}.json"] : bucket_location
338
353
  cfg = connection_config
339
354
  fields = columns.map{|o| {name: o.name, type: o.sql_type, mode: "nullable" } }
340
- GoogleBigquery::Jobs.load(cfg[:project],
355
+ BigBroda::Jobs.load(cfg[:project],
341
356
  cfg[:database],
342
357
  table_name,
343
358
  bucket_location,
@@ -350,602 +365,18 @@ module ActiveRecord
350
365
  end
351
366
 
352
367
  ActiveRecord::Base.send :include, LoadOperations
368
+ end
353
369
 
354
- module ConnectionAdapters
355
-
356
-
357
- class BigqueryColumn < Column
358
- class << self
359
- TRUE_VALUES = [true, 1, '1', 'true', 'TRUE'].to_set
360
- FALSE_VALUES = [false, 0, '0','false', 'FALSE'].to_set
361
-
362
- def binary_to_string(value)
363
- if value.encoding != Encoding::ASCII_8BIT
364
- value = value.force_encoding(Encoding::ASCII_8BIT)
365
- end
366
- value
367
- end
368
-
369
- def string_to_time(string)
370
- return string unless string.is_a?(String)
371
- return nil if string.empty?
372
- fast_string_to_time(string) || fallback_string_to_time(string) || Time.at(string.to_f).send(Base.default_timezone)
373
- end
374
- end
375
- end
376
-
377
- class BigqueryAdapter < AbstractAdapter
378
-
379
- include SchemaStatements
380
-
381
- class Version
382
- end
383
-
384
- class ColumnDefinition < ActiveRecord::ConnectionAdapters::ColumnDefinition
385
- attr_accessor :array
386
- end
387
-
388
- class TableDefinition < ActiveRecord::ConnectionAdapters::TableDefinition
389
-
390
- def primary_key(name, type = :primary_key, options = {})
391
- return column name, :string, options
392
- end
393
-
394
- def record(*args)
395
- options = args.extract_options!
396
- column(:created_at, :record, options)
397
- end
398
-
399
- def timestamps(*args)
400
- options = args.extract_options!
401
- column(:created_at, :timestamp, options)
402
- column(:updated_at, :timestamp, options)
403
- end
404
-
405
- def references(*args)
406
- options = args.extract_options!
407
- polymorphic = options.delete(:polymorphic)
408
- index_options = options.delete(:index)
409
- args.each do |col|
410
- column("#{col}_id", :string, options)
411
- column("#{col}_type", :string, polymorphic.is_a?(Hash) ? polymorphic : options) if polymorphic
412
- index(polymorphic ? %w(id type).map { |t| "#{col}_#{t}" } : "#{col}_id", index_options.is_a?(Hash) ? index_options : {}) if index_options
413
- end
414
- end
415
-
416
- end
417
-
418
- class StatementPool < ConnectionAdapters::StatementPool
419
- def initialize(connection, max)
420
- super
421
- @cache = Hash.new { |h,pid| h[pid] = {} }
422
- end
423
-
424
- def each(&block); cache.each(&block); end
425
- def key?(key); cache.key?(key); end
426
- def [](key); cache[key]; end
427
- def length; cache.length; end
428
-
429
- def []=(sql, key)
430
- while @max <= cache.size
431
- dealloc(cache.shift.last[:stmt])
432
- end
433
- cache[sql] = key
434
- end
435
-
436
- def clear
437
- cache.values.each do |hash|
438
- dealloc hash[:stmt]
439
- end
440
- cache.clear
441
- end
442
-
443
- private
444
- def cache
445
- @cache[$$]
446
- end
447
-
448
- def dealloc(stmt)
449
- stmt.close unless stmt.closed?
450
- end
451
- end
452
-
453
- class BindSubstitution < Arel::Visitors::SQLite # :nodoc:
454
- include Arel::Visitors::BindVisitor
455
- end
456
-
457
- def initialize(connection, logger, config)
458
- super(connection, logger)
459
-
460
- @active = nil
461
- @statements = StatementPool.new(@connection,
462
- self.class.type_cast_config_to_integer(config.fetch(:statement_limit) { 1000 }))
463
- @config = config
464
-
465
- #if self.class.type_cast_config_to_boolean(config.fetch(:prepared_statements) { true })
466
- # @prepared_statements = true
467
- # @visitor = Arel::Visitors::SQLite.new self
468
- #else
469
- #use the sql without prepraded statements, as I know BQ doesn't support them.
470
- @visitor = unprepared_visitor
471
- end
472
-
473
- def adapter_name #:nodoc:
474
- 'BigQuery'
475
- end
476
-
477
- def supports_ddl_transactions?
478
- false
479
- end
480
-
481
- def supports_savepoints?
482
- false
483
- end
484
-
485
- def supports_partial_index?
486
- true
487
- end
488
-
489
- # Returns true, since this connection adapter supports prepared statement
490
- # caching.
491
- def supports_statement_cache?
492
- false
493
- end
494
-
495
- # Returns true, since this connection adapter supports migrations.
496
- def supports_migrations? #:nodoc:
497
- true
498
- end
499
-
500
- def supports_primary_key? #:nodoc:
501
- true
502
- end
503
-
504
- def requires_reloading?
505
- false
506
- end
507
-
508
- def supports_add_column?
509
- true
510
- end
511
-
512
- def active?
513
- @active != false
514
- end
515
-
516
- # Disconnects from the database if already connected. Otherwise, this
517
- # method does nothing.
518
- def disconnect!
519
- super
520
- @active = false
521
- @connection.close rescue nil
522
- end
523
-
524
- # Clears the prepared statements cache.
525
- def clear_cache!
526
- @statements.clear
527
- end
528
-
529
- def supports_index_sort_order?
530
- true
531
- end
532
-
533
- # Returns true
534
- def supports_count_distinct? #:nodoc:
535
- true
536
- end
537
-
538
- # Returns false
539
- def supports_autoincrement? #:nodoc:
540
- false
541
- end
542
-
543
- def supports_index_sort_order?
544
- false
545
- end
546
-
547
- # Returns 62. SQLite supports index names up to 64
548
- # characters. The rest is used by rails internally to perform
549
- # temporary rename operations
550
- def allowed_index_name_length
551
- index_name_length - 2
552
- end
553
-
554
- def default_primary_key_type
555
- if supports_autoincrement?
556
- 'STRING'
557
- else
558
- 'STRING'
559
- end
560
- end
561
-
562
- def native_database_types #:nodoc:
563
- {
564
- :primary_key => default_primary_key_type,
565
- :string => { :name => "STRING", :default=> nil },
566
- #:text => { :name => "text" },
567
- :integer => { :name => "INTEGER", :default=> nil },
568
- :float => { :name => "FLOAT", :default=> 0.0 },
569
- #:decimal => { :name => "decimal" },
570
- :datetime => { :name => "TIMESTAMP" },
571
- #:timestamp => { :name => "datetime" },
572
- :timestamp => { name: "TIMESTAMP" },
573
- #:time => { :name => "time" },
574
- :date => { :name => "TIMESTAMP" },
575
- :record => { :name => "RECORD" },
576
- :boolean => { :name => "BOOLEAN" }
577
- }
578
- end
579
-
580
- # Returns the current database encoding format as a string, eg: 'UTF-8'
581
- def encoding
582
- @connection.encoding.to_s
583
- end
584
-
585
- # Returns false.
586
- def supports_explain?
587
- false
588
- end
589
-
590
- def create_database(database)
591
- result = GoogleBigquery::Dataset.create(@config[:project],
592
- {"datasetReference"=> { "datasetId" => database }} )
593
- result
594
- end
595
-
596
- def drop_database(database)
597
- tables = GoogleBigquery::Table.list(@config[:project], database)["tables"]
598
- unless tables.blank?
599
- tables.map!{|o| o["tableReference"]["tableId"]}
600
- tables.each do |table_id|
601
- GoogleBigquery::Table.delete(@config[:project], database, table_id)
602
- end
603
- end
604
- result = GoogleBigquery::Dataset.delete(@config[:project], database )
605
- result
606
- end
607
-
608
- # QUOTING ==================================================
609
-
610
- def quote(value, column = nil)
611
- if value.kind_of?(String) && column && column.type == :binary && column.class.respond_to?(:string_to_binary)
612
- s = column.class.string_to_binary(value).unpack("H*")[0]
613
- "x'#{s}'"
614
- else
615
- super
616
- end
617
- end
618
-
619
- def quote_table_name(name)
620
- "#{@config[:database]}.#{name}"
621
- end
622
-
623
- def quote_table_name_for_assignment(table, attr)
624
- quote_column_name(attr)
625
- end
626
-
627
- def quote_column_name(name) #:nodoc:
628
- name
629
- end
630
-
631
- # Quote date/time values for use in SQL input. Includes microseconds
632
- # if the value is a Time responding to usec.
633
- def quoted_date(value) #:nodoc:
634
- if value.respond_to?(:usec)
635
- "#{super}.#{sprintf("%06d", value.usec)}"
636
- else
637
- super
638
- end
639
- end
640
-
641
- def quoted_true
642
- "1"
643
- end
644
-
645
- def quoted_false
646
- "0"
647
- end
648
-
649
- def type_cast(value, column) # :nodoc:
650
- return value.to_f if BigDecimal === value
651
- return super unless String === value
652
- return super unless column && value
653
-
654
- value = super
655
- if column.type == :string && value.encoding == Encoding::ASCII_8BIT
656
- logger.error "Binary data inserted for `string` type on column `#{column.name}`" if logger
657
- value = value.encode Encoding::UTF_8
658
- end
659
- value
660
- end
661
-
662
- # DATABASE STATEMENTS ======================================
663
-
664
- def explain(arel, binds = [])
665
- bypass_feature
666
- end
667
-
668
- class ExplainPrettyPrinter
669
- # Pretty prints the result of a EXPLAIN QUERY PLAN in a way that resembles
670
- # the output of the SQLite shell:
671
- #
672
- # 0|0|0|SEARCH TABLE users USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)
673
- # 0|1|1|SCAN TABLE posts (~100000 rows)
674
- #
675
- def pp(result) # :nodoc:
676
- result.rows.map do |row|
677
- row.join('|')
678
- end.join("\n") + "\n"
679
- end
680
- end
681
-
682
- def exec_query(sql, name = nil, binds = [])
683
- log(sql, name, binds) do
684
-
685
- # Don't cache statements if they are not prepared
686
- if without_prepared_statement?(binds)
687
- result = GoogleBigquery::Jobs.query(@config[:project], {"query"=> sql })
688
- cols = result["schema"]["fields"].map{|o| o["name"] }
689
- records = result["totalRows"].to_i.zero? ? [] : result["rows"].map{|o| o["f"].map{|k,v| k["v"]} }
690
- stmt = records
691
- else
692
- #binding.pry
693
- #BQ does not support prepared statements, yiak!
694
- end
695
-
696
- ActiveRecord::Result.new(cols, stmt)
697
- end
698
- end
699
-
700
- def exec_delete(sql, name = 'SQL', binds = [])
701
- exec_query(sql, name, binds)
702
- @connection.changes
703
- end
704
-
705
- alias :exec_update :exec_delete
706
-
707
- def last_inserted_id(result)
708
- @connection.last_insert_row_id
709
- end
710
-
711
- def execute(sql, name = nil) #:nodoc:
712
- log(sql, name) { @connection.execute(sql) }
713
- end
714
-
715
- def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) #:nodoc:
716
- super
717
- id_value || @connection.last_insert_row_id
718
- end
719
- alias :create :insert_sql
720
-
721
- def select_rows(sql, name = nil)
722
- exec_query(sql, name).rows
723
- end
724
-
725
- def begin_db_transaction #:nodoc:
726
- log('begin transaction',nil) { } #@connection.transaction
727
- end
728
-
729
- def commit_db_transaction #:nodoc:
730
- log('commit transaction',nil) { } #@connection.commit
731
- end
732
-
733
- def rollback_db_transaction #:nodoc:
734
- log('rollback transaction',nil) { } #@connection.rollback
735
- end
736
-
737
- # SCHEMA STATEMENTS ========================================
738
-
739
- def tables(name = nil, table_name = nil) #:nodoc:
740
- table = GoogleBigquery::Table.list(@config[:project], @config[:database])
741
- return [] if table["tables"].blank?
742
- table_names = table["tables"].map{|o| o["tableReference"]["tableId"]}
743
- table_names = table_names.select{|o| o == table_name } if table_name
744
- table_names
745
- end
746
-
747
- def table_exists?(table_name)
748
- table_name && tables(nil, table_name).any?
749
- end
750
-
751
- # Returns an array of +SQLite3Column+ objects for the table specified by +table_name+.
752
- def columns(table_name) #:nodoc:
753
- schema = GoogleBigquery::Table.get(@config[:project], @config[:database], table_name)
754
- schema["schema"]["fields"].map do |field|
755
- mode = field['mode'].present? && field['mode'] == "REQUIRED" ? false : true
756
- #column expects (name, default, sql_type = nil, null = true)
757
- BigqueryColumn.new(field['name'], nil, field['type'], mode )
758
- end
759
- end
760
-
761
- # Returns an array of indexes for the given table.
762
- def indexes(table_name, name = nil) #:nodoc:
763
- []
764
- end
765
-
766
- def primary_key(table_name) #:nodoc:
767
- "id"
768
- end
769
-
770
- def remove_index!(table_name, index_name) #:nodoc:
771
- #exec_query "DROP INDEX #{quote_column_name(index_name)}"
772
- end
773
-
774
- def add_column(table_name, column_name, type, options = {}) #:nodoc:
775
- if supports_add_column? && valid_alter_table_options( type, options )
776
- super(table_name, column_name, type, options)
777
- else
778
- alter_table(table_name) do |definition|
779
- definition.column(column_name, type, options)
780
- end
781
- end
782
- end
783
-
784
- # See also TableDefinition#column for details on how to create columns.
785
- def create_table(table_name, options = {})
786
- td = create_table_definition table_name, options[:temporary], options[:options]
787
-
788
- unless options[:id] == false
789
- pk = options.fetch(:primary_key) {
790
- Base.get_primary_key table_name.to_s.singularize
791
- }
792
-
793
- td.primary_key pk, options.fetch(:id, :primary_key), options
794
- end
795
-
796
- yield td if block_given?
797
-
798
- if options[:force] && table_exists?(table_name)
799
- drop_table(table_name, options)
800
- end
801
-
802
- hsh = td.columns.map { |c| {"name"=> c[:name], "type"=> type_to_sql(c[:type]) } }
803
-
804
- @table_body = { "tableReference"=> {
805
- "projectId"=> @config[:project],
806
- "datasetId"=> @config[:database],
807
- "tableId"=> td.name},
808
- "schema"=> [fields: hsh]
809
- }
810
-
811
- res = GoogleBigquery::Table.create(@config[:project], @config[:database], @table_body )
812
-
813
- raise res["error"]["errors"].map{|o| "[#{o['domain']}]: #{o['reason']} #{o['message']}" }.join(", ") if res["error"].present?
814
- end
815
-
816
- # See also Table for details on all of the various column transformation.
817
- def change_table(table_name, options = {})
818
- if supports_bulk_alter? && options[:bulk]
819
- recorder = ActiveRecord::Migration::CommandRecorder.new(self)
820
- yield update_table_definition(table_name, recorder)
821
- bulk_change_table(table_name, recorder.commands)
822
- else
823
- yield update_table_definition(table_name, self)
824
- end
825
- end
826
- # Renames a table.
827
- #
828
- # Example:
829
- # rename_table('octopuses', 'octopi')
830
- def rename_table(table_name, new_name)
831
- raise Error::PendingFeature
832
- end
833
-
834
- # See: http://www.sqlite.org/lang_altertable.html
835
- # SQLite has an additional restriction on the ALTER TABLE statement
836
- def valid_alter_table_options( type, options)
837
- type.to_sym != :primary_key
838
- end
839
-
840
- def add_column(table_name, column_name, type, options = {}) #:nodoc:
841
-
842
- if supports_add_column? && valid_alter_table_options( type, options )
843
-
844
- hsh = table_name.classify.constantize.columns.map { |c| {"name"=> c.name, "type"=> c.type } }
845
- hsh << {"name"=> column_name, :type=> type}
846
- fields = [ fields: hsh ]
847
-
848
- res = GoogleBigquery::Table.patch(@config[:project], @config[:database], table_name,
849
- {"tableReference"=> {
850
- "projectId" => @config[:project],
851
- "datasetId" =>@config[:database],
852
- "tableId" => table_name },
853
- "schema" => fields,
854
- "description"=> "added from migration"} )
855
-
856
- else
857
- bypass_feature
858
- end
859
- end
860
-
861
- def bypass_feature
862
- begin
863
- raise Error::NotImplementedColumnOperation
864
- rescue => e
865
- puts e.message
866
- logger.warn(e.message)
867
- end
868
- end
869
-
870
- def remove_column(table_name, column_name, type = nil, options = {}) #:nodoc:
871
- bypass_feature
872
- end
873
-
874
- def change_column_default(table_name, column_name, default) #:nodoc:
875
- bypass_feature
876
- end
877
-
878
- def change_column_null(table_name, column_name, null, default = nil)
879
- bypass_feature
880
- end
881
-
882
- def change_column(table_name, column_name, type, options = {}) #:nodoc:
883
- bypass_feature
884
- end
885
-
886
- def rename_column(table_name, column_name, new_column_name) #:nodoc:
887
- bypass_feature
888
- end
889
-
890
- def add_reference(table_name, ref_name, options = {})
891
- polymorphic = options.delete(:polymorphic)
892
- index_options = options.delete(:index)
893
- add_column(table_name, "#{ref_name}_id", :string, options)
894
- add_column(table_name, "#{ref_name}_type", :string, polymorphic.is_a?(Hash) ? polymorphic : options) if polymorphic
895
- add_index(table_name, polymorphic ? %w[id type].map{ |t| "#{ref_name}_#{t}" } : "#{ref_name}_id", index_options.is_a?(Hash) ? index_options : nil) if index_options
896
- end
897
-
898
- def drop_table(table_name)
899
- GoogleBigquery::Table.delete(@config[:project], @config[:database], table_name )
900
- end
901
-
902
- def dump_schema_information #:nodoc:
903
- bypass_feature
904
- end
905
-
906
- def assume_migrated_upto_version(version, migrations_paths = ActiveRecord::Migrator.migrations_paths)
907
- bypass_feature
908
- end
909
-
910
-
911
- protected
912
- def select(sql, name = nil, binds = []) #:nodoc:
913
- exec_query(sql, name, binds)
914
- end
915
-
916
- def table_structure(table_name)
917
- structure = GoogleBigquery::Table.get(@config[:project], @config[:database], table_name)["schema"]["fields"]
918
- raise(ActiveRecord::StatementInvalid, "Could not find table '#{table_name}'") if structure.empty?
919
- structure
920
- end
921
-
922
- def alter_table(table_name, options = {}) #:nodoc:
923
-
924
- end
925
-
926
- def move_table(from, to, options = {}, &block) #:nodoc:
927
- copy_table(from, to, options, &block)
928
- drop_table(from)
929
- end
930
-
931
- def copy_table(from, to, options = {}) #:nodoc:
932
-
933
- end
934
-
935
- def copy_table_indexes(from, to, rename = {}) #:nodoc:
936
-
937
- end
938
-
939
- def copy_table_contents(from, to, columns, rename = {}) #:nodoc:
940
-
941
- end
942
-
943
- def create_table_definition(name, temporary, options)
944
- TableDefinition.new native_database_types, name, temporary, options
945
- end
946
-
947
- end
948
370
 
371
+ if ActiveRecord::VERSION::MAJOR == 4
372
+ case ActiveRecord::VERSION::MINOR
373
+ when 0
374
+ require File.join(File.dirname(__FILE__), 'rails_41.rb')
375
+ when 1
376
+ require File.join(File.dirname(__FILE__), 'rails_41.rb')
377
+ when 2
378
+ require File.join(File.dirname(__FILE__), 'rails_42.rb')
949
379
  end
950
-
951
- end
380
+ else
381
+ raise "BigBroda only works on Rails 4.X version"
382
+ end