Converted Fileproinfo Testlink Create Tables
Converted Fileproinfo Testlink Create Tables
net/
# This script is distributed under the GNU General Public License 2 or
later.
#
--------------------------------------------------------------------------
-------------
# @filesource testlink_create_tables.sql
#
# SQL script - create all DB tables for MySQL
# tables are in alphabetic order
#
# ATTENTION: do not use a different naming convention, that one already in
use.
#
# IMPORTANT NOTE:
# each NEW TABLE added here NEED TO BE DEFINED in object.class.php
getDBTables()
#
# IMPORTANT NOTE - DATETIME or TIMESTAMP
# Extracted from MySQL Manual
#
# The TIMESTAMP column type provides a type that you can use to
automatically
# mark INSERT or UPDATE operations with the current date and time.
# If you have multiple TIMESTAMP columns in a table, only the first one is
updated automatically.
#
# Knowing this is clear that we can use in interchangable way DATETIME or
TIMESTAMP
#
# Naming convention for column regarding date/time of creation or change
#
# Right or wrong from TL 1.7 we have used
#
# creation_ts
# modification_ts
#
# Then no other naming convention has to be used as:
# create_ts, modified_ts
#
# CRITIC:
# Because this file will be processed during installation doing text
replaces
# to add TABLE PREFIX NAME, any NEW DDL CODE added must be respect present
# convention regarding case and spaces between DDL keywords.
#
#
--------------------------------------------------------------------------
-------------
# @internal revisions
#
#
--------------------------------------------------------------------------
-------------
CREATE TABLE /*prefix*/assignment_types (
`id` int(10) unsigned NOT NULL auto_increment,
`fk_table` varchar(30) default '',
`description` varchar(100) NOT NULL default 'unknown',
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8;
# VIEWS
#
# @used_by latest_tcase_version_id
#
CREATE OR REPLACE VIEW /*prefix*/latest_tcase_version_number
AS SELECT NH_TC.id AS testcase_id,max(TCV.version) AS version
FROM /*prefix*/nodes_hierarchy NH_TC
JOIN /*prefix*/nodes_hierarchy NH_TCV
ON NH_TCV.parent_id = NH_TC.id
JOIN /*prefix*/tcversions TCV
ON NH_TCV.id = TCV.id
GROUP BY testcase_id;
#
# @uses latest_tcase_version_number
#
CREATE OR REPLACE VIEW /*prefix*/latest_tcase_version_id
AS SELECT
LTCVN.testcase_id AS testcase_id,
LTCVN.version AS version,
TCV.id AS tcversion_id
FROM /*prefix*/latest_tcase_version_number LTCVN
join /*prefix*/nodes_hierarchy NHTCV
on NHTCV.parent_id = LTCVN.testcase_id
join /*prefix*/tcversions TCV
on TCV.id = NHTCV.id
and TCV.version = LTCVN.version;
#
# @used_by latest_req_version_id
#
CREATE OR REPLACE VIEW /*prefix*/latest_req_version
AS SELECT RQ.id AS req_id,max(RQV.version) AS version
FROM /*prefix*/nodes_hierarchy NHRQV
JOIN /*prefix*/requirements RQ
ON RQ.id = NHRQV.parent_id
JOIN /*prefix*/req_versions RQV
ON RQV.id = NHRQV.id
GROUP BY RQ.id;
#
# @uses latest_req_version
#
CREATE OR REPLACE VIEW /*prefix*/latest_req_version_id
AS SELECT
LRQVN.req_id AS req_id,
LRQVN.version AS version,
REQV.id AS req_version_id
FROM /*prefix*/latest_req_version LRQVN
JOIN /*prefix*/nodes_hierarchy NHRQV
ON NHRQV.parent_id = LRQVN.req_id
JOIN /*prefix*/req_versions REQV
ON REQV.id = NHRQV.id AND REQV.version = LRQVN.version;
#
CREATE OR REPLACE VIEW /*prefix*/latest_rspec_revision
AS SELECT RSR.parent_id AS req_spec_id, RS.testproject_id AS
testproject_id,
MAX(RSR.revision) AS revision
FROM /*prefix*/req_specs_revisions RSR
JOIN /*prefix*/req_specs RS
ON RS.id = RSR.parent_id
GROUP BY RSR.parent_id,RS.testproject_id;
#
CREATE OR REPLACE VIEW /*prefix*/tcversions_without_keywords
AS SELECT
NHTCV.parent_id AS testcase_id,
NHTCV.id AS id
FROM /*prefix*/nodes_hierarchy NHTCV
WHERE NHTCV.node_type_id = 4 AND
NOT(EXISTS(SELECT 1 FROM /*prefix*/testcase_keywords TCK
WHERE TCK.tcversion_id = NHTCV.id));
#
CREATE OR REPLACE VIEW /*prefix*/latest_exec_by_testplan
AS SELECT tcversion_id, testplan_id, MAX(id) AS id
FROM /*prefix*/executions
GROUP BY tcversion_id,testplan_id;
#
CREATE OR REPLACE VIEW /*prefix*/latest_exec_by_context
AS SELECT tcversion_id, testplan_id,build_id,platform_id,max(id) AS id
FROM /*prefix*/executions
GROUP BY tcversion_id,testplan_id,build_id,platform_id;
#
CREATE OR REPLACE VIEW /*prefix*/tcversions_without_platforms
AS SELECT
NHTCV.parent_id AS testcase_id,
NHTCV.id AS id
FROM /*prefix*/nodes_hierarchy NHTCV
WHERE NHTCV.node_type_id = 4 AND
NOT(EXISTS(SELECT 1 FROM /*prefix*/testcase_platforms TCPL
WHERE TCPL.tcversion_id = NHTCV.id));
#
CREATE OR REPLACE VIEW /*prefix*/latest_exec_by_testplan_plat
AS SELECT tcversion_id, testplan_id,platform_id,max(id) AS id
FROM /*prefix*/executions
GROUP BY tcversion_id,testplan_id,platform_id;
#
CREATE OR REPLACE VIEW /*prefix*/tsuites_tree_depth_2
AS SELECT TPRJ.prefix,
NHTPRJ.name AS testproject_name,
NHTS_L1.name AS level1_name,
NHTS_L2.name AS level2_name,
NHTPRJ.id AS testproject_id,
NHTS_L1.id AS level1_id,
NHTS_L2.id AS level2_id
FROM /*prefix*/testprojects TPRJ
JOIN /*prefix*/nodes_hierarchy NHTPRJ
ON TPRJ.id = NHTPRJ.id
LEFT OUTER JOIN /*prefix*/nodes_hierarchy NHTS_L1
ON NHTS_L1.parent_id = NHTPRJ.id
LEFT OUTER JOIN /*prefix*/nodes_hierarchy NHTS_L2
ON NHTS_L2.parent_id = NHTS_L1.id
WHERE NHTPRJ.node_type_id = 1
AND NHTS_L1.node_type_id = 2
AND NHTS_L2.node_type_id = 2;
#
CREATE OR REPLACE VIEW /*prefix*/exec_by_date_time
AS (
SELECT NHTPL.name AS testplan_name,
DATE_FORMAT(E.execution_ts, '%Y-%m-%d') AS yyyy_mm_dd,
DATE_FORMAT(E.execution_ts, '%Y-%m') AS yyyy_mm,
DATE_FORMAT(E.execution_ts, '%H') AS hh,
DATE_FORMAT(E.execution_ts, '%k') AS hour,
E.* FROM /*prefix*/executions E
JOIN /*prefix*/testplans TPL on TPL.id=E.testplan_id
JOIN /*prefix*/nodes_hierarchy NHTPL on NHTPL.id = TPL.id);