X
X
xbox2015-01-19 12:46:02
symfony
xbox, 2015-01-19 12:46:02

How to add database fields and tables to a working project on Symfony 1.2 in order not to break anything?

Good afternoon.
A small introduction.
There is a working site on Symfony 1.2, which was created by one good web studio. (This is to the fact that the quality of the code is normal and the project was initially sharpened for the joint work of several programmers). We have not been using the services of the web studio for the last couple of years, because even small changes take a lot of time and money. It's usually quicker and easier to do everything yourself.
I am a littleI have programming skills in php and make changes on my own, but I know Symfony very superficially. During the time that I am editing the site, I figured out the folder structure in the project. Modules, templates, layouts, actions, routing in siphon - this is what I mastered. I can't work with classes. Changing something that exists in a project is usually not a problem for me, but in many cases I myself cannot create something new.

Often there is a need to add a field to an existing database table or even create a new table. Making changes to the Mysql database (via phpmyadmin etc) is not a problem.
But how to add a field to the database table or create a new table in the database, so that in all places where it is necessary, the symphony registers everything, and so that the working draft does not break, and the data in the site database is preserved?
If I access an existing table field, for example, $item->getTitle(), then after adding a new field to the database, I can access it like this $item->getNewfield() ? With the correct addition of the field, will Symphony write everything that is needed for this?
PS Symfony uses Propel.
And one more thing, just in case. I have manually created/changed table indexes in a working Mysql database. The indexes are working correctly. But in any configs, the symphony did not prescribe anything. When changing the structure of the database with symphony commands, I would not want these indexes to fly off.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
silentvick, 2015-01-19
@xbox

Обязательно перед изменениями сделайте бэкап
Начать стоит со схемы в файле config/schema.yml , которая хранит описание структуры БД. Для новой таблицы надо будет описать ее схему в этом файле. Новое поле добавить проще: надо просто дописать его объявление к уже существующей схеме таблицы. Делайте по примеру уже написанных схем. Если задуманная структура не очень сложная, то это не должно составить труда. Также советую заглянуть в пример из документации.
Далее можно обновить саму БД. Сделать это можно вручную (например, через phpmyadmin). Также можно выполнить команду:
Это создаст sql-файл в data/sql директории, содержащий запросы для создания описанной структуры БД. Оттуда можно взять запрос для новой таблицы. Это исключит возможность несоответствия таблицы, созданной "вручную" от описанной в schema.yml.
Дальше следует обновить модели, формы и фильтры:
Это создаст классы моделей, форм и фильтров для новых таблиц, а также обновит свойства и методы для уже существующих классов при добавлении новых полей (можно будет вызывать $item->getNewfield()).
Don't forget to clear the cache afterwards:
This should be enough for simple changes.
PS: Indexes will not be lost, but they should still be written in the schema :)

Q
Quber, 2015-01-19
@Quber

Не знаю как это устроено в первой части. Работаю со второй. На dev версии это делается очень просто, одной командой:
Она создаст все необходимые поля, индексы, изменит где необходимо и что необходимо.
Для боевой версии это решение разработчики не рекомендуют:
Рекомендуется использовать миграции. Это бандл для доктрины DoctrineMigrationsBundle. Тут подробно написано про него и как им пользоваться symfony.com/doc/current/bundles/DoctrineMigrations...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question