· 4 years ago · May 19, 2021, 10:18 AM
1Adding DB table
2
3Can add in phpMyAdmin first - careful with types (smallint etc) to be accurate
4
5Generate Symfony entity with make:entity, a questionnaire that helps speed things up
6Produces file like src/Entity/OrdersStockLateLog.php
7
8Having got an entity, will need a repository to run proper functions via
9e.g. src/Repository/OrdersStockLateLogRepository.php
10
11
12Usage
13Use "getRepository" command on the Entity (not repository, confusingly!)
14The PHP docs helps Symfony find it
15 /** @var OrdersStockLateLogRepository $repo */
16 $repo = $this->entityManager->getRepository(OrdersStockLateLog::class);
17
18Then we can get rows with commands like "findOneBy"
19Or we can create a new instance of the entity and run setters on it, e.g.
20 $logEntry = new OrdersStockLateLog();
21 $logEntry->setLastUpdate(time());
22When changing things, remember to finish with persisting the entity, and a flush to make Doctrine run the SQL
23 $this->entityManager->persist($logEntry);
24 $this->entityManager->flush();
25
26
27In our source, "Controllers" are for display, not editing database - Model View Controller pattern where the Symfony controllers are confusingly forming the View
28
29
30
31Export table SQL from phpMyAdmin with command like
32 SHOW CREATE TABLE orders_stock_late_log
33
34Clear fluff after InnoDB, and it should be edited into the Merge Request description for easy access
35
36Create a schema file like _build/schema/baseline/newcre/orders_stock_late_log.schemal.sql
37At the start add something like -
38 CREATE DATABASE IF NOT EXISTS newcre;
39 USE newcre;
40
41Do you think the data should be in or out of the Prod-Dev data sync? It should be put as a line in
42src/Modules/ProdDevDataSync/DbTablesWithoutData.php
43or src/Modules/ProdDevDataSync/DbTablesWithData.php