   `superuser` int(1) NOT NULL DEFAULT '0',
   `status` int(1) NOT NULL DEFAULT '0',
   `create_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
-  `lastvisit_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
-  PRIMARY KEY (`id`),
-  UNIQUE KEY `user_username` (`username`),
-  UNIQUE KEY `user_email` (`email`)
-) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=433 ;
-
--- --------------------------------------------------------
-
---
--- Table structure for table `tbl_user_oauth`
---
-
-CREATE TABLE IF NOT EXISTS `tbl_user_oauth` (
+  `lastvisit_at` timestamp NULL DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
+
+-- --------------------------------------------------------
+
+--
+-- Struttura della tabella `tbl_user_oauth`
+--
+
+CREATE TABLE `tbl_user_oauth` (
   `user_id` int(11) NOT NULL,
   `provider` varchar(45) NOT NULL,
   `identifier` varchar(64) NOT NULL,
   `profile_cache` text,
-  `session_data` text,
-  PRIMARY KEY (`provider`,`identifier`),
-  UNIQUE KEY `unic_user_id_name` (`user_id`,`provider`),
-  KEY `oauth_user_id` (`user_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
---
--- Constraints for dumped tables
---
-
---
--- Constraints for table `tbl_account`
+  `session_data` text
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+--
+-- Indici per le tabelle scaricate
+--
+
+--
+-- Indici per le tabelle `tbl_account`
+--
+ALTER TABLE `tbl_account`
+  ADD PRIMARY KEY (`id`),
+  ADD UNIQUE KEY `firm_code` (`firm_id`,`code`),
+  ADD KEY `account_parent_id` (`account_parent_id`),
+  ADD KEY `firm_id` (`firm_id`);
+
+--
+-- Indici per le tabelle `tbl_challenge`
+--
+ALTER TABLE `tbl_challenge`
+  ADD PRIMARY KEY (`id`),
+  ADD UNIQUE KEY `user_id_2` (`user_id`,`exercise_id`),
+  ADD KEY `mark` (`rate`),
+  ADD KEY `assigned_at` (`assigned_at`),
+  ADD KEY `instructor_id` (`instructor_id`),
+  ADD KEY `user_id` (`user_id`),
+  ADD KEY `firm_id` (`firm_id`),
+  ADD KEY `exercise_id` (`exercise_id`),
+  ADD KEY `suspended_at` (`suspended_at`),
+  ADD KEY `transaction_id` (`transaction_id`),
+  ADD KEY `checked_at` (`checked_at`),
+  ADD KEY `session` (`session`);
+
+--
+-- Indici per le tabelle `tbl_event`
+--
+ALTER TABLE `tbl_event`
+  ADD PRIMARY KEY (`id`),
+  ADD KEY `firm_id` (`firm_id`),
+  ADD KEY `user_id` (`user_id`);
+
+--
+-- Indici per le tabelle `tbl_exercise`
+--
+ALTER TABLE `tbl_exercise`
+  ADD PRIMARY KEY (`id`),
+  ADD UNIQUE KEY `slug` (`slug`),
+  ADD KEY `user_id` (`user_id`),
+  ADD KEY `firm_id` (`firm_id`);
+
+--
+-- Indici per le tabelle `tbl_firm`
+--
+ALTER TABLE `tbl_firm`
+  ADD PRIMARY KEY (`id`),
+  ADD UNIQUE KEY `slug` (`slug`),
+  ADD KEY `language_id` (`language_id`),
+  ADD KEY `parent_firm_id` (`firm_parent_id`,`create_date`),
+  ADD KEY `shortcodes` (`shortcodes`);
+
+--
+-- Indici per le tabelle `tbl_firm_language`
+--
+ALTER TABLE `tbl_firm_language`
+  ADD PRIMARY KEY (`firm_id`,`language_id`),
+  ADD KEY `firm_id` (`firm_id`),
+  ADD KEY `language_id` (`language_id`);
+
+--
+-- Indici per le tabelle `tbl_firm_user`
+--
+ALTER TABLE `tbl_firm_user`
+  ADD PRIMARY KEY (`firm_id`,`user_id`),
+  ADD KEY `user_id` (`user_id`),
+  ADD KEY `firm_id` (`firm_id`);
+
+--
+-- Indici per le tabelle `tbl_journalentry`
+--
+ALTER TABLE `tbl_journalentry`
+  ADD PRIMARY KEY (`id`),
+  ADD UNIQUE KEY `firm_rank` (`firm_id`,`rank`),
+  ADD KEY `firm_id` (`firm_id`),
+  ADD KEY `is_confirmed` (`is_confirmed`),
+  ADD KEY `is_closing` (`is_closing`),
+  ADD KEY `firm_is_confirmed` (`firm_id`,`is_confirmed`),
+  ADD KEY `firm_is_closing` (`firm_id`,`is_closing`),
+  ADD KEY `is_included` (`is_included`),
+  ADD KEY `transaction_id` (`transaction_id`);
+
+--
+-- Indici per le tabelle `tbl_language`
+--
+ALTER TABLE `tbl_language`
+  ADD PRIMARY KEY (`id`),
+  ADD KEY `is_default` (`is_default`);
+
+--
+-- Indici per le tabelle `tbl_migration`
+--
+ALTER TABLE `tbl_migration`
+  ADD PRIMARY KEY (`version`);
+
+--
+-- Indici per le tabelle `tbl_posting`
+--
+ALTER TABLE `tbl_posting`
+  ADD PRIMARY KEY (`id`),
+  ADD UNIQUE KEY `journalentryrank` (`journalentry_id`,`rank`),
+  ADD KEY `account_id` (`account_id`),
+  ADD KEY `journalentry_id` (`journalentry_id`);
+
+--
+-- Indici per le tabelle `tbl_profiles`
+--
+ALTER TABLE `tbl_profiles`
+  ADD PRIMARY KEY (`user_id`),
+  ADD KEY `email_notices` (`email_notices`);
+
+--
+-- Indici per le tabelle `tbl_profiles_fields`
+--
+ALTER TABLE `tbl_profiles_fields`
+  ADD PRIMARY KEY (`id`);
+
+--
+-- Indici per le tabelle `tbl_template`
+--
+ALTER TABLE `tbl_template`
+  ADD PRIMARY KEY (`id`),
+  ADD KEY `firm_id` (`firm_id`);
+
+--
+-- Indici per le tabelle `tbl_transaction`
+--
+ALTER TABLE `tbl_transaction`
+  ADD PRIMARY KEY (`id`),
+  ADD KEY `exercise_id` (`exercise_id`),
+  ADD KEY `event_date` (`event_date`,`rank`);
+
+--
+-- Indici per le tabelle `tbl_users`
+--
+ALTER TABLE `tbl_users`
+  ADD PRIMARY KEY (`id`),
+  ADD UNIQUE KEY `user_username` (`username`),
+  ADD UNIQUE KEY `user_email` (`email`);
+
+--
+-- Indici per le tabelle `tbl_user_oauth`
+--
+ALTER TABLE `tbl_user_oauth`
+  ADD PRIMARY KEY (`provider`,`identifier`),
+  ADD UNIQUE KEY `unic_user_id_name` (`user_id`,`provider`),
+  ADD KEY `oauth_user_id` (`user_id`);
+
+--
+-- AUTO_INCREMENT per le tabelle scaricate
+--
+
+--
+-- AUTO_INCREMENT per la tabella `tbl_account`
+--
+ALTER TABLE `tbl_account`
+  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=579927;
+--
+-- AUTO_INCREMENT per la tabella `tbl_challenge`
+--
+ALTER TABLE `tbl_challenge`
+  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=118;
+--
+-- AUTO_INCREMENT per la tabella `tbl_event`
+--
+ALTER TABLE `tbl_event`
+  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=112417;
+--
+-- AUTO_INCREMENT per la tabella `tbl_exercise`
+--
+ALTER TABLE `tbl_exercise`
+  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;
+--
+-- AUTO_INCREMENT per la tabella `tbl_firm`
+--
+ALTER TABLE `tbl_firm`
+  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2837;
+--
+-- AUTO_INCREMENT per la tabella `tbl_journalentry`
+--
+ALTER TABLE `tbl_journalentry`
+  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=38636;
+--
+-- AUTO_INCREMENT per la tabella `tbl_language`
+--
+ALTER TABLE `tbl_language`
+  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9;
+--
+-- AUTO_INCREMENT per la tabella `tbl_posting`
+--
+ALTER TABLE `tbl_posting`
+  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=259201;
+--
+-- AUTO_INCREMENT per la tabella `tbl_profiles`
+--
+ALTER TABLE `tbl_profiles`
+  MODIFY `user_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=722;
+--
+-- AUTO_INCREMENT per la tabella `tbl_profiles_fields`
+--
+ALTER TABLE `tbl_profiles_fields`
+  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10;
+--
+-- AUTO_INCREMENT per la tabella `tbl_template`
+--
+ALTER TABLE `tbl_template`
+  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=553;
+--
+-- AUTO_INCREMENT per la tabella `tbl_transaction`
+--
+ALTER TABLE `tbl_transaction`
+  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=26;
+--
+-- AUTO_INCREMENT per la tabella `tbl_users`
+--
+ALTER TABLE `tbl_users`
+  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=722;
+--
+-- Limiti per le tabelle scaricate
+--
+
+--
+-- Limiti per la tabella `tbl_account`
 --
 ALTER TABLE `tbl_account`
   ADD CONSTRAINT `tbl_account_ibfk_1` FOREIGN KEY (`firm_id`) REFERENCES `tbl_firm` (`id`) ON UPDATE CASCADE;
 
 --
--- Constraints for table `tbl_challenge`
+-- Limiti per la tabella `tbl_challenge`
 --
 ALTER TABLE `tbl_challenge`
   ADD CONSTRAINT `tbl_challenge_ibfk_1` FOREIGN KEY (`instructor_id`) REFERENCES `tbl_users` (`id`) ON UPDATE CASCADE,
   ADD CONSTRAINT `tbl_challenge_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `tbl_users` (`id`) ON UPDATE CASCADE,
   ADD CONSTRAINT `tbl_challenge_ibfk_3` FOREIGN KEY (`firm_id`) REFERENCES `tbl_firm` (`id`) ON UPDATE CASCADE,
   ADD CONSTRAINT `tbl_challenge_ibfk_5` FOREIGN KEY (`exercise_id`) REFERENCES `tbl_exercise` (`id`) ON UPDATE CASCADE,
-  ADD CONSTRAINT `tbl_challenge_ibfk_6` FOREIGN KEY (`transaction_id`) REFERENCES `tbl_transaction` (`id`) ON UPDATE CASCADE;
-
---
--- Constraints for table `tbl_event`
+  ADD CONSTRAINT `tbl_challenge_ibfk_6` FOREIGN KEY (`transaction_id`) REFERENCES `tbl_transaction` (`id`) ON DELETE SET NULL ON UPDATE CASCADE;
+
+--
+-- Limiti per la tabella `tbl_event`
 --
 ALTER TABLE `tbl_event`
-  ADD CONSTRAINT `tbl_event_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `tbl_users` (`id`) ON UPDATE CASCADE,
+  ADD CONSTRAINT `tbl_event_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `tbl_users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
   ADD CONSTRAINT `tbl_event_ibfk_2` FOREIGN KEY (`firm_id`) REFERENCES `tbl_firm` (`id`) ON UPDATE CASCADE;
 
 --
--- Constraints for table `tbl_exercise`
+-- Limiti per la tabella `tbl_exercise`
 --
 ALTER TABLE `tbl_exercise`
   ADD CONSTRAINT `tbl_exercise_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `tbl_users` (`id`) ON UPDATE CASCADE,
   ADD CONSTRAINT `tbl_exercise_ibfk_2` FOREIGN KEY (`firm_id`) REFERENCES `tbl_firm` (`id`);
 
 --
--- Constraints for table `tbl_firm_user`
+-- Limiti per la tabella `tbl_firm_user`
 --
 ALTER TABLE `tbl_firm_user`
   ADD CONSTRAINT `tbl_firm_user_ibfk_1` FOREIGN KEY (`firm_id`) REFERENCES `tbl_firm` (`id`) ON UPDATE CASCADE,
   ADD CONSTRAINT `tbl_firm_user_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `tbl_users` (`id`) ON UPDATE CASCADE;
 
 --
--- Constraints for table `tbl_journalentry`
+-- Limiti per la tabella `tbl_journalentry`
 --
 ALTER TABLE `tbl_journalentry`
-  ADD CONSTRAINT `tbl_journalentry_ibfk_2` FOREIGN KEY (`transaction_id`) REFERENCES `tbl_transaction` (`id`) ON UPDATE CASCADE,
-  ADD CONSTRAINT `tbl_journalentry_ibfk_1` FOREIGN KEY (`firm_id`) REFERENCES `tbl_firm` (`id`) ON UPDATE CASCADE;
-
---
--- Constraints for table `tbl_posting`
+  ADD CONSTRAINT `tbl_journalentry_ibfk_1` FOREIGN KEY (`firm_id`) REFERENCES `tbl_firm` (`id`) ON UPDATE CASCADE,
+  ADD CONSTRAINT `tbl_journalentry_ibfk_2` FOREIGN KEY (`transaction_id`) REFERENCES `tbl_transaction` (`id`) ON DELETE SET NULL ON UPDATE CASCADE;
+
+--
+-- Limiti per la tabella `tbl_posting`
 --
 ALTER TABLE `tbl_posting`
   ADD CONSTRAINT `tbl_posting_ibfk_1` FOREIGN KEY (`account_id`) REFERENCES `tbl_account` (`id`) ON UPDATE CASCADE,
   ADD CONSTRAINT `tbl_posting_ibfk_2` FOREIGN KEY (`journalentry_id`) REFERENCES `tbl_journalentry` (`id`) ON UPDATE CASCADE;
 
 --
--- Constraints for table `tbl_profiles`
+-- Limiti per la tabella `tbl_profiles`
 --
 ALTER TABLE `tbl_profiles`
   ADD CONSTRAINT `user_profile_id` FOREIGN KEY (`user_id`) REFERENCES `tbl_users` (`id`) ON DELETE CASCADE;
 
 --
--- Constraints for table `tbl_transaction`
+-- Limiti per la tabella `tbl_transaction`
 --
 ALTER TABLE `tbl_transaction`
   ADD CONSTRAINT `tbl_transaction_ibfk_1` FOREIGN KEY (`exercise_id`) REFERENCES `tbl_exercise` (`id`) ON UPDATE CASCADE;
-  
---
--- Dumping data for table `tbl_language`
---
-
-INSERT INTO `tbl_language` (`id`, `language_code`, `country_code`, `english_name`, `native_name`, `is_default`) VALUES
-(1, 'en', 'US', 'English', 'English', 2),
-(2, 'it', 'IT', 'Italian', 'italiano', 1);
-  
-INSERT INTO `tbl_users` (`id`, `username`, `password`, `email`, `activkey`, `superuser`, `status`, `create_at`, `lastvisit_at`) VALUES
-(1, 'admin', '21232f297a57a5a743894a0e4a801fc3', 'info@example.com', '5bc1a418ca19f1b3f694612375a1afc9', 1, 1, '2013-02-24 13:41:09', '2013-06-09 19:56:21');
-
---
--- Dumping data for table `tbl_profiles_fields`
---
-
-INSERT INTO `tbl_profiles_fields` (`id`, `varname`, `title`, `field_type`, `field_size`, `field_size_min`, `required`, `match`, `range`, `error_message`, `other_validator`, `default`, `widget`, `widgetparams`, `position`, `visible`) VALUES
-(1, 'first_name', 'First Name', 'VARCHAR', 255, 3, 2, '', '', 'Incorrect First Name (length between 3 and 50 characters).', '', '', '', '', 1, 1),
-(2, 'last_name', 'Last Name', 'VARCHAR', 255, 3, 2, '', '', 'Incorrect Last Name (length between 3 and 50 characters).', '', '', '', '', 2, 1),
-(3, 'school', 'School', 'VARCHAR', 255, 0, 2, '', '', '', '', '', '', '', 3, 1),
-(4, 'terms', 'Terms and conditions acceptance', 'TEXT', 0, 0, 0, '', '', '', '', '', '', '', 0, 0),
-(5, 'usercode', 'User code', 'VARCHAR', 255, 0, 0, '', '', '', '', '', '', '', 0, 0),
-(6, 'language', 'Language', 'VARCHAR', 7, 0, 0, '', '', '', '', '', '', '', 0, 0),
-(7, 'allowed_firms', 'Allowed firms', 'INTEGER', 10, 0, 0, '', '', '', '', '10', '', '', 0, 0);
-
---
--- Dumping data for table `tbl_profiles`
---
-
-INSERT INTO `tbl_profiles` (`user_id`, `first_name`, `last_name`, `school`, `terms`, `usercode`, `language`, `allowed_firms`) VALUES
-(1, 'Administrator', 'DELT', '', '', '', 'en', 10);
-
-  
-COMMIT;

  `is_adjustment` tinyint(1) NOT NULL DEFAULT '0',
  `is_included` tinyint(1) NOT NULL DEFAULT '1',
  `rank` int(11) NOT NULL,
  `transaction_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `firm_rank` (`firm_id`,`rank`),
  KEY `firm_id` (`firm_id`),
  KEY `is_confirmed` (`is_confirmed`),
  KEY `is_closing` (`is_closing`),
  KEY `firm_is_confirmed` (`firm_id`,`is_confirmed`),
  KEY `firm_is_closing` (`firm_id`,`is_closing`),
  KEY `is_included` (`is_included`),
  KEY `transaction_id` (`transaction_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- Table structure for table `tbl_language`
--

CREATE TABLE IF NOT EXISTS `tbl_language` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `language_code` char(3) CHARACTER SET utf8 NOT NULL,
  `country_code` char(3) CHARACTER SET utf8 DEFAULT NULL,
  `english_name` varchar(64) CHARACTER SET utf8 NOT NULL,
  `native_name` varchar(64) CHARACTER SET utf8 NOT NULL,
  `is_default` tinyint(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`id`),
  KEY `is_default` (`is_default`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=9 ;

-- --------------------------------------------------------

--
-- Table structure for table `tbl_migration`
--

CREATE TABLE IF NOT EXISTS `tbl_migration` (
  `version` varchar(255) NOT NULL,
  `apply_time` int(11) DEFAULT NULL,
  PRIMARY KEY (`version`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Table structure for table `tbl_posting`
--

CREATE TABLE IF NOT EXISTS `tbl_posting` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `account_id` int(11) NOT NULL,
  `journalentry_id` int(11) NOT NULL,
  `amount` decimal(16,2) NOT NULL COMMENT 'positive if Debit, negative if Credit',
  `rank` int(11) NOT NULL,
  `comment` varchar(100) CHARACTER SET utf8 NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `journalentryrank` (`journalentry_id`,`rank`),
  KEY `account_id` (`account_id`),
  KEY `journalentry_id` (`journalentry_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=70408 ;

-- --------------------------------------------------------

--
-- Table structure for table `tbl_profiles`
--

CREATE TABLE IF NOT EXISTS `tbl_profiles` (
  `user_id` int(11) NOT NULL AUTO_INCREMENT,
  `first_name` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `last_name` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
  `school` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '',

  `language` varchar(7) COLLATE utf8_bin NOT NULL DEFAULT '',
  `allowed_firms` int(11) NOT NULL DEFAULT '10',
  `email_notices` tinyint(1) NOT NULL DEFAULT '1',
  `is_blogger` tinyint(1) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

-- --------------------------------------------------------

--
-- Struttura della tabella `tbl_profiles_fields`
--

CREATE TABLE `tbl_profiles_fields` (
  `id` int(11) NOT NULL,
  `varname` varchar(50) NOT NULL DEFAULT '',
  `title` varchar(255) NOT NULL DEFAULT '',
  `field_type` varchar(50) NOT NULL DEFAULT '',
