@@ -22,13 +22,15 @@ class CreateTable extends AbstractSql
2222
2323 protected array $ constraints = [];
2424
25+ protected bool $ ifNotExists = false ;
26+
2527 protected bool $ isTemporary = false ;
2628
2729 /**
2830 * {@inheritDoc}
2931 */
3032 protected array $ specifications = [
31- self ::TABLE => 'CREATE %1$sTABLE %2$s ( ' ,
33+ self ::TABLE => 'CREATE %1$sTABLE %2$s%3$s ( ' ,
3234 self ::COLUMNS => [
3335 "\n %1 \$s " => [
3436 [1 => '%1$s ' , 'combinedby ' => ", \n " ],
@@ -51,6 +53,17 @@ public function __construct(string|TableIdentifier $table = '', bool $isTemporar
5153 $ this ->setTemporary ($ isTemporary );
5254 }
5355
56+ public function ifNotExists (bool $ ifNotExists = true ): static
57+ {
58+ $ this ->ifNotExists = $ ifNotExists ;
59+ return $ this ;
60+ }
61+
62+ public function getIfNotExists (): bool
63+ {
64+ return $ this ->ifNotExists ;
65+ }
66+
5467 public function setTemporary (string |int |bool $ temporary ): static
5568 {
5669 $ this ->isTemporary = (bool ) $ temporary ;
@@ -102,6 +115,7 @@ protected function processTable(?PlatformInterface $adapterPlatform = null): arr
102115 {
103116 return [
104117 $ this ->isTemporary ? 'TEMPORARY ' : '' ,
118+ $ this ->ifNotExists ? 'IF NOT EXISTS ' : '' ,
105119 $ this ->resolveTable ($ this ->table , $ adapterPlatform ),
106120 ];
107121 }
0 commit comments