Module: ZBootstrap

Defined in:
lib/jungle_path/app/ztools/zbootstrapdata.rb

Class Method Summary collapse

Class Method Details

.fix_serial(db = nil) ⇒ Object



58
59
60
61
62
# File 'lib/jungle_path/app/ztools/zbootstrapdata.rb', line 58

def self.fix_serial db=nil
  db = Server::API::DB.instance unless db
  db.reset_sequence_for_table("user")
  db.reset_sequence_for_table("contact")
end

.root_data(db_config = nil, schema_initial_version = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
56
# File 'lib/jungle_path/app/ztools/zbootstrapdata.rb', line 15

def self.root_data db_config=nil, schema_initial_version=nil
  db = JunglePath::DBAccess::IO::DB.new(db_config) if db_config
  db = Server::DB.instance unless db

  # set starting version numnber
  if schema_initial_version
    schema_info = Schema::SchemaInfo.new({version: schema_initial_version})
    db.insert._model(schema_info)
  end

  hash = 'sha1:1000:/CloeFSPBOT7Ac/Jf/qQLk59iQbflhxf:H4eHZ0w51f3UdQpM+tp2DdhofDPkTf2P\n' # "test"
  hash_zoo = 'sha1:1000:wNGOiLtzLt7U9t7g+AoQVYZBeZn4NDIl:WZ7ADLonzVbnMP+d0g4K94Rk06ai4Ezk\n' # "zoo"
  users = [
    Schema::User.new({id: 0, name: 'root', user_name: 'root', role: 'root', hash: hash, email: nil, active: true, created_by_user_id: 0, updated_by_user_id: 0}),
    Schema::User.new({id: 1, name: 'admin', user_name: 'admin', role: 'admin', hash: hash, email: nil, active: true, created_by_user_id: 0, updated_by_user_id: 0}),
    Schema::User.new({id: 2, name: 'user', user_name: 'user', role: 'user', hash: hash_zoo, email: nil, active: true, created_by_user_id: 0, updated_by_user_id: 0})
  ]
  users.each {|user| db.insert._model(user)}

  contacts = [
    Schema::Contact.new({id: 0, name: 'root', email: '[email protected]', user_id: 0, created_by_user_id: 0, updated_by_user_id: 0}),
    Schema::Contact.new({id: 1, name: 'admin', email: '[email protected]', user_id: 1, created_by_user_id: 0, updated_by_user_id: 0}),
    Schema::Contact.new({id: 2, name: 'user', email: '[email protected]', user_id: 2, created_by_user_id: 0, updated_by_user_id: 0})
  ]
  contacts.each {|contact| db.insert._model(contact)}

  #roles = [
  #  Schema::Role.new({id: 0, name: 'root', description: 'do anything', created_by_user_id: 0, updated_by_user_id: 0}),
  #  Schema::Role.new({id: 1, name: 'admin', description: 'general admin -- filtered by organization', created_by_user_id: 0, updated_by_user_id: 0}),
  #  Schema::Role.new({id: 2, name: 'user', description: 'basic user of system', created_by_user_id: 0, updated_by_user_id: 0})
  #]
  #roles.each {|role| db.insert._model(role)}

  #user_roles = [
  #  Schema::UserRole.new({user_id: 0, role_id: 0, created_by_user_id: 0, updated_by_user_id: 0}),
  #  Schema::UserRole.new({user_id: 1, role_id: 1, created_by_user_id: 0, updated_by_user_id: 0}),
  #  Schema::UserRole.new({user_id: 2, role_id: 2, created_by_user_id: 0, updated_by_user_id: 0})
  #]
  #user_roles.each {|user_role| db.insert._model(user_role)}

fix_serial db
end