Symfony2 field order in database table - php

I have generated 2 entities in my bundle and then using app/console doctrine:schema:update --force I recreate database schema. The order of fields that I have defined in the entities does not match the order of fields in the database table. Is there a way to control/define order in which fields are listed in the database table?
Thanks,
Z

It's not a problem; If you have generated the schema first then you updated it, the new fields will be just appended to current columns.
Furthermore you can find this different order for columns which has relationship which will be appended, too (on the generation time). In fact it does not create any issue; but if it's important to you, you can change the arrangement through one of the DataBase Management Tools (e.g. phpMyAdmin)

Related

How to copy over values from one column to another newly added column?

I am working on a web application that is up and running on a production server. I need to make some changes to the database but I am not sure what is the best way to go about this.
I have a table called Trips and it contains columns "maximum_guests", "minimum_guests", etc.
I need to add a column called "base_guests" and I want to give it a value of "maximum_guests" for existing entries in my table(production data). From this point forward Trips will only be created if both "base_guests" and "maximum_guests" are provided.
Is there a safe way to do this? I am using Php Symfony, mysql and doctrine if that helps.
You should first make an export of your database just in case. Then add the column to the table and run.
UPDATE Trips set base_guests = maximum_guests;
This will assign the value of maximum_guests to base_guests for each record in the Trips table.

Database design using Symfony2 and Doctrine for lookup tables

I have an entity that contains several choice fields and to normalize the database, the best way is to have these fields linked to a lookup table. The lookup tables are two columns with the first as the primary key as an integery type and the second is the lookup value, usually a string of several words.
To display an entity object, I need to query each lookup table to get the values. Is this the standard wy of doing it or does anyone else have another method? Should there be only one lookup table or would I need a different lookup for each field? I think I need one for each field since I have to allow a user to choose the field that applies to them and only want to show the appropiate choices for each field.
Everything is stored in doctrine and the database, correct? No arrays or simple lookup objects stored only in Symfony/php?
I am using this as a reference for my naming and creating queries
doctrine join multiple tables
In the end, I decided to add a lookup table to my database and add another entity to my Symfony project. The form to display the choice selection uses the entity type, and when I need to display the underlying selection in twig, I added a data transformer according to the docs from Symfony http://symfony.com/doc/current/cookbook/form/data_transformers.html

Cross database joins with Doctrine in PHP

I was reading about cross database joins in Doctrine on their blog: http://www.doctrine-project.org/blog/cross-database-joins.html
The problem is that whenever table name contains a dot (used to specify the database), doctrine:schema:update outputs Nothing to update - your database is already in sync with the current entity metadata. The command basically just ignores entities whose table name contains a dot.
This is normal and it is a limitation of the ORM/DBAL.
The Doctrine\ORM\Tools\SchemaTool uses a schema manager retrieved from your current connection.
The Doctrine\DBAL\Schema\AbstractSchemaManager reads the tables from the current connection's db, and not from all databases.
Therefore, you have to manually handle tables placed in different DBs, or use your own schema manager with your own listTables implementation.

Check for changes in database schema and update

At our company we have a business solution which includes CMS, CRM and several other systems.
These are installed in several domains, for each of our clients.
The systems are still in development, so new tables and fields are added to the database.
Each time we want to release a new version to our clients, i have to go through their database and insert the new fields and tables manually.
Is there a way that this could be done automatically(a script maybe that detects the new fields and tables and inserts them?)
We are using php and mysql.
We would like to avoid backing up the clients data, dropping the database tables, running the sql query to insert all the database tables(including the new ones) and then re-inserting the customers data. Is this possible?
Toad for MySQL
DB Extract, Compare-and-Search Utility — Lets you compare two MySQL databases, view the differences, and create the script to update the target.
What you are looking for is
ALTER TABLE 'xyz' ADD 'new_colum' INT(10) DEFAULT '0' NOT NULL;
or if you want to get rid of a colum
ALTER TABLE 'xyz' DROP 'new_colum';
Put all table edits into an update.php file and the either call and delete it once manually or try to select "new_colum" once and update the database when it's not present.
OR what I do: "I have a settingsfield "software version" and use this as a trigger to update my tables.
But since you have to install the new scripts anyways you can just call it manually.

How to sync mysql table fields with prefix

I want ask that, is there any easy way to synchronize mysql table fields?
Let me extend my question:
I have a mysql database driven site, and I want to use my table for more than one content provider (I can use only one table because of hosting features) by separating table prefix (like Wordpress does).
I need a way to copy all fields from current table and add a prefix (I'll specify) to all new entries (E.g : there are 2 fields, links, pages and I want to add new fields new_links, new_pages to current table automatically / all keys must be the same (I mean field id's, values etc..)).
After creating those fields, there should be a way to control that, if one or more new entry was added to original fields then new fields should be created in prefixed (new_) fields.
I'm not 100% sure that I'm getting the issue, but...
Adding two new columns to the table shouldn't be a problem:
ALTER TABLE foo ADD COLUMN new_links ...
You could keep them in sync from your application (problematic) or via a trigger.
Definitely time to upgrade hosting providers.

Categories