 USE `ica`;
 CREATE  OR REPLACE VIEW `references_summary` AS
 SELECT
-	tbl_reference.id AS reference_id,
-	tbl_reference.referee_jointsource_id AS referee_jointsource_id,
-	tbl_reference.referrer_jointsource_id AS referrer_jointsource_id,
-	tbl_state.id AS state_id,
-	tbl_state.state AS state
+  tbl_reference.id AS reference_id,
+  tbl_reference.referee_jointsource_id AS referee_jointsource_id,
+  tbl_reference.referrer_jointsource_id AS referrer_jointsource_id,
+  tbl_state.id AS state_id,
+  tbl_state.state AS state
 FROM `references` AS tbl_reference
 LEFT JOIN `references_state_latest` AS tbl_state_latest
-	ON tbl_state_latest.reference_id = tbl_reference.id
+  ON tbl_state_latest.reference_id = tbl_reference.id
 LEFT JOIN `references_states` AS tbl_state
-	ON tbl_state.id = tbl_state_latest.state_id;
+  ON tbl_state.id = tbl_state_latest.state_id;
 
 -- -----------------------------------------------------
 -- View `ica`.`jointsources_summary`

USE `ica`;
CREATE  OR REPLACE VIEW `sources_summary` AS
SELECT
	tbl_source.id AS source_id,
	tbl_source.jointsource_id AS jointsource_id,
	tbl_source.type AS source_type,
	tbl_state.id AS state_id,
	tbl_state.state AS state,
	tbl_source.content_id AS content_id,
	tbl_source.title_id AS title_id
FROM `sources` AS tbl_source
LEFT JOIN `sources_state_latest` AS tbl_state_latest
	ON tbl_state_latest.source_id = tbl_source.id
LEFT JOIN `sources_states` AS tbl_state
	ON tbl_state.id = tbl_state_latest.state_id;

-- -----------------------------------------------------
-- View `ica`.`contents_langs_summary`

USE `ica`;
CREATE  OR REPLACE VIEW `jointsources_state_latest` AS
SELECT
  tbl_state.jointsource_id AS jointsource_id,
  MAX(tbl_state.id) AS state_id
FROM `jointsources_states` AS tbl_state
GROUP BY jointsource_id;

