Class: DynamicMigrations::Postgres::Server::Database::Schema::Table::PrimaryKey

Inherits:
DynamicMigrations::Postgres::Server::Database::Source show all
Defined in:
lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb

Overview

This class represents a postgres table primary_key

Defined Under Namespace

Classes: DuplicateColumnError, ExpectedArrayOfColumnsError, ExpectedTableError, InvalidNameError, UnexpectedIndexTypeError

Instance Attribute Summary collapse

Attributes inherited from DynamicMigrations::Postgres::Server::Database::Source

#source

Instance Method Summary collapse

Methods inherited from DynamicMigrations::Postgres::Server::Database::Source

#assert_is_a_symbol!, #from_configuration?, #from_database?

Constructor Details

#initialize(source, table, columns, name, description: nil) ⇒ PrimaryKey

initialize a new object to represent a primary_key in a postgres table

Raises:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb', line 31

def initialize source, table, columns, name, description: nil
  super source
  raise ExpectedTableError, table unless table.is_a? Table
  @table = table
  @columns = {}

  # assert that the provided columns is an array
  unless columns.is_a?(Array) && columns.count > 0
    raise ExpectedArrayOfColumnsError
  end

  columns.each do |column|
    add_column column
  end

  raise InvalidNameError, "Unexpected name `#{name}`. Name should be a Symbol" unless name.is_a? Symbol
  raise InvalidNameError, "The name `#{name}` is too long. Names must be less than 64 characters" unless name.length < 64
  @name = name

  unless description.nil?
    raise ExpectedStringError, description unless description.is_a? String
    @description = description.strip.freeze
    @description = nil if description == ""
  end
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



28
29
30
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb', line 28

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



27
28
29
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb', line 27

def name
  @name
end

#tableObject (readonly)

Returns the value of attribute table.



26
27
28
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb', line 26

def table
  @table
end

Instance Method Details

#column_namesObject



67
68
69
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb', line 67

def column_names
  @columns.keys
end

#columnsObject

return an array of this primary keys columns



63
64
65
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb', line 63

def columns
  @columns.values
end

#differences_descriptions(other_primary_key) ⇒ Object



71
72
73
74
75
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb', line 71

def differences_descriptions other_primary_key
  method_differences_descriptions other_primary_key, [
    :column_names
  ]
end

#has_description?Boolean

return true if this has a description, otherwise false

Returns:

  • (Boolean)


58
59
60
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb', line 58

def has_description?
  !@description.nil?
end