title: ALTER TABLE CREATE CONSTRAINT IF NOT EXIST possible?
body: <p>I have an application which starts (AppStarter) a web server with a web application. The Web Application has migration scripts (flyway).</p>
  
  <p>I want to write some data from AppStarter through JDBC in a table. But I want to create the table if it does not exist. The table also has some constraints.</p>
  
  <p>Within the AppStarter I execute following command:</p>
  
  <pre><code>CREATE CACHED TABLE PUBLIC.CORE_USERROLE_TO_PARAMETER (
      ID VARCHAR(32) PRIMARY KEY NOT NULL,
      VERSION INTEGER,
      USER_ID VARCHAR(32)NOT NULL,
      ROLE_ID VARCHAR(32) NOT NULL,
      PARAMETER VARCHAR(255) NOT NULL
  );
  
  ALTER TABLE PUBLIC.CORE_USERROLE_TO_PARAMETER ADD CONSTRAINT PUBLIC.CURTBP_USER_ID FOREIGN KEY(USER_ID) REFERENCES PUBLIC.CORE_USER(ID) NOCHECK;
  ALTER TABLE PUBLIC.CORE_USERROLE_TO_PARAMETER ADD CONSTRAINT PUBLIC.CURTBP_ROLE_ID FOREIGN KEY(ROLE_ID) REFERENCES PUBLIC.CORE_USER_ROLE(ID) NOCHECK;
  </code></pre>
  
  <p>The web app also reads some information from this table and creates the tables. 
  Now I have a sql migration script</p>
  
  <pre><code>CREATE CACHED TABLE IF NOT EXISTS PUBLIC.CORE_USERROLE_TO_PARAMETER (
      ID VARCHAR(32) PRIMARY KEY NOT NULL,
      VERSION INTEGER,
      USER_ID VARCHAR(32)NOT NULL,
      ROLE_ID VARCHAR(32) NOT NULL,
      PARAMETER VARCHAR(255) NOT NULL
  );
  </code></pre>
  
  <p>But how do I create the constraint only if they does not already exist? </p>
  
  <p>Thanks in advance</p>
  
  <p>Currently I can get if the constraints exists with </p>
  
  <pre><code>select * from INFORMATION_SCHEMA.CONSTRAINTS WHERE CONSTRAINT_NAME='CURTRP_USER_ID'
  </code></pre>
  
  <p>but how do I build this into a if query with H2</p>
  
  <p><strong>Edit:</strong>
  I could move the constraint part in total to the migration script, but this seems somehow wrong. </p>
  
  <p>I am working with H2 Database.</p>