@@ -27,7 +27,7 @@ cfg_if::cfg_if! {
27
27
}
28
28
29
29
async fn create_tables( connection: & mut AsyncPgConnection ) {
30
- diesel:: sql_query( "CREATE TABLE users (
30
+ diesel:: sql_query( "CREATE TABLE IF NOT EXISTS users (
31
31
id SERIAL PRIMARY KEY,
32
32
name VARCHAR NOT NULL
33
33
)" ) . execute( connection) . await . unwrap( ) ;
@@ -36,7 +36,7 @@ cfg_if::cfg_if! {
36
36
) . execute( connection) . await . unwrap( ) ;
37
37
38
38
diesel:: sql_query(
39
- "CREATE TABLE animals (
39
+ "CREATE TABLE IF NOT EXISTS animals (
40
40
id SERIAL PRIMARY KEY,
41
41
species VARCHAR NOT NULL,
42
42
legs INTEGER NOT NULL,
@@ -50,7 +50,7 @@ cfg_if::cfg_if! {
50
50
. await . unwrap( ) ;
51
51
52
52
diesel:: sql_query(
53
- "CREATE TABLE posts (
53
+ "CREATE TABLE IF NOT EXISTS posts (
54
54
id SERIAL PRIMARY KEY,
55
55
user_id INTEGER NOT NULL,
56
56
title VARCHAR NOT NULL
@@ -61,7 +61,7 @@ cfg_if::cfg_if! {
61
61
(1, 'About Rust'),
62
62
(2, 'My first post too')" ) . execute( connection) . await . unwrap( ) ;
63
63
64
- diesel:: sql_query( "CREATE TABLE comments (
64
+ diesel:: sql_query( "CREATE TABLE IF NOT EXISTS comments (
65
65
id SERIAL PRIMARY KEY,
66
66
post_id INTEGER NOT NULL,
67
67
body VARCHAR NOT NULL
@@ -71,7 +71,7 @@ cfg_if::cfg_if! {
71
71
(2, 'Yay! I am learning Rust'),
72
72
(3, 'I enjoyed your post')" ) . execute( connection) . await . unwrap( ) ;
73
73
74
- diesel:: sql_query( "CREATE TABLE brands (
74
+ diesel:: sql_query( "CREATE TABLE IF NOT EXISTS brands (
75
75
id SERIAL PRIMARY KEY,
76
76
color VARCHAR NOT NULL DEFAULT 'Green',
77
77
accent VARCHAR DEFAULT 'Blue'
0 commit comments