sfPostgresDoctrinePlugin - 1.2.26

A postgres doctrine plugin.

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


« Back to the Plugins Home

Signin


Forgot your password?
Create an account

Tools

Stats

advanced search
Information Readme Releases Changelog Contribute
Show source

sfPostgresDoctrinePlugin

The sfPostgresDoctrinePlugin is a symfony plugin that extends the sfDoctrinePlugin for Postgres database.

It gives you:

  • ability to have a real inheritance

  • schemas menagement

  • ability to omit tables in schema and model generation process

  • ability to have one to one relation in schema and models generating process

  • enums and objects menagement

  • behaviors menagement

  • views menagement

  • plugin model management

  • ability to use custom record class for all Doctrine_Record objects

  • ability to use custom table class for all Doctrine_Table objects

  • ability to use uppercase in names of schema, tables and columns

Installation

  • Install the plugin (via a package)

    symfony plugin:install sfPostgresDoctrinePlugin                 
    
  • Install the plugin (via a Subversion checkout)

    svn co http//svn.symfony-project.com/plugins/sfPostgresDoctrinePlugin/trunk plugins/sfPostgresDoctrinePlugin
    
  • Publich config

    symfony plugin:publish-configs
    
  • Activate the plugin in the config/ProjectConfiguration.class.php

    class ProjectConfiguration extends sfProjectConfiguration
    {
      public function setup()
      {
        $this->enablePlugins(array(
          'sfDoctrinePlugin', 
          'sfPostgresDoctrinePlugin',
          '...'
        ));
      }
    }

Plugins (IMPORTANT INDO!!!)

  • When you have already model for the plugins in db and you want to generate schema from db you must omit all tables for plugins in this process. The cause of that is plugin hava custom schema in his folder, and we cannot overwrite them!!!

    So you must use omit.yml file

    So in section tables in omit.yml file you must have tables to ommit, for example:

    tables:
        - 'sfdoctrineguarplugin.*'  #omit all tables in schema 'sfdoctrineguarplugin' 
        - 'public.sf*'              #omit all tables in schema 'public' starting with 'sf'
    

Schemas menagement

  • You always must tell in tableName attribute fullname of the table, which is schemaName.tableName and set the packege attribute to schemaName.Entities

    example:

    Vehicle:
        tableName: public.vehicles
        package: Public.Entities
        ...
    
    Car:
        tableName: car.infos
        package: Car.Entities
        ...
    
  • When you generating schema and model you do it the same way like for the sfDoctrinePlugin. The relations, inheritances and enums are building automatically, also when you write behaviors condition in config/sfPostgresDoctrinePlugin/behaviors.yml the behaviors are binding to the schema and the model. If you want't omit some table you must put them in config/sfPostgresDoctrinePlugin/omit.yml file.

    The naming of the model is automatically genereted. The main format is:

    [SchemaName]_[CanonicalizedTableName]_Item

    In relations:

    [SchemaName]_[CanonicalizedTableName]_Item / to one

    [SchemaName]_[CanonicalizedTableName]_Items / to many

    In relations when is more then one for the same table the format of the alias is:

    [SchemaName]_[CanonicalizedTableName]_Item_For[CanonicalizedColumnName] / to one

    [SchemaName]_[CanonicalizedTableName]_Items_For[CanonicalizedColumnName] / to many

  • When you building db you do it the same way like for the sfDoctrinePlugin.
    The creation of the schemas, inheritance, relations and object and enums defined in config/sfPostgresDoctrinePlugin/types.yml files is automatical. If in model or schemas are some views you must put them in config/sfPostgresDoctrinePlugin/omit.yml file (before it was views.yml but plugin has backward compability and also check this file) to omit generation process for them.

One to one relations

  • When you generating schema and model in onetoone.yml file you configure relations.

    example:

    Public_User_Item has many Public_UserData_Item and has relations Public_UserData_Items and should have one Public_UserData_Item so:

    Public_UserData_Item: Public_User_Item
    

    or

    Public_User_Item: Public_UserData_Item                  
    

Inheritance

  • in schema.yml file the only information is

    inheritance:
        extends: #ParentModelName#      
    

    example:

    Vehicle:
        tableName: public.vehicles
        package: Public.Entities
        ...
    
    Bikes:
        tableName: public.bikes
        package: Public.Entities
        inheritance:
            extends: Vehicle
        ...     
    
    Car:
        tableName: car.infos
        package: Car.Entities
        inheritence:
            extends: Vehicle
        ...
    
    Truck:
        tableName: public.trucks
        package: Public.Entities 
        inheritence:
            extends: Car
        ...
    

Enums and objects menagement

  • In config/sfPostgresDoctrinePlugin/types.yml are definition of enums and objects, which are considered in build-sql task:

    example:

    public.audit:       #full name of object (schemaName.objectName         
        body: >         #sql body of the object
            creator text,
            createtime timestamp with time zone,
            updator text,
            updatetime timestamp with time zone         
        tables: all     #to which tables check if we generating db 
                        #may be an array with full names of the tables [schemaName1.tableName1, schemaName2.tableName2] 
        params:
            all: audit  #columns name condition 
                        #may be an array of columns
            schemaName1.tableName1:
                - anotheraudit
                - mainaudit
            schemaName2.tableName2: [audit_a, audit_b]
    
    types.cars:     #for enums all above is the same 
        type: enum  #type attribute is a only difference
        body: >
            'car',
            'truck',
            'bus'               
        tables: car.infos
        params:
            car.infos: vehicle_type
    

Behaviors menagement

  • In plugins/sfPostgresDoctrinePlugin/config/behaviors.yml are definition of behaviors, which are considered in building model and schema tasks:

    example:

    Audit:  #name of the behavior
        tableName: all #to which tables check if we building model and schema
                       #may be an array with full names of the tables
        condition: 
            columns: audit # behavior are binding when table has this column
        params:
            all:
                info: 'some infos for all'
            car.infos:
                info: 'some infos only for car.infos table
    
    Versioning:
        tableName: all
        condition:
            columns: [current_from, current_to]  # behavior are binding when table has this two columns
        params: 
            all:
                column_from: current_from
                column_to: current_to 
    
    Privilege:
        tableName: all  # all table
        exclusions:     # except this collection
            - 'catalogs.*'
            - 'users.*'
            - 'public.*'
            - books.novels
        condition:      # without (!) and with columns   
            columns: ['!current_from', '!current_to', version]
          params:
            all:          
              operations: # for all permit insert and forbid update
                insert: permit
                update: forbidden
            sales.item:
              operations: # for one permit conditional update
                update: 
                  permit: internal_name #only this column can be update
            '*.common*':   # for this pattern forbidden unblocked insert -> (params:all) 
              operations:
                insert: forbidden
    

Views menagement

  • Command

    symfony doctrine:build-views-schema
    

    generate schema for views in config/genereted_views.yml

    For example next thing to do is copy this file to directory config/doctrine and build model

Plugin Model management

  • Generating model from plugin's schema.yml file make for every plugin custom package in lib/model/directory/plugins with name of the plugin, if no tableName attribute is defined in schema.yml for plugin.

  • Generating sql for plugin's model process make for every plugin custom schema in db with name of the plugin, if no tableName attribute is defined in schema.yml for plugin.

Custom Record Class

  • BaseDoctrineRecord.class.php in lib/model/doctrine catalog give you ability to override or implement custom method for all object in you model.

Custom Table Class

  • BaseDoctrineTable.class.php in lib/model/doctrine catalog give you ability to override or implement custom method for all tables in you model.

TODO

  • Ability to have stored procedures (with arguments) as normal model

  • Postgres array type implementing to special behavior (for totally automated process)

  • Custom type implementing to special behavior (for totally automated process)