@@ -5,7 +5,6 @@ fn run_infer_schema() {
55 let p = project ( "print_schema" ) . build ( ) ;
66 let db = database ( & p. database_url ( ) ) ;
77
8- // Make sure the project is setup
98 p. command ( "setup" ) . run ( ) ;
109
1110 db. execute ( "CREATE TABLE users1 (id INTEGER PRIMARY KEY);" ) ;
@@ -85,7 +84,6 @@ fn run_infer_schema_whitelist() {
8584 let p = project ( "print_schema_whitelist" ) . build ( ) ;
8685 let db = database ( & p. database_url ( ) ) ;
8786
88- // Make sure the project is setup
8987 p. command ( "setup" ) . run ( ) ;
9088
9189 db. execute ( "CREATE TABLE users1 (id INTEGER PRIMARY KEY);" ) ;
@@ -137,7 +135,6 @@ fn run_infer_schema_blacklist() {
137135 let p = project ( "print_schema_blacklist" ) . build ( ) ;
138136 let db = database ( & p. database_url ( ) ) ;
139137
140- // Make sure the project is setup
141138 p. command ( "setup" ) . run ( ) ;
142139
143140 db. execute ( "CREATE TABLE users1 (id INTEGER PRIMARY KEY);" ) ;
@@ -189,7 +186,6 @@ fn run_infer_schema_order() {
189186 let p = project ( "print_schema_order" ) . build ( ) ;
190187 let db = database ( & p. database_url ( ) ) ;
191188
192- // Make sure the project is setup
193189 p. command ( "setup" ) . run ( ) ;
194190
195191 db. execute ( "CREATE TABLE def (id INTEGER PRIMARY KEY);" ) ;
@@ -299,7 +295,6 @@ fn run_infer_schema_compound_primary_key() {
299295 let p = project ( "print_schema_compound_primary_key" ) . build ( ) ;
300296 let db = database ( & p. database_url ( ) ) ;
301297
302- // Make sure the project is setup
303298 p. command ( "setup" ) . run ( ) ;
304299
305300 db. execute ( "CREATE TABLE asd (id INTEGER, qsd INTEGER, PRIMARY KEY (id, qsd));" ) ;
@@ -361,7 +356,6 @@ fn print_schema_specifying_schema_name() {
361356 let p = project ( "print_schema_specifying_schema_name" ) . build ( ) ;
362357 let db = database ( & p. database_url ( ) ) ;
363358
364- // Make sure the project is setup
365359 p. command ( "setup" ) . run ( ) ;
366360
367361 db. execute ( "CREATE SCHEMA custom_schema" ) ;
@@ -390,3 +384,79 @@ r"pub mod custom_schema {
390384}
391385" ) ;
392386}
387+
388+ #[ test]
389+ #[ cfg( feature = "postgres" ) ]
390+ fn print_schema_with_foreign_keys ( ) {
391+ let p = project ( "print_schema_with_foreign_keys" ) . build ( ) ;
392+ let db = database ( & p. database_url ( ) ) ;
393+
394+ p. command ( "setup" ) . run ( ) ;
395+
396+ db. execute ( "CREATE TABLE users (id SERIAL PRIMARY KEY)" ) ;
397+ db. execute ( "CREATE TABLE posts (id SERIAL PRIMARY KEY, user_id INTEGER NOT NULL REFERENCES users)" ) ;
398+ db. execute ( "CREATE TABLE comments (id SERIAL PRIMARY KEY, post_id INTEGER NOT NULL REFERENCES posts)" ) ;
399+
400+ let result = p. command ( "print-schema" ) . run ( ) ;
401+
402+ assert ! ( result. is_success( ) , "Result was unsuccessful {:?}" , result) ;
403+
404+ assert_eq ! ( result. stdout( ) ,
405+ r"table! {
406+ /// Representation of the `comments` table.
407+ ///
408+ /// (Automatically generated by Diesel.)
409+ comments (id) {
410+ /// The `id` column of the `comments` table.
411+ ///
412+ /// Its SQL type is `Int4`.
413+ ///
414+ /// (Automatically generated by Diesel.)
415+ id -> Int4,
416+ /// The `post_id` column of the `comments` table.
417+ ///
418+ /// Its SQL type is `Int4`.
419+ ///
420+ /// (Automatically generated by Diesel.)
421+ post_id -> Int4,
422+ }
423+ }
424+
425+ table! {
426+ /// Representation of the `posts` table.
427+ ///
428+ /// (Automatically generated by Diesel.)
429+ posts (id) {
430+ /// The `id` column of the `posts` table.
431+ ///
432+ /// Its SQL type is `Int4`.
433+ ///
434+ /// (Automatically generated by Diesel.)
435+ id -> Int4,
436+ /// The `user_id` column of the `posts` table.
437+ ///
438+ /// Its SQL type is `Int4`.
439+ ///
440+ /// (Automatically generated by Diesel.)
441+ user_id -> Int4,
442+ }
443+ }
444+
445+ table! {
446+ /// Representation of the `users` table.
447+ ///
448+ /// (Automatically generated by Diesel.)
449+ users (id) {
450+ /// The `id` column of the `users` table.
451+ ///
452+ /// Its SQL type is `Int4`.
453+ ///
454+ /// (Automatically generated by Diesel.)
455+ id -> Int4,
456+ }
457+ }
458+
459+ joinable!(posts -> users (user_id));
460+ joinable!(comments -> posts (post_id));
461+ " ) ;
462+ }
0 commit comments