4
4
5
5
namespace Atk4 \Data \Schema ;
6
6
7
- use Atk4 \Core \Exception ;
7
+ use Atk4 \Data \Exception ;
8
8
use Atk4 \Data \Field ;
9
9
use Atk4 \Data \FieldSqlExpression ;
10
10
use Atk4 \Data \Model ;
@@ -98,7 +98,9 @@ public function create(): self
98
98
99
99
public function drop (): self
100
100
{
101
- $ this ->getSchemaManager ()->dropTable ($ this ->getDatabasePlatform ()->quoteSingleIdentifier ($ this ->table ->getName ()));
101
+ $ this ->getSchemaManager ()
102
+ ->dropTable ($ this ->getDatabasePlatform ()->quoteSingleIdentifier ($ this ->table ->getName ()));
103
+
102
104
$ this ->createdTableNames = array_diff ($ this ->createdTableNames , [$ this ->table ->getName ()]);
103
105
104
106
return $ this ;
@@ -111,6 +113,19 @@ public function dropIfExists(): self
111
113
} catch (\Doctrine \DBAL \Exception |\Doctrine \DBAL \DBALException $ e ) {
112
114
}
113
115
116
+ $ this ->createdTableNames = array_diff ($ this ->createdTableNames , [$ this ->table ->getName ()]);
117
+
118
+ // OracleSchemaManager::dropTable() called in self::drop() above tries to drop AI,
119
+ // but if AI trigger is not present, AI sequence is not dropped
120
+ // https://github.com/doctrine/dbal/issues/4997
121
+ if ($ this ->getDatabasePlatform () instanceof OraclePlatform) {
122
+ $ dropTriggerSql = $ this ->getDatabasePlatform ()->getDropAutoincrementSql ($ this ->table ->getName ())[1 ];
123
+ try {
124
+ $ this ->connection ->expr ($ dropTriggerSql )->execute ();
125
+ } catch (Exception $ e ) {
126
+ }
127
+ }
128
+
114
129
return $ this ;
115
130
}
116
131
@@ -152,6 +167,7 @@ public function id(string $name = 'id'): self
152
167
$ options = [
153
168
'type ' => 'integer ' ,
154
169
'ref_type ' => self ::REF_TYPE_PRIMARY ,
170
+ 'mandatory ' => true ,
155
171
];
156
172
157
173
$ this ->field ($ name , $ options );
0 commit comments