Repository: shuttle-hq/synth (language: rust)

Issue:
Add foreign keys to test schemas
**What is wrong**
The end-to-end tests in our [testing harness](https://github.com/getsynth/synth/tree/master/synth/testing_harness) only test with schemas that do not include primary/foreign key relations.

As a result, we don't E2E test importing into the `same_as` generator and we are not able to detect breaking changes to the code that orders insertion into databases with PK/FK constraints.

**How to fix it**
Add constraints to the test schemas in the testing harness and modify the relevant imported synth schemas (e.g. [hospital_master](https://github.com/getsynth/synth/tree/master/synth/testing_harness/postgres/hospital_master)). This will probably also require changing some of the generated data we test against (e.g. [hospital_data_generated_master.json](https://github.com/getsynth/synth/blob/master/synth/testing_harness/postgres/hospital_data_generated_master.json)).


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/synth-postgres.yml b/.github/workflows/synth-postgres.yml
index 6d96a775..c4db8c57 100644
--- a/.github/workflows/synth-postgres.yml
+++ b/.github/workflows/synth-postgres.yml
@@ -2,11 +2,11 @@ name: synth-postgres
 
 on:
   push:
-    branches: [ master ]
-    paths: [ '**/*.rs' ]
+    branches: [master]
+    paths: ["**/*.rs", "synth/testing_harness/postgres/**"]
   pull_request:
-    branches: [ master ]
-    paths: [ '**/*.rs' ]
+    branches: [master]
+    paths: ["**/*.rs", "synth/testing_harness/postgres/**"]
 
   workflow_dispatch:
 
@@ -42,7 +42,7 @@ jobs:
       - run: |
           echo "Running generate test"
           cd synth/testing_harness/postgres
-          synth generate --size 10 hospital_master > hospital_data_generated.json
+          synth generate hospital_master > hospital_data_generated.json
           diff hospital_data_generated.json hospital_data_generated_master.json || exit 1
       - run: |
           echo "Testing import"
@@ -64,4 +64,4 @@ jobs:
             echo "got"
             echo $WARNINGS
             exit 1
-          fi
\ No newline at end of file
+          fi


Test patch:
diff --git a/synth/testing_harness/postgres/.gitignore b/synth/testing_harness/postgres/.gitignore
new file mode 100644
index 00000000..d8d5d5eb
--- /dev/null
+++ b/synth/testing_harness/postgres/.gitignore
@@ -0,0 +1,1 @@
+hospital_data_generated.json
diff --git a/synth/testing_harness/postgres/0_hospital_schema.sql b/synth/testing_harness/postgres/0_hospital_schema.sql
index a8fbda41..60f82e1d 100644
--- a/synth/testing_harness/postgres/0_hospital_schema.sql
+++ b/synth/testing_harness/postgres/0_hospital_schema.sql
@@ -12,7 +12,7 @@ drop table if exists doctors;
 create table doctors
 (
     id          int primary key,
-    hospital_id int,
+    hospital_id int references hospitals (id),
     name        varchar(255),
     date_joined date
 );
@@ -22,7 +22,7 @@ drop table if exists patients;
 create table patients
 (
     id          int primary key,
-    doctor_id   int,
+    doctor_id   int references doctors (id),
     name        varchar(255),
     date_joined date,
     address     varchar(255),
diff --git a/synth/testing_harness/postgres/e2e.sh b/synth/testing_harness/postgres/e2e.sh
index d44f643f..0cfa8a6f 100755
--- a/synth/testing_harness/postgres/e2e.sh
+++ b/synth/testing_harness/postgres/e2e.sh
@@ -16,7 +16,7 @@ synth init || exit 1
 
 # 1. generate test
 echo "Running generate test"
-synth generate --size 10 hospital_master > hospital_data_generated.json || exit 1
+synth generate hospital_master > hospital_data_generated.json || exit 1
 
 # check by diff against golden master
 diff hospital_data_generated.json hospital_data_generated_master.json || exit 1
diff --git a/synth/testing_harness/postgres/hospital_data_generated.json b/synth/testing_harness/postgres/hospital_data_generated.json
new file mode 100644
index 00000000..a9e29127
--- /dev/null
+++ b/synth/testing_harness/postgres/hospital_data_generated.json
@@ -0,0 +1,1 @@
+{"doctors":[{"date_joined":null,"hospital_id":1,"id":1,"name":"HsYUIjTQAfCUoicfTzNbfEOeEZJsv"},{"date_joined":null,"hospital_id":1,"id":2,"name":"AYdvXxD53ZAGMjFj6K46UIp8CF9xkuGd3DhU9RJyfK0myw5vJXdAqU9Ns9ycOsChvqaHH3Elg5zJaMuo2uftO97TSisawK2PCkqe45tki0A9IX6lWRkQXUjy"},{"date_joined":null,"hospital_id":1,"id":3,"name":null},{"date_joined":"2017-07-26","hospital_id":1,"id":4,"name":null},{"date_joined":"2013-09-22","hospital_id":1,"id":5,"name":"BdK5vp8UWEcCoDi7gDsY1UF8m6Wm8ntoJupczJWHsLAbgeeKzWI1FSANXVUnevpn5LL"},{"date_joined":"2015-10-22","hospital_id":1,"id":6,"name":null}],"hospitals":[{"address":"cWqH2zCQeBzOgiS4skLnjvARIONorhfKroxrFAEtscPPTz6chnuu0kk3rjIcCRZBj2aF9QBXLox31x9wYrj2SKdOTJymvI4iBE7PXD9HJYaHdUATGmPf1m0OcvFTpQNLGWUs7AiX3HYqNgdoSoUgNBQmRAXxBg9oFdaBL1tWkbY8jRmG6xjnchpv08FQOovJDr0nnq4m8","hospital_name":"ABt4ngpHa6VTIy2THCQ1DDEVBfxLTyPPXFObexN9KBTYdCScDhQdIOp4HOOK1QelPiVYziVjjG22myDgH6UxLFCDsN6RFrGuiGlWZy1kCN2AFAj","id":1}],"patients":[{"address":"nnyXvUk9SSNyc58DZ8LSPl","date_joined":"2019-05-24","doctor_id":1,"id":1,"name":null,"phone":null,"ssn":"GfrLO52ad"},{"address":null,"date_joined":null,"doctor_id":2,"id":2,"name":null,"phone":"pp93sJiwQApdmbIrQlU","ssn":null},{"address":null,"date_joined":null,"doctor_id":3,"id":3,"name":"vZ","phone":"BfgcME2jCs01ReQ","ssn":null},{"address":null,"date_joined":null,"doctor_id":4,"id":4,"name":null,"phone":"jZP5bvEBl5jAnNt","ssn":"zvY0d"},{"address":null,"date_joined":"2019-07-02","doctor_id":5,"id":5,"name":"P1WBZimZVnJLdz6flyRdthjTr5tdowR7GQbZoTdHui7EZTqVUW3snRjy6esftmtawTqGfov4rKIiI1UOaJV29rz0N77XBiD8VovPFXPSG4g3E9ruTlka7QShqhHU3ITYYSISxu2E5r9o8n9Rds89AQOnDikJjvUw5vMoAGfyICJ0Kb0S1aLS21UAHQD9q6SVIIJIg6d3imZDIbwKb7pyUpePW0tQwSf","phone":null,"ssn":null},{"address":null,"date_joined":null,"doctor_id":6,"id":6,"name":null,"phone":null,"ssn":null},{"address":null,"date_joined":null,"doctor_id":1,"id":7,"name":"CdT0YrhTGSZIfKDLedqdUs9BoFKnJvgMb1fYvhmi45S5Btk","phone":null,"ssn":null}]}
diff --git a/synth/testing_harness/postgres/hospital_data_generated_master.json b/synth/testing_harness/postgres/hospital_data_generated_master.json
index d89478cb..a9e29127 100644
--- a/synth/testing_harness/postgres/hospital_data_generated_master.json
+++ b/synth/testing_harness/postgres/hospital_data_generated_master.json
@@ -1,1 +1,1 @@
-{"doctors":[{"date_joined":"2017-12-25","hospital_id":1,"id":1,"name":null}],"hospitals":[{"address":"dTsr3zDyuf04ccmf55Wkr5LBWyGFzffnId25CeaBDJLYd15KF2uRb2noqulsLtX6HMlrAVC6HKHJqsUYlW4ykDizAFLHsbCXU7pJmesZRDNYcFy43p7G1e11ODKsFh8e","hospital_name":"NBQmRAXxBg9oFdaBL1tWkbY8jRmG6xjnchpv08FQOovJDr0nnq4m8Er3IxAhd0ccccvZciPCulne8nuQX0j8ddHUlNrw6dw6GpIWOLEDLCcJiZDj0fkbB9iV1guzLlgxS8zTqxpJM5Q6CBF1WKhZ7RYWt4a5NwKgihcWiKlU6NHDWh","id":1},{"address":null,"hospital_name":"2nhVel8NQPJ0PUL228jE0SCVmYnnuXwQqX5DJTAYdvXxD53ZAGMjFj6K46UIp8CF9xkuGd3DhU9RJyfK0myw5vJXdAqU9Ns9ycOsC","id":2},{"address":null,"hospital_name":"Kbm9rsF3f0q1zhjUz","id":3},{"address":"wK2PCkqe45tki0A9IX6lWRkQXUjy6rW6HqgDn1kX3mmKXj7HhjLDRRbw3vmLIlrw26rYtdNMeWlmayTleVzvHPCjZFTJm8SzGOe0iTASsVtZjQShDtfYkVEAZrDoCrO6VK5nnyXvUk9SSNyc58DZ8L","hospital_name":"2YC5ZY1WlGfrLO52adbvSgFUZCPhUaYCPT3QoQYHEA55ziZvgWRT78Tjn4j8m1zEG0vZJu0zxA9dIZCrd8NltfLA3xFy2ctNTT4n","id":4},{"address":null,"hospital_name":"pQZkiB6FADYFNtRzvY0diniut4z3JG270eww5CvhiQwG4Bj","id":5},{"address":null,"hospital_name":null,"id":6},{"address":"GQbZoTdHui7EZTqVUW3snRjy6esftm","hospital_name":null,"id":7}],"patients":[{"address":"T7Ud9qyEXSsQukTjLv3ptEn4sPadtrCXwxo96964WKpe4QIB9K1tqIcYVYm5jcHw5QDcYmtL42DAJLNjJgIlj1lNKFrZn8OkcSMfikcRDP1xGRiRMSVPMciC2Mq1tndRT2qvba9dmqzaF6fG7zwOy7C1Kg815SulhgcC9RxhAwcdJDjznRamVPxCBCdT0YrhTGSZIfKDLedqdUs9BoF","date_joined":null,"doctor_id":null,"id":1,"name":null,"phone":null,"ssn":null},{"address":"yCMTxtQOe55Nmk5mAcLOFK9WdeZiXnQQVqdRCNrlfPg4tg9JRTryU0BThh5BGZoIcRbmbySmrkAYSA8jIgZKoDvlacYKDmbnUErbwg3xRbCKEWZ8CxUXbU1Sv5OQFnZbRKmjAwVeqRSSJ7AUihkPesQsbjhY7sGRBVrnQMrikzZhKSxkeximiNZg2I7LAQHx0ojaw9OmdMYMsxVcJBX61fB1NbUrBZ63fAOpaPgtC","date_joined":"2018-01-12","doctor_id":13,"id":2,"name":null,"phone":"sTnaul","ssn":null},{"address":"MmhMZMRnBkNtw5h9YfxQXtVKixIucvh9kk4v3Fmuw6q0QYokvTXyIKXv2pT8VlCGqZ74SRf646sr0FEYve50TACTIgzdVLh79w64eIadVGK7QWJ6kpuvRtdMNIBJNDzF0VqqtBX7sLdKiwTelwQGgPvMHolvhTpQme5SnyxmgzKusz01bMS9l3nx3dD4fd5exyQG1CZAblSsXgsMGYoPkX8XTPALAUD63qxYahTbw9V57HteORc","date_joined":null,"doctor_id":10,"id":3,"name":"d64rAV4cHkjK89NJJdoZIVN03XgeKFEBxm5Y3t7Es41y6pykOZa1uvH5juNQUrbr4xZeQleBUijhFjRTZUdIyTC5wNhwO0ICtfIwdFgpGuigJs80myHxbj9RL","phone":null,"ssn":null}]}
+{"doctors":[{"date_joined":null,"hospital_id":1,"id":1,"name":"HsYUIjTQAfCUoicfTzNbfEOeEZJsv"},{"date_joined":null,"hospital_id":1,"id":2,"name":"AYdvXxD53ZAGMjFj6K46UIp8CF9xkuGd3DhU9RJyfK0myw5vJXdAqU9Ns9ycOsChvqaHH3Elg5zJaMuo2uftO97TSisawK2PCkqe45tki0A9IX6lWRkQXUjy"},{"date_joined":null,"hospital_id":1,"id":3,"name":null},{"date_joined":"2017-07-26","hospital_id":1,"id":4,"name":null},{"date_joined":"2013-09-22","hospital_id":1,"id":5,"name":"BdK5vp8UWEcCoDi7gDsY1UF8m6Wm8ntoJupczJWHsLAbgeeKzWI1FSANXVUnevpn5LL"},{"date_joined":"2015-10-22","hospital_id":1,"id":6,"name":null}],"hospitals":[{"address":"cWqH2zCQeBzOgiS4skLnjvARIONorhfKroxrFAEtscPPTz6chnuu0kk3rjIcCRZBj2aF9QBXLox31x9wYrj2SKdOTJymvI4iBE7PXD9HJYaHdUATGmPf1m0OcvFTpQNLGWUs7AiX3HYqNgdoSoUgNBQmRAXxBg9oFdaBL1tWkbY8jRmG6xjnchpv08FQOovJDr0nnq4m8","hospital_name":"ABt4ngpHa6VTIy2THCQ1DDEVBfxLTyPPXFObexN9KBTYdCScDhQdIOp4HOOK1QelPiVYziVjjG22myDgH6UxLFCDsN6RFrGuiGlWZy1kCN2AFAj","id":1}],"patients":[{"address":"nnyXvUk9SSNyc58DZ8LSPl","date_joined":"2019-05-24","doctor_id":1,"id":1,"name":null,"phone":null,"ssn":"GfrLO52ad"},{"address":null,"date_joined":null,"doctor_id":2,"id":2,"name":null,"phone":"pp93sJiwQApdmbIrQlU","ssn":null},{"address":null,"date_joined":null,"doctor_id":3,"id":3,"name":"vZ","phone":"BfgcME2jCs01ReQ","ssn":null},{"address":null,"date_joined":null,"doctor_id":4,"id":4,"name":null,"phone":"jZP5bvEBl5jAnNt","ssn":"zvY0d"},{"address":null,"date_joined":"2019-07-02","doctor_id":5,"id":5,"name":"P1WBZimZVnJLdz6flyRdthjTr5tdowR7GQbZoTdHui7EZTqVUW3snRjy6esftmtawTqGfov4rKIiI1UOaJV29rz0N77XBiD8VovPFXPSG4g3E9ruTlka7QShqhHU3ITYYSISxu2E5r9o8n9Rds89AQOnDikJjvUw5vMoAGfyICJ0Kb0S1aLS21UAHQD9q6SVIIJIg6d3imZDIbwKb7pyUpePW0tQwSf","phone":null,"ssn":null},{"address":null,"date_joined":null,"doctor_id":6,"id":6,"name":null,"phone":null,"ssn":null},{"address":null,"date_joined":null,"doctor_id":1,"id":7,"name":"CdT0YrhTGSZIfKDLedqdUs9BoFKnJvgMb1fYvhmi45S5Btk","phone":null,"ssn":null}]}
diff --git a/synth/testing_harness/postgres/hospital_master/doctors.json b/synth/testing_harness/postgres/hospital_master/doctors.json
index 153651e5..308108f0 100644
--- a/synth/testing_harness/postgres/hospital_master/doctors.json
+++ b/synth/testing_harness/postgres/hospital_master/doctors.json
@@ -29,22 +29,8 @@
       ]
     },
     "hospital_id": {
-      "type": "one_of",
-      "variants": [
-        {
-          "weight": 1.0,
-          "type": "number",
-          "range": {
-            "low": 1,
-            "high": 12
-          },
-          "subtype": "i32"
-        },
-        {
-          "weight": 1.0,
-          "type": "null"
-        }
-      ]
+      "type": "same_as",
+      "ref": "hospitals.content.id"
     },
     "id": {
       "type": "number",
diff --git a/synth/testing_harness/postgres/hospital_master/hospitals.json b/synth/testing_harness/postgres/hospital_master/hospitals.json
index 2404447e..65e1b335 100644
--- a/synth/testing_harness/postgres/hospital_master/hospitals.json
+++ b/synth/testing_harness/postgres/hospital_master/hospitals.json
@@ -45,4 +45,4 @@
       "subtype": "i32"
     }
   }
-}
\ No newline at end of file
+}
diff --git a/synth/testing_harness/postgres/hospital_master/patients.json b/synth/testing_harness/postgres/hospital_master/patients.json
index 60413540..7aa65a64 100644
--- a/synth/testing_harness/postgres/hospital_master/patients.json
+++ b/synth/testing_harness/postgres/hospital_master/patients.json
@@ -43,22 +43,8 @@
       ]
     },
     "doctor_id": {
-      "type": "one_of",
-      "variants": [
-        {
-          "weight": 1.0,
-          "type": "number",
-          "range": {
-            "low": 1,
-            "high": 19
-          },
-          "subtype": "i32"
-        },
-        {
-          "weight": 1.0,
-          "type": "null"
-        }
-      ]
+      "type": "same_as",
+      "ref": "doctors.content.id"
     },
     "id": {
       "type": "number",