PdoAdapter.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Cache\Adapter;
  11. use Doctrine\DBAL\Connection;
  12. use Doctrine\DBAL\DBALException;
  13. use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
  14. use Doctrine\DBAL\DriverManager;
  15. use Doctrine\DBAL\Exception;
  16. use Doctrine\DBAL\Exception\TableNotFoundException;
  17. use Doctrine\DBAL\Schema\Schema;
  18. use Symfony\Component\Cache\Exception\InvalidArgumentException;
  19. use Symfony\Component\Cache\Marshaller\DefaultMarshaller;
  20. use Symfony\Component\Cache\Marshaller\MarshallerInterface;
  21. use Symfony\Component\Cache\PruneableInterface;
  22. class PdoAdapter extends AbstractAdapter implements PruneableInterface
  23. {
  24. protected $maxIdLength = 255;
  25. private $marshaller;
  26. private $conn;
  27. private $dsn;
  28. private $driver;
  29. private $serverVersion;
  30. private $table = 'cache_items';
  31. private $idCol = 'item_id';
  32. private $dataCol = 'item_data';
  33. private $lifetimeCol = 'item_lifetime';
  34. private $timeCol = 'item_time';
  35. private $username = '';
  36. private $password = '';
  37. private $connectionOptions = [];
  38. private $namespace;
  39. /**
  40. * You can either pass an existing database connection as PDO instance or
  41. * a Doctrine DBAL Connection or a DSN string that will be used to
  42. * lazy-connect to the database when the cache is actually used.
  43. *
  44. * When a Doctrine DBAL Connection is passed, the cache table is created
  45. * automatically when possible. Otherwise, use the createTable() method.
  46. *
  47. * List of available options:
  48. * * db_table: The name of the table [default: cache_items]
  49. * * db_id_col: The column where to store the cache id [default: item_id]
  50. * * db_data_col: The column where to store the cache data [default: item_data]
  51. * * db_lifetime_col: The column where to store the lifetime [default: item_lifetime]
  52. * * db_time_col: The column where to store the timestamp [default: item_time]
  53. * * db_username: The username when lazy-connect [default: '']
  54. * * db_password: The password when lazy-connect [default: '']
  55. * * db_connection_options: An array of driver-specific connection options [default: []]
  56. *
  57. * @param \PDO|Connection|string $connOrDsn a \PDO or Connection instance or DSN string or null
  58. *
  59. * @throws InvalidArgumentException When first argument is not PDO nor Connection nor string
  60. * @throws InvalidArgumentException When PDO error mode is not PDO::ERRMODE_EXCEPTION
  61. * @throws InvalidArgumentException When namespace contains invalid characters
  62. */
  63. public function __construct($connOrDsn, string $namespace = '', int $defaultLifetime = 0, array $options = [], MarshallerInterface $marshaller = null)
  64. {
  65. if (isset($namespace[0]) && preg_match('#[^-+.A-Za-z0-9]#', $namespace, $match)) {
  66. throw new InvalidArgumentException(sprintf('Namespace contains "%s" but only characters in [-+.A-Za-z0-9] are allowed.', $match[0]));
  67. }
  68. if ($connOrDsn instanceof \PDO) {
  69. if (\PDO::ERRMODE_EXCEPTION !== $connOrDsn->getAttribute(\PDO::ATTR_ERRMODE)) {
  70. throw new InvalidArgumentException(sprintf('"%s" requires PDO error mode attribute be set to throw Exceptions (i.e. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)).', __CLASS__));
  71. }
  72. $this->conn = $connOrDsn;
  73. } elseif ($connOrDsn instanceof Connection) {
  74. $this->conn = $connOrDsn;
  75. } elseif (\is_string($connOrDsn)) {
  76. $this->dsn = $connOrDsn;
  77. } else {
  78. throw new InvalidArgumentException(sprintf('"%s" requires PDO or Doctrine\DBAL\Connection instance or DSN string as first argument, "%s" given.', __CLASS__, get_debug_type($connOrDsn)));
  79. }
  80. $this->table = $options['db_table'] ?? $this->table;
  81. $this->idCol = $options['db_id_col'] ?? $this->idCol;
  82. $this->dataCol = $options['db_data_col'] ?? $this->dataCol;
  83. $this->lifetimeCol = $options['db_lifetime_col'] ?? $this->lifetimeCol;
  84. $this->timeCol = $options['db_time_col'] ?? $this->timeCol;
  85. $this->username = $options['db_username'] ?? $this->username;
  86. $this->password = $options['db_password'] ?? $this->password;
  87. $this->connectionOptions = $options['db_connection_options'] ?? $this->connectionOptions;
  88. $this->namespace = $namespace;
  89. $this->marshaller = $marshaller ?? new DefaultMarshaller();
  90. parent::__construct($namespace, $defaultLifetime);
  91. }
  92. /**
  93. * Creates the table to store cache items which can be called once for setup.
  94. *
  95. * Cache ID are saved in a column of maximum length 255. Cache data is
  96. * saved in a BLOB.
  97. *
  98. * @throws \PDOException When the table already exists
  99. * @throws DBALException When the table already exists
  100. * @throws Exception When the table already exists
  101. * @throws \DomainException When an unsupported PDO driver is used
  102. */
  103. public function createTable()
  104. {
  105. // connect if we are not yet
  106. $conn = $this->getConnection();
  107. if ($conn instanceof Connection) {
  108. $schema = new Schema();
  109. $this->addTableToSchema($schema);
  110. foreach ($schema->toSql($conn->getDatabasePlatform()) as $sql) {
  111. if (method_exists($conn, 'executeStatement')) {
  112. $conn->executeStatement($sql);
  113. } else {
  114. $conn->exec($sql);
  115. }
  116. }
  117. return;
  118. }
  119. switch ($this->driver) {
  120. case 'mysql':
  121. // We use varbinary for the ID column because it prevents unwanted conversions:
  122. // - character set conversions between server and client
  123. // - trailing space removal
  124. // - case-insensitivity
  125. // - language processing like é == e
  126. $sql = "CREATE TABLE $this->table ($this->idCol VARBINARY(255) NOT NULL PRIMARY KEY, $this->dataCol MEDIUMBLOB NOT NULL, $this->lifetimeCol INTEGER UNSIGNED, $this->timeCol INTEGER UNSIGNED NOT NULL) COLLATE utf8_bin, ENGINE = InnoDB";
  127. break;
  128. case 'sqlite':
  129. $sql = "CREATE TABLE $this->table ($this->idCol TEXT NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol INTEGER, $this->timeCol INTEGER NOT NULL)";
  130. break;
  131. case 'pgsql':
  132. $sql = "CREATE TABLE $this->table ($this->idCol VARCHAR(255) NOT NULL PRIMARY KEY, $this->dataCol BYTEA NOT NULL, $this->lifetimeCol INTEGER, $this->timeCol INTEGER NOT NULL)";
  133. break;
  134. case 'oci':
  135. $sql = "CREATE TABLE $this->table ($this->idCol VARCHAR2(255) NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol INTEGER, $this->timeCol INTEGER NOT NULL)";
  136. break;
  137. case 'sqlsrv':
  138. $sql = "CREATE TABLE $this->table ($this->idCol VARCHAR(255) NOT NULL PRIMARY KEY, $this->dataCol VARBINARY(MAX) NOT NULL, $this->lifetimeCol INTEGER, $this->timeCol INTEGER NOT NULL)";
  139. break;
  140. default:
  141. throw new \DomainException(sprintf('Creating the cache table is currently not implemented for PDO driver "%s".', $this->driver));
  142. }
  143. if (method_exists($conn, 'executeStatement')) {
  144. $conn->executeStatement($sql);
  145. } else {
  146. $conn->exec($sql);
  147. }
  148. }
  149. /**
  150. * Adds the Table to the Schema if the adapter uses this Connection.
  151. */
  152. public function configureSchema(Schema $schema, Connection $forConnection): void
  153. {
  154. // only update the schema for this connection
  155. if ($forConnection !== $this->getConnection()) {
  156. return;
  157. }
  158. if ($schema->hasTable($this->table)) {
  159. return;
  160. }
  161. $this->addTableToSchema($schema);
  162. }
  163. /**
  164. * {@inheritdoc}
  165. */
  166. public function prune()
  167. {
  168. $deleteSql = "DELETE FROM $this->table WHERE $this->lifetimeCol + $this->timeCol <= :time";
  169. if ('' !== $this->namespace) {
  170. $deleteSql .= " AND $this->idCol LIKE :namespace";
  171. }
  172. try {
  173. $delete = $this->getConnection()->prepare($deleteSql);
  174. } catch (TableNotFoundException $e) {
  175. return true;
  176. } catch (\PDOException $e) {
  177. return true;
  178. }
  179. $delete->bindValue(':time', time(), \PDO::PARAM_INT);
  180. if ('' !== $this->namespace) {
  181. $delete->bindValue(':namespace', sprintf('%s%%', $this->namespace), \PDO::PARAM_STR);
  182. }
  183. try {
  184. return $delete->execute();
  185. } catch (TableNotFoundException $e) {
  186. return true;
  187. } catch (\PDOException $e) {
  188. return true;
  189. }
  190. }
  191. /**
  192. * {@inheritdoc}
  193. */
  194. protected function doFetch(array $ids)
  195. {
  196. $now = time();
  197. $expired = [];
  198. $sql = str_pad('', (\count($ids) << 1) - 1, '?,');
  199. $sql = "SELECT $this->idCol, CASE WHEN $this->lifetimeCol IS NULL OR $this->lifetimeCol + $this->timeCol > ? THEN $this->dataCol ELSE NULL END FROM $this->table WHERE $this->idCol IN ($sql)";
  200. $stmt = $this->getConnection()->prepare($sql);
  201. $stmt->bindValue($i = 1, $now, \PDO::PARAM_INT);
  202. foreach ($ids as $id) {
  203. $stmt->bindValue(++$i, $id);
  204. }
  205. $result = $stmt->execute();
  206. if (\is_object($result)) {
  207. $result = $result->iterateNumeric();
  208. } else {
  209. $stmt->setFetchMode(\PDO::FETCH_NUM);
  210. $result = $stmt;
  211. }
  212. foreach ($result as $row) {
  213. if (null === $row[1]) {
  214. $expired[] = $row[0];
  215. } else {
  216. yield $row[0] => $this->marshaller->unmarshall(\is_resource($row[1]) ? stream_get_contents($row[1]) : $row[1]);
  217. }
  218. }
  219. if ($expired) {
  220. $sql = str_pad('', (\count($expired) << 1) - 1, '?,');
  221. $sql = "DELETE FROM $this->table WHERE $this->lifetimeCol + $this->timeCol <= ? AND $this->idCol IN ($sql)";
  222. $stmt = $this->getConnection()->prepare($sql);
  223. $stmt->bindValue($i = 1, $now, \PDO::PARAM_INT);
  224. foreach ($expired as $id) {
  225. $stmt->bindValue(++$i, $id);
  226. }
  227. $stmt->execute();
  228. }
  229. }
  230. /**
  231. * {@inheritdoc}
  232. */
  233. protected function doHave(string $id)
  234. {
  235. $sql = "SELECT 1 FROM $this->table WHERE $this->idCol = :id AND ($this->lifetimeCol IS NULL OR $this->lifetimeCol + $this->timeCol > :time)";
  236. $stmt = $this->getConnection()->prepare($sql);
  237. $stmt->bindValue(':id', $id);
  238. $stmt->bindValue(':time', time(), \PDO::PARAM_INT);
  239. $result = $stmt->execute();
  240. return (bool) (\is_object($result) ? $result->fetchOne() : $stmt->fetchColumn());
  241. }
  242. /**
  243. * {@inheritdoc}
  244. */
  245. protected function doClear(string $namespace)
  246. {
  247. $conn = $this->getConnection();
  248. if ('' === $namespace) {
  249. if ('sqlite' === $this->driver) {
  250. $sql = "DELETE FROM $this->table";
  251. } else {
  252. $sql = "TRUNCATE TABLE $this->table";
  253. }
  254. } else {
  255. $sql = "DELETE FROM $this->table WHERE $this->idCol LIKE '$namespace%'";
  256. }
  257. try {
  258. if (method_exists($conn, 'executeStatement')) {
  259. $conn->executeStatement($sql);
  260. } else {
  261. $conn->exec($sql);
  262. }
  263. } catch (TableNotFoundException $e) {
  264. } catch (\PDOException $e) {
  265. }
  266. return true;
  267. }
  268. /**
  269. * {@inheritdoc}
  270. */
  271. protected function doDelete(array $ids)
  272. {
  273. $sql = str_pad('', (\count($ids) << 1) - 1, '?,');
  274. $sql = "DELETE FROM $this->table WHERE $this->idCol IN ($sql)";
  275. try {
  276. $stmt = $this->getConnection()->prepare($sql);
  277. $stmt->execute(array_values($ids));
  278. } catch (TableNotFoundException $e) {
  279. } catch (\PDOException $e) {
  280. }
  281. return true;
  282. }
  283. /**
  284. * {@inheritdoc}
  285. */
  286. protected function doSave(array $values, int $lifetime)
  287. {
  288. if (!$values = $this->marshaller->marshall($values, $failed)) {
  289. return $failed;
  290. }
  291. $conn = $this->getConnection();
  292. $driver = $this->driver;
  293. $insertSql = "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:id, :data, :lifetime, :time)";
  294. switch (true) {
  295. case 'mysql' === $driver:
  296. $sql = $insertSql." ON DUPLICATE KEY UPDATE $this->dataCol = VALUES($this->dataCol), $this->lifetimeCol = VALUES($this->lifetimeCol), $this->timeCol = VALUES($this->timeCol)";
  297. break;
  298. case 'oci' === $driver:
  299. // DUAL is Oracle specific dummy table
  300. $sql = "MERGE INTO $this->table USING DUAL ON ($this->idCol = ?) ".
  301. "WHEN NOT MATCHED THEN INSERT ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (?, ?, ?, ?) ".
  302. "WHEN MATCHED THEN UPDATE SET $this->dataCol = ?, $this->lifetimeCol = ?, $this->timeCol = ?";
  303. break;
  304. case 'sqlsrv' === $driver && version_compare($this->getServerVersion(), '10', '>='):
  305. // MERGE is only available since SQL Server 2008 and must be terminated by semicolon
  306. // It also requires HOLDLOCK according to http://weblogs.sqlteam.com/dang/archive/2009/01/31/UPSERT-Race-Condition-With-MERGE.aspx
  307. $sql = "MERGE INTO $this->table WITH (HOLDLOCK) USING (SELECT 1 AS dummy) AS src ON ($this->idCol = ?) ".
  308. "WHEN NOT MATCHED THEN INSERT ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (?, ?, ?, ?) ".
  309. "WHEN MATCHED THEN UPDATE SET $this->dataCol = ?, $this->lifetimeCol = ?, $this->timeCol = ?;";
  310. break;
  311. case 'sqlite' === $driver:
  312. $sql = 'INSERT OR REPLACE'.substr($insertSql, 6);
  313. break;
  314. case 'pgsql' === $driver && version_compare($this->getServerVersion(), '9.5', '>='):
  315. $sql = $insertSql." ON CONFLICT ($this->idCol) DO UPDATE SET ($this->dataCol, $this->lifetimeCol, $this->timeCol) = (EXCLUDED.$this->dataCol, EXCLUDED.$this->lifetimeCol, EXCLUDED.$this->timeCol)";
  316. break;
  317. default:
  318. $driver = null;
  319. $sql = "UPDATE $this->table SET $this->dataCol = :data, $this->lifetimeCol = :lifetime, $this->timeCol = :time WHERE $this->idCol = :id";
  320. break;
  321. }
  322. $now = time();
  323. $lifetime = $lifetime ?: null;
  324. try {
  325. $stmt = $conn->prepare($sql);
  326. } catch (TableNotFoundException $e) {
  327. if (!$conn->isTransactionActive() || \in_array($this->driver, ['pgsql', 'sqlite', 'sqlsrv'], true)) {
  328. $this->createTable();
  329. }
  330. $stmt = $conn->prepare($sql);
  331. } catch (\PDOException $e) {
  332. if (!$conn->inTransaction() || \in_array($this->driver, ['pgsql', 'sqlite', 'sqlsrv'], true)) {
  333. $this->createTable();
  334. }
  335. $stmt = $conn->prepare($sql);
  336. }
  337. if ('sqlsrv' === $driver || 'oci' === $driver) {
  338. $stmt->bindParam(1, $id);
  339. $stmt->bindParam(2, $id);
  340. $stmt->bindParam(3, $data, \PDO::PARAM_LOB);
  341. $stmt->bindValue(4, $lifetime, \PDO::PARAM_INT);
  342. $stmt->bindValue(5, $now, \PDO::PARAM_INT);
  343. $stmt->bindParam(6, $data, \PDO::PARAM_LOB);
  344. $stmt->bindValue(7, $lifetime, \PDO::PARAM_INT);
  345. $stmt->bindValue(8, $now, \PDO::PARAM_INT);
  346. } else {
  347. $stmt->bindParam(':id', $id);
  348. $stmt->bindParam(':data', $data, \PDO::PARAM_LOB);
  349. $stmt->bindValue(':lifetime', $lifetime, \PDO::PARAM_INT);
  350. $stmt->bindValue(':time', $now, \PDO::PARAM_INT);
  351. }
  352. if (null === $driver) {
  353. $insertStmt = $conn->prepare($insertSql);
  354. $insertStmt->bindParam(':id', $id);
  355. $insertStmt->bindParam(':data', $data, \PDO::PARAM_LOB);
  356. $insertStmt->bindValue(':lifetime', $lifetime, \PDO::PARAM_INT);
  357. $insertStmt->bindValue(':time', $now, \PDO::PARAM_INT);
  358. }
  359. foreach ($values as $id => $data) {
  360. try {
  361. $result = $stmt->execute();
  362. } catch (TableNotFoundException $e) {
  363. if (!$conn->isTransactionActive() || \in_array($this->driver, ['pgsql', 'sqlite', 'sqlsrv'], true)) {
  364. $this->createTable();
  365. }
  366. $result = $stmt->execute();
  367. } catch (\PDOException $e) {
  368. if (!$conn->inTransaction() || \in_array($this->driver, ['pgsql', 'sqlite', 'sqlsrv'], true)) {
  369. $this->createTable();
  370. }
  371. $result = $stmt->execute();
  372. }
  373. if (null === $driver && !(\is_object($result) ? $result->rowCount() : $stmt->rowCount())) {
  374. try {
  375. $insertStmt->execute();
  376. } catch (DBALException | Exception $e) {
  377. } catch (\PDOException $e) {
  378. // A concurrent write won, let it be
  379. }
  380. }
  381. }
  382. return $failed;
  383. }
  384. /**
  385. * @return \PDO|Connection
  386. */
  387. private function getConnection(): object
  388. {
  389. if (null === $this->conn) {
  390. if (strpos($this->dsn, '://')) {
  391. if (!class_exists(DriverManager::class)) {
  392. throw new InvalidArgumentException(sprintf('Failed to parse the DSN "%s". Try running "composer require doctrine/dbal".', $this->dsn));
  393. }
  394. $this->conn = DriverManager::getConnection(['url' => $this->dsn]);
  395. } else {
  396. $this->conn = new \PDO($this->dsn, $this->username, $this->password, $this->connectionOptions);
  397. $this->conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
  398. }
  399. }
  400. if (null === $this->driver) {
  401. if ($this->conn instanceof \PDO) {
  402. $this->driver = $this->conn->getAttribute(\PDO::ATTR_DRIVER_NAME);
  403. } else {
  404. $driver = $this->conn->getDriver();
  405. switch (true) {
  406. case $driver instanceof \Doctrine\DBAL\Driver\Mysqli\Driver:
  407. throw new \LogicException(sprintf('The adapter "%s" does not support the mysqli driver, use pdo_mysql instead.', static::class));
  408. case $driver instanceof \Doctrine\DBAL\Driver\AbstractMySQLDriver:
  409. $this->driver = 'mysql';
  410. break;
  411. case $driver instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver:
  412. case $driver instanceof \Doctrine\DBAL\Driver\PDO\SQLite\Driver:
  413. $this->driver = 'sqlite';
  414. break;
  415. case $driver instanceof \Doctrine\DBAL\Driver\PDOPgSql\Driver:
  416. case $driver instanceof \Doctrine\DBAL\Driver\PDO\PgSQL\Driver:
  417. $this->driver = 'pgsql';
  418. break;
  419. case $driver instanceof \Doctrine\DBAL\Driver\OCI8\Driver:
  420. case $driver instanceof \Doctrine\DBAL\Driver\PDOOracle\Driver:
  421. case $driver instanceof \Doctrine\DBAL\Driver\PDO\OCI\Driver:
  422. $this->driver = 'oci';
  423. break;
  424. case $driver instanceof \Doctrine\DBAL\Driver\SQLSrv\Driver:
  425. case $driver instanceof \Doctrine\DBAL\Driver\PDOSqlsrv\Driver:
  426. case $driver instanceof \Doctrine\DBAL\Driver\PDO\SQLSrv\Driver:
  427. $this->driver = 'sqlsrv';
  428. break;
  429. default:
  430. $this->driver = \get_class($driver);
  431. break;
  432. }
  433. }
  434. }
  435. return $this->conn;
  436. }
  437. private function getServerVersion(): string
  438. {
  439. if (null === $this->serverVersion) {
  440. $conn = $this->conn instanceof \PDO ? $this->conn : $this->conn->getWrappedConnection();
  441. if ($conn instanceof \PDO) {
  442. $this->serverVersion = $conn->getAttribute(\PDO::ATTR_SERVER_VERSION);
  443. } elseif ($conn instanceof ServerInfoAwareConnection) {
  444. $this->serverVersion = $conn->getServerVersion();
  445. } else {
  446. $this->serverVersion = '0';
  447. }
  448. }
  449. return $this->serverVersion;
  450. }
  451. private function addTableToSchema(Schema $schema): void
  452. {
  453. $types = [
  454. 'mysql' => 'binary',
  455. 'sqlite' => 'text',
  456. 'pgsql' => 'string',
  457. 'oci' => 'string',
  458. 'sqlsrv' => 'string',
  459. ];
  460. if (!isset($types[$this->driver])) {
  461. throw new \DomainException(sprintf('Creating the cache table is currently not implemented for PDO driver "%s".', $this->driver));
  462. }
  463. $table = $schema->createTable($this->table);
  464. $table->addColumn($this->idCol, $types[$this->driver], ['length' => 255]);
  465. $table->addColumn($this->dataCol, 'blob', ['length' => 16777215]);
  466. $table->addColumn($this->lifetimeCol, 'integer', ['unsigned' => true, 'notnull' => false]);
  467. $table->addColumn($this->timeCol, 'integer', ['unsigned' => true]);
  468. $table->setPrimaryKey([$this->idCol]);
  469. }
  470. }