From 020be62dea73a50ee5105d56633f8bb2f6722bb9 Mon Sep 17 00:00:00 2001
From: Bruce Momjian <bruce@momjian.us>
Date: Tue, 22 Feb 2000 20:58:31 +0000
Subject: [PATCH] Well, here's the first pass on regression tests for the
 Foreign Key support in 7.0 which was made against a CVS copy from this
 afternoon.

This modifies
 src/test/regress/sql/run_check.tests
 src/test/regress/sql/alter_table.sql
 src/test/regress/expected/alter_table.out
 src/test/regress/sql/foreign_key.sql
 src/test/regress/expected/foreign_key.out

sszabo@bigpanda.co
---
 doc/src/sgml/release.sgml                 |  2 +-
 src/test/regress/expected/alter_table.out | 24 ++++++
 src/test/regress/sql/alter_table.sql      | 30 +++++++
 src/test/regress/sql/run_check.tests      |  1 +
 src/tools/pgcvslog                        | 96 +++++++++++++++++++++++
 5 files changed, 152 insertions(+), 1 deletion(-)
 create mode 100755 src/tools/pgcvslog

diff --git a/doc/src/sgml/release.sgml b/doc/src/sgml/release.sgml
index 00d78c58ca1..ca197419688 100644
--- a/doc/src/sgml/release.sgml
+++ b/doc/src/sgml/release.sgml
@@ -179,7 +179,7 @@ Add Win1250 (Czech) support (Pavel Behal)
 <surname>Momjian</surname>
 </author>
 </authorgroup>
-<date>1998-06-09</date>
+<date>1999-06-09</date>
 </docinfo>
 -->
 
diff --git a/src/test/regress/expected/alter_table.out b/src/test/regress/expected/alter_table.out
index 174925df849..6ef19f56cf6 100644
--- a/src/test/regress/expected/alter_table.out
+++ b/src/test/regress/expected/alter_table.out
@@ -269,3 +269,27 @@ SELECT unique1 FROM tenk1 WHERE unique1 < 5;
        4
 (5 rows)
 
+-- FOREIGN KEY CONSTRAINT adding TEST
+CREATE TABLE tmp2 (a int primary key);
+NOTICE:  CREATE TABLE/PRIMARY KEY will create implicit index 'tmp2_pkey' for table 'tmp2'
+CREATE TABLE tmp3 (a int, b int);
+-- Insert rows into tmp2 (pktable)
+INSERT INTO tmp2 values (1);
+INSERT INTO tmp2 values (2);
+INSERT INTO tmp2 values (3);
+INSERT INTO tmp2 values (4);
+-- Insert rows into tmp3
+INSERT INTO tmp3 values (1,10);
+INSERT INTO tmp3 values (1,20);
+INSERT INTO tmp3 values (5,50);
+-- Try (and fail) to add constraint due to invalid data
+ALTER TABLE tmp3 add constraint tmpconstr foreign key (a) references tmp2 match full;
+NOTICE:  ALTER TABLE ... ADD CONSTRAINT will create implicit trigger(s) for FOREIGN KEY check(s)
+ERROR:  <unnamed> referential integrity violation - key referenced from tmp3 not found in tmp2
+-- Delete failing row
+DELETE FROM tmp3 where a=5;
+-- Try (and succeed)
+ALTER TABLE tmp3 add constraint tmpconstr foreign key (a) references tmp2 match full;
+NOTICE:  ALTER TABLE ... ADD CONSTRAINT will create implicit trigger(s) for FOREIGN KEY check(s)
+DROP TABLE tmp3
+DROP TABLE tmp2
diff --git a/src/test/regress/sql/alter_table.sql b/src/test/regress/sql/alter_table.sql
index 5ba66c46e8f..512b74d49c3 100644
--- a/src/test/regress/sql/alter_table.sql
+++ b/src/test/regress/sql/alter_table.sql
@@ -163,3 +163,33 @@ ALTER TABLE ten_k RENAME TO tenk1;
 -- 5 values, sorted 
 SELECT unique1 FROM tenk1 WHERE unique1 < 5;
 
+-- FOREIGN KEY CONSTRAINT adding TEST
+
+CREATE TABLE tmp2 (a int primary key);
+
+CREATE TABLE tmp3 (a int, b int);
+
+-- Insert rows into tmp2 (pktable)
+INSERT INTO tmp2 values (1);
+INSERT INTO tmp2 values (2);
+INSERT INTO tmp2 values (3);
+INSERT INTO tmp2 values (4);
+
+-- Insert rows into tmp3
+INSERT INTO tmp3 values (1,10);
+INSERT INTO tmp3 values (1,20);
+INSERT INTO tmp3 values (5,50);
+
+-- Try (and fail) to add constraint due to invalid data
+ALTER TABLE tmp3 add constraint tmpconstr foreign key (a) references tmp2 match full;
+
+-- Delete failing row
+DELETE FROM tmp3 where a=5;
+
+-- Try (and succeed)
+ALTER TABLE tmp3 add constraint tmpconstr foreign key (a) references tmp2 match full;
+
+DROP TABLE tmp3
+
+DROP TABLE tmp2
+
diff --git a/src/test/regress/sql/run_check.tests b/src/test/regress/sql/run_check.tests
index 33d89042376..8c832e016c4 100644
--- a/src/test/regress/sql/run_check.tests
+++ b/src/test/regress/sql/run_check.tests
@@ -119,6 +119,7 @@ parallel	group5
 	test	alter_table
 	test	portals_p2
 	test	rules
+	test	foreign_key
 endparallel
 
 # ----------
diff --git a/src/tools/pgcvslog b/src/tools/pgcvslog
new file mode 100755
index 00000000000..c54177e81c6
--- /dev/null
+++ b/src/tools/pgcvslog
@@ -0,0 +1,96 @@
+:
+# This utility is used to generate a compact list of changes for each
+# release, bjm 2000-02-22
+
+# Usage $0 [-r 'revision pattern'] file
+
+# cvs log -d '>1999-06-14 00:00:00 GMT' > log
+# pgcvslog -r '\.2\.[0-9]*$' log
+
+if [ "X$1" = "X-r" ]
+then	REV="$2"
+	shift 2
+else	REV=".*"
+fi
+
+cat "$@" |
+
+# mark each line with a datetime and line number, for sorting and merging
+# we don't print anything from the -- or == line and the date:
+
+awk '
+	$0 ~ /^Working file:/	{workingfile = $0}
+
+	$1 == "revision" && $2 !~ /'"$REV"'/ {skip = "Y"}
+
+	($0 ~ /^====*$/ || $0 ~ /^----*$/) && skip == "N" \
+	{
+		/* print blank line separating entries */
+		if (datetime != "")
+		{
+			printf ("%s| %10d|%s\n", datetime, NR, "");
+			printf ("%s| %10d|%s\n", datetime, NR, "---");
+			printf ("%s| %10d|%s\n", datetime, NR+1, "");
+		}
+	}
+
+	$0 ~ /^====*$/ || $0 ~ /^----*$/ \
+	{
+		datetime="";
+		skip="N";
+	}
+
+	datetime != "" && skip == "N" \
+		{printf ("%s| %10d| %s\n", datetime, NR, $0);}
+
+	$1 == "date:"	\
+	{
+		/* get entry date */
+		datetime=$2"-"$3
+		if (workingfile != "" && skip == "N")
+		{
+			printf ("%s| %10d|%s\n", datetime, NR-1, workingfile);
+			printf ("%s| %10d|%s\n", datetime, NR, $0);
+			printf ("%s| %10d|%s\n", datetime, NR+1, "");
+		}
+	}
+
+	$0 ~ /^====*$/ 			{workingfile=""}' |
+
+sort | cut -d'|' -f3 | cat |
+
+# collect duplicate narratives
+awk '	BEGIN	{ slot = 0;}
+	{
+		if ($0 ~ /^Working file:/)
+		{
+			if (slot != oldslot)
+				same = 0;
+			else
+			{
+				same = 1;
+				for (i=1; i <= slot; i++)
+				{
+					if (oldnarr[i] != narr[i])
+						same = 0;
+				}
+			}
+
+			if (oldslot && !same)
+				for (i=1; i <= oldslot; i++)
+					print oldnarr[i];
+			for (i=1; i <= slot; i++)
+				oldnarr[i] = narr[i];
+			oldslot = slot;
+			slot = 0;
+			print save_working;
+			save_working = $0;
+ 		}
+		else if ($1 != "date:")
+			narr[++slot] = $0;
+	}
+	END	{
+			print save_working;
+			for (i=1; i <= slot; i++)
+				print narr[i];
+		}'
-- 
GitLab