app_module = Mks::Auth::ApplicationModule.where(code: 'EDM', name: 'Equipment Data Module').first_or_create equipment_owner = Mks::Auth::UserRole.where(name: 'equipment_owner', application_module_id: app_module.id).first_or_create equipment_staff = Mks::Auth::UserRole.where(name: 'equipment_staff', application_module_id: app_module.id).first_or_create menu1 = Mks::Auth::Menu.where(text: 'Equipment Setting', application_module_id: app_module.id).first_or_create menu2 = Mks::Auth::Menu.where(text: 'Equipment Transaction', application_module_id: app_module.id).first_or_create Mks::Auth::Menu.where(text: 'Equipment Types', parent_id: menu1.id, location: 'equipment_types', application_module_id: app_module.id).first_or_create Mks::Auth::Menu.where(text: 'Equipment Categories', parent_id: menu1.id, location: 'equipment_categories', application_module_id: app_module.id).first_or_create Mks::Auth::Menu.where(text: 'Equipments', parent_id: menu1.id, location: 'equipments', application_module_id: app_module.id).first_or_create Mks::Auth::Menu.where(text: 'Equipment Items', parent_id: menu2.id, location: 'equipment_items', application_module_id: app_module.id).first_or_create equipment_owner_menu = equipment_owner.menus.where(application_module_id: app_module.id) equipment_owner.menus.delete(equipment_owner_menu) equipment_owner.menus << menu1 equipment_owner.menus << menu1.children equipment_staff_menu = equipment_staff.menus.where(application_module_id: app_module.id) equipment_staff.menus.delete(equipment_staff_menu) equipment_staff.menus << menu2 equipment_staff.menus << menu2.children u1 = Mks::Auth::User.where(first_name: 'Adey', last_name: 'E.') if u1.empty? u1 = Mks::Auth::User.create(first_name: 'Adey', last_name: 'E.', email: 'adey@gmail.com', active: true, application_modules: [app_module], password: 'adey123') u1.roles << equipment_owner u1.roles << equipment_staff end