[sqlalchemy] Re: Seperate History Tables

2009-03-30 Thread Suha Onay
It is done now. Thank you for all your help.
Suha


On Mon, Mar 30, 2009 at 17:06, Michael Bayer wrote:

>
>
> On Mar 30, 2009, at 5:10 AM, Suha Onay wrote:
>
> > The problem is i defined the history class with the following way
> > (examining the test_versioning file):
> > --
> > Base = declarative_base(metaclass=VersionedMeta)
> >
> > class User(Base):
> > __tablename__ = 'users'
> >
> > id = sa.Column(sa.Integer, primary_key=True)
> > name = sa.Column(sa.Unicode(12), info={'label': u'Kod Adı'})
> > fullname = sa.Column(sa.Unicode(40), info={'label': u'Adı ve
> > Soyadı'})
> >
> > User_History = User.__history_mapper__.class_
> >
> > def upgrade():
> > User.__table__.create(migrate_engine)
> >
> > def downgrade():
> > User.__table__.drop(migrate_engine)
> > --
> > With the upper mode definition, when i updated a user data, it says
> > that no users_history table defined.
> >
> > If in upgrade, add the line
> > "User_History.__table__.create(migrate_engine)", it says that:
> > type object 'UserHistory' has no attribute '__table__'
> >
> > How can i define the models?
>
> im going to assume that "define the models" means "create the
> tables".  if so, just call Base.metadata.create_all().
>
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Seperate History Tables

2009-03-30 Thread Michael Bayer


On Mar 30, 2009, at 5:10 AM, Suha Onay wrote:

> The problem is i defined the history class with the following way  
> (examining the test_versioning file):
> --
> Base = declarative_base(metaclass=VersionedMeta)
>
> class User(Base):
> __tablename__ = 'users'
>
> id = sa.Column(sa.Integer, primary_key=True)
> name = sa.Column(sa.Unicode(12), info={'label': u'Kod Adı'})
> fullname = sa.Column(sa.Unicode(40), info={'label': u'Adı ve  
> Soyadı'})
>
> User_History = User.__history_mapper__.class_
>
> def upgrade():
> User.__table__.create(migrate_engine)
>
> def downgrade():
> User.__table__.drop(migrate_engine)
> --
> With the upper mode definition, when i updated a user data, it says  
> that no users_history table defined.
>
> If in upgrade, add the line  
> "User_History.__table__.create(migrate_engine)", it says that:
> type object 'UserHistory' has no attribute '__table__'
>
> How can i define the models?

im going to assume that "define the models" means "create the  
tables".  if so, just call Base.metadata.create_all().


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Seperate History Tables

2009-03-30 Thread Michael Bayer


On Mar 30, 2009, at 4:32 AM, Suha Onay wrote:

> İnstalled nose and tested: no error
> It is OK now.
>
> To make it easy for the developers not to care about the history  
> tables and versioning, is it possible not to define _history models  
> manually and make history_meta to generate them automatically?


thats what the recipe posted does.   your class extends a declarative  
base with the versioning metaclass installed, and the _history models  
are created automatically without you ever having to see them.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Seperate History Tables

2009-03-30 Thread Suha Onay
The problem is i defined the history class with the following way (examining
the test_versioning file):
--
Base = declarative_base(metaclass=VersionedMeta)

class User(Base):
__tablename__ = 'users'

id = sa.Column(sa.Integer, primary_key=True)
name = sa.Column(sa.Unicode(12), info={'label': u'Kod Adı'})
fullname = sa.Column(sa.Unicode(40), info={'label': u'Adı ve Soyadı'})

User_History = User.__history_mapper__.class_

def upgrade():
User.__table__.create(migrate_engine)

def downgrade():
User.__table__.drop(migrate_engine)
--
With the upper mode definition, when i updated a user data, it says that no
users_history table defined.

If in upgrade, add the line "User_History.__table__.create(migrate_engine)",
it says that:
type object 'UserHistory' has no attribute '__table__'

How can i define the models?

Suha


On Mon, Mar 30, 2009 at 12:32, Suha Onay  wrote:

> İnstalled nose and tested: no error
> It is OK now.
>
> To make it easy for the developers not to care about the history tables and
> versioning, is it possible not to define _history models manually and make
> history_meta to generate them automatically?
>
> Suha
>
>
> On Fri, Mar 27, 2009 at 20:09, Michael Bayer wrote:
>
>>
>>
>> install nose and type "nosetests".
>>
>>
>> Suha Onay wrote:
>> >
>> > The version is ok: 0.5.3
>> > The problem is I don't know how to do the unit tests: no tests package.
>> > from tests import eq_, Comparable
>> >
>> > How can i do the unit tests?
>> >
>> > Suha
>> >
>> >
>> >
>> >
>> > On Thu, Mar 26, 2009 at 19:04, Michael Bayer 
>> > wrote:
>> >>
>> >> not sure.  make sure you're on 0.5.3.   do the unit tests included
>> >> with
>> >> the recipe pass ?
>> >>
>> >>
>> >> Suha Onay wrote:
>> >>> Thanks for the recipe.I faced with an error.
>> >>>
>> >>> The model is now:
>> >>>
>> --
>> >>> from history_meta import VersionedMeta
>> >>>
>> >>> Base = declarative_base(metaclass=VersionedMeta)
>> >>>
>> >>> class User(Base):
>> >>> __tablename__ = 'users'
>> >>>
>> >>> id = sa.Column(sa.Integer, primary_key=True)
>> >>> name = sa.Column(sa.Unicode(12))
>> >>> fullname = sa.Column(sa.Unicode(40))
>> >>> password = sa.Column(sa.Unicode(20))
>> >>> active = sa.Column(sa.Boolean())
>> >>> type = sa.Column(sa.SmallInteger())
>> >>> note = sa.Column(sa.Text())
>> >>> date_created = sa.Column(sa.Date())
>> >>>
>> --
>> >>> Session = sessionmaker(bind=engine, autocommit=False, autoflush=True,
>> >>> expire_on_commit=False, extension=VersionedListener())
>> >>>
>> --
>> >>>
>> >>> When inserting a new user, the error occurs:
>> >>> sqlite3:  -=>
>> ('(IntegrityError)
>> >>> users.version may not be NULL',)
>> >>> postgre:  -=>
>> ('(IntegrityError)
>> >>> null
>> >>> value in column "version" violates not-null constraint\n',)
>> >>>
>> >>> The code in history_meta creates the column version with default value
>> >>> 1:
>> >>> cls.version = Column('version', Integer, default=1, nullable=False)
>> >>>
>> >>> What is the reason?
>> >>> Thanks.
>> >>>
>> >>> Suha
>> >>>
>> >>>
>> >>>
>> >>> On Wed, Mar 25, 2009 at 17:17, Michael Bayer
>> >>> wrote:
>> >>>
>> 
>>  I've placed a recipe for this on the wiki at
>>  http://www.sqlalchemy.org/trac/wiki/UsageRecipes/LogVersions
>>   .
>> 
>> 
>>  On Mar 25, 2009, at 10:12 AM, Suha Onay wrote:
>> 
>>  >
>>  > Hi,
>>  >
>>  > I am using sqlalchemy for a while in a project.
>>  > The project has lots of models like User:
>>  >
>> 
>> --
>>  > from mcmodel import MCModel
>>  >
>>  > Base = declarative_base()
>>  >
>>  > class User(MCModel, Base):
>>  >__tablename__ = 'users'
>>  >
>>  >id = sa.Column(sa.Integer, primary_key=True)
>>  >name = sa.Column(sa.Unicode(12))
>>  >fullname = sa.Column(sa.Unicode(40))
>>  >password = sa.Column(sa.Unicode(20))
>>  >active = sa.Column(sa.Boolean())
>>  >type = sa.Column(sa.SmallInteger())
>>  >note = sa.Column(sa.Text())
>>  >date_created = sa.Column(sa.Date())
>>  >
>> 
>> --
>>  > All of these models inherit from MCModel (nothing doing special).
>>  >
>>  > I want to save all the changes done to a user in a seperate db
>> table
>>  > like "_hist_users".
>>  > The new inserts do not need to be in the hist table.
>>  > When a user is updated, the old data of the user will be copied to
>>  the
>>  > hist table with a column declaring this is an

[sqlalchemy] Re: Seperate History Tables

2009-03-30 Thread Suha Onay
İnstalled nose and tested: no error
It is OK now.

To make it easy for the developers not to care about the history tables and
versioning, is it possible not to define _history models manually and make
history_meta to generate them automatically?

Suha

On Fri, Mar 27, 2009 at 20:09, Michael Bayer wrote:

>
>
> install nose and type "nosetests".
>
>
> Suha Onay wrote:
> >
> > The version is ok: 0.5.3
> > The problem is I don't know how to do the unit tests: no tests package.
> > from tests import eq_, Comparable
> >
> > How can i do the unit tests?
> >
> > Suha
> >
> >
> >
> >
> > On Thu, Mar 26, 2009 at 19:04, Michael Bayer 
> > wrote:
> >>
> >> not sure.  make sure you're on 0.5.3.   do the unit tests included
> >> with
> >> the recipe pass ?
> >>
> >>
> >> Suha Onay wrote:
> >>> Thanks for the recipe.I faced with an error.
> >>>
> >>> The model is now:
> >>>
> --
> >>> from history_meta import VersionedMeta
> >>>
> >>> Base = declarative_base(metaclass=VersionedMeta)
> >>>
> >>> class User(Base):
> >>> __tablename__ = 'users'
> >>>
> >>> id = sa.Column(sa.Integer, primary_key=True)
> >>> name = sa.Column(sa.Unicode(12))
> >>> fullname = sa.Column(sa.Unicode(40))
> >>> password = sa.Column(sa.Unicode(20))
> >>> active = sa.Column(sa.Boolean())
> >>> type = sa.Column(sa.SmallInteger())
> >>> note = sa.Column(sa.Text())
> >>> date_created = sa.Column(sa.Date())
> >>>
> --
> >>> Session = sessionmaker(bind=engine, autocommit=False, autoflush=True,
> >>> expire_on_commit=False, extension=VersionedListener())
> >>>
> --
> >>>
> >>> When inserting a new user, the error occurs:
> >>> sqlite3:  -=> ('(IntegrityError)
> >>> users.version may not be NULL',)
> >>> postgre:  -=> ('(IntegrityError)
> >>> null
> >>> value in column "version" violates not-null constraint\n',)
> >>>
> >>> The code in history_meta creates the column version with default value
> >>> 1:
> >>> cls.version = Column('version', Integer, default=1, nullable=False)
> >>>
> >>> What is the reason?
> >>> Thanks.
> >>>
> >>> Suha
> >>>
> >>>
> >>>
> >>> On Wed, Mar 25, 2009 at 17:17, Michael Bayer
> >>> wrote:
> >>>
> 
>  I've placed a recipe for this on the wiki at
>  http://www.sqlalchemy.org/trac/wiki/UsageRecipes/LogVersions
>   .
> 
> 
>  On Mar 25, 2009, at 10:12 AM, Suha Onay wrote:
> 
>  >
>  > Hi,
>  >
>  > I am using sqlalchemy for a while in a project.
>  > The project has lots of models like User:
>  >
> 
> --
>  > from mcmodel import MCModel
>  >
>  > Base = declarative_base()
>  >
>  > class User(MCModel, Base):
>  >__tablename__ = 'users'
>  >
>  >id = sa.Column(sa.Integer, primary_key=True)
>  >name = sa.Column(sa.Unicode(12))
>  >fullname = sa.Column(sa.Unicode(40))
>  >password = sa.Column(sa.Unicode(20))
>  >active = sa.Column(sa.Boolean())
>  >type = sa.Column(sa.SmallInteger())
>  >note = sa.Column(sa.Text())
>  >date_created = sa.Column(sa.Date())
>  >
> 
> --
>  > All of these models inherit from MCModel (nothing doing special).
>  >
>  > I want to save all the changes done to a user in a seperate db table
>  > like "_hist_users".
>  > The new inserts do not need to be in the hist table.
>  > When a user is updated, the old data of the user will be copied to
>  the
>  > hist table with a column declaring this is an update operation.
>  > When a user is deleted, the old data of the user will be moved to
>  the
>  > hist table with a column declaring this is a delete operation.
>  > With these operations, it is possible to know who modified what and
>  > when.
>  >
>  > How can i achieve in this?
>  > By modifying the MCModel to enable all the models aware of history
>  > backup?
>  > Or using class
>  sqlalchemy.orm.interfaces.MapperExtension.after_update
>  > methods? (i do not know how)
>  > Or anything else?
>  >
>  > Thanks in advance.
>  >
>  > Suha
>  >
>  >
>  >
>  >
>  >
>  >
>  > >
> 
> 
>  >
> 
> >>>
> >>> >
> >>>
> >>
> >>
> >> >
> >>
> >
> > >
> >
>
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups

[sqlalchemy] Re: Seperate History Tables

2009-03-27 Thread Michael Bayer


install nose and type "nosetests".


Suha Onay wrote:
>
> The version is ok: 0.5.3
> The problem is I don't know how to do the unit tests: no tests package.
> from tests import eq_, Comparable
>
> How can i do the unit tests?
>
> Suha
>
>
>
>
> On Thu, Mar 26, 2009 at 19:04, Michael Bayer 
> wrote:
>>
>> not sure.  make sure you're on 0.5.3.   do the unit tests included
>> with
>> the recipe pass ?
>>
>>
>> Suha Onay wrote:
>>> Thanks for the recipe.I faced with an error.
>>>
>>> The model is now:
>>> --
>>> from history_meta import VersionedMeta
>>>
>>> Base = declarative_base(metaclass=VersionedMeta)
>>>
>>> class User(Base):
>>>     __tablename__ = 'users'
>>>
>>>     id = sa.Column(sa.Integer, primary_key=True)
>>>     name = sa.Column(sa.Unicode(12))
>>>     fullname = sa.Column(sa.Unicode(40))
>>>     password = sa.Column(sa.Unicode(20))
>>>     active = sa.Column(sa.Boolean())
>>>     type = sa.Column(sa.SmallInteger())
>>>     note = sa.Column(sa.Text())
>>>     date_created = sa.Column(sa.Date())
>>> --
>>> Session = sessionmaker(bind=engine, autocommit=False, autoflush=True,
>>> expire_on_commit=False, extension=VersionedListener())
>>> --
>>>
>>> When inserting a new user, the error occurs:
>>> sqlite3:  -=> ('(IntegrityError)
>>> users.version may not be NULL',)
>>> postgre:  -=> ('(IntegrityError)
>>> null
>>> value in column "version" violates not-null constraint\n',)
>>>
>>> The code in history_meta creates the column version with default value
>>> 1:
>>> cls.version = Column('version', Integer, default=1, nullable=False)
>>>
>>> What is the reason?
>>> Thanks.
>>>
>>> Suha
>>>
>>>
>>>
>>> On Wed, Mar 25, 2009 at 17:17, Michael Bayer
>>> wrote:
>>>

 I've placed a recipe for this on the wiki at
 http://www.sqlalchemy.org/trac/wiki/UsageRecipes/LogVersions
  .


 On Mar 25, 2009, at 10:12 AM, Suha Onay wrote:

 >
 > Hi,
 >
 > I am using sqlalchemy for a while in a project.
 > The project has lots of models like User:
 >
 --
 > from mcmodel import MCModel
 >
 > Base = declarative_base()
 >
 > class User(MCModel, Base):
 >    __tablename__ = 'users'
 >
 >    id = sa.Column(sa.Integer, primary_key=True)
 >    name = sa.Column(sa.Unicode(12))
 >    fullname = sa.Column(sa.Unicode(40))
 >    password = sa.Column(sa.Unicode(20))
 >    active = sa.Column(sa.Boolean())
 >    type = sa.Column(sa.SmallInteger())
 >    note = sa.Column(sa.Text())
 >    date_created = sa.Column(sa.Date())
 >
 --
 > All of these models inherit from MCModel (nothing doing special).
 >
 > I want to save all the changes done to a user in a seperate db table
 > like "_hist_users".
 > The new inserts do not need to be in the hist table.
 > When a user is updated, the old data of the user will be copied to
 the
 > hist table with a column declaring this is an update operation.
 > When a user is deleted, the old data of the user will be moved to
 the
 > hist table with a column declaring this is a delete operation.
 > With these operations, it is possible to know who modified what and
 > when.
 >
 > How can i achieve in this?
 > By modifying the MCModel to enable all the models aware of history
 > backup?
 > Or using class
 sqlalchemy.orm.interfaces.MapperExtension.after_update
 > methods? (i do not know how)
 > Or anything else?
 >
 > Thanks in advance.
 >
 > Suha
 >
 >
 >
 >
 >
 >
 > >


 >

>>>
>>> >
>>>
>>
>>
>> >
>>
>
> >
>


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Seperate History Tables

2009-03-27 Thread Suha Onay

The version is ok: 0.5.3
The problem is I don't know how to do the unit tests: no tests package.
from tests import eq_, Comparable

How can i do the unit tests?

Suha




On Thu, Mar 26, 2009 at 19:04, Michael Bayer  wrote:
>
> not sure.  make sure you're on 0.5.3.   do the unit tests included with
> the recipe pass ?
>
>
> Suha Onay wrote:
>> Thanks for the recipe.I faced with an error.
>>
>> The model is now:
>> --
>> from history_meta import VersionedMeta
>>
>> Base = declarative_base(metaclass=VersionedMeta)
>>
>> class User(Base):
>>     __tablename__ = 'users'
>>
>>     id = sa.Column(sa.Integer, primary_key=True)
>>     name = sa.Column(sa.Unicode(12))
>>     fullname = sa.Column(sa.Unicode(40))
>>     password = sa.Column(sa.Unicode(20))
>>     active = sa.Column(sa.Boolean())
>>     type = sa.Column(sa.SmallInteger())
>>     note = sa.Column(sa.Text())
>>     date_created = sa.Column(sa.Date())
>> --
>> Session = sessionmaker(bind=engine, autocommit=False, autoflush=True,
>> expire_on_commit=False, extension=VersionedListener())
>> --
>>
>> When inserting a new user, the error occurs:
>> sqlite3:  -=> ('(IntegrityError)
>> users.version may not be NULL',)
>> postgre:  -=> ('(IntegrityError)
>> null
>> value in column "version" violates not-null constraint\n',)
>>
>> The code in history_meta creates the column version with default value 1:
>> cls.version = Column('version', Integer, default=1, nullable=False)
>>
>> What is the reason?
>> Thanks.
>>
>> Suha
>>
>>
>>
>> On Wed, Mar 25, 2009 at 17:17, Michael Bayer
>> wrote:
>>
>>>
>>> I've placed a recipe for this on the wiki at
>>> http://www.sqlalchemy.org/trac/wiki/UsageRecipes/LogVersions
>>>  .
>>>
>>>
>>> On Mar 25, 2009, at 10:12 AM, Suha Onay wrote:
>>>
>>> >
>>> > Hi,
>>> >
>>> > I am using sqlalchemy for a while in a project.
>>> > The project has lots of models like User:
>>> >
>>> --
>>> > from mcmodel import MCModel
>>> >
>>> > Base = declarative_base()
>>> >
>>> > class User(MCModel, Base):
>>> >    __tablename__ = 'users'
>>> >
>>> >    id = sa.Column(sa.Integer, primary_key=True)
>>> >    name = sa.Column(sa.Unicode(12))
>>> >    fullname = sa.Column(sa.Unicode(40))
>>> >    password = sa.Column(sa.Unicode(20))
>>> >    active = sa.Column(sa.Boolean())
>>> >    type = sa.Column(sa.SmallInteger())
>>> >    note = sa.Column(sa.Text())
>>> >    date_created = sa.Column(sa.Date())
>>> >
>>> --
>>> > All of these models inherit from MCModel (nothing doing special).
>>> >
>>> > I want to save all the changes done to a user in a seperate db table
>>> > like "_hist_users".
>>> > The new inserts do not need to be in the hist table.
>>> > When a user is updated, the old data of the user will be copied to the
>>> > hist table with a column declaring this is an update operation.
>>> > When a user is deleted, the old data of the user will be moved to the
>>> > hist table with a column declaring this is a delete operation.
>>> > With these operations, it is possible to know who modified what and
>>> > when.
>>> >
>>> > How can i achieve in this?
>>> > By modifying the MCModel to enable all the models aware of history
>>> > backup?
>>> > Or using class sqlalchemy.orm.interfaces.MapperExtension.after_update
>>> > methods? (i do not know how)
>>> > Or anything else?
>>> >
>>> > Thanks in advance.
>>> >
>>> > Suha
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> > >
>>>
>>>
>>> >
>>>
>>
>> >
>>
>
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Seperate History Tables

2009-03-26 Thread Michael Bayer

not sure.  make sure you're on 0.5.3.   do the unit tests included with
the recipe pass ?


Suha Onay wrote:
> Thanks for the recipe.I faced with an error.
>
> The model is now:
> --
> from history_meta import VersionedMeta
>
> Base = declarative_base(metaclass=VersionedMeta)
>
> class User(Base):
> __tablename__ = 'users'
>
> id = sa.Column(sa.Integer, primary_key=True)
> name = sa.Column(sa.Unicode(12))
> fullname = sa.Column(sa.Unicode(40))
> password = sa.Column(sa.Unicode(20))
> active = sa.Column(sa.Boolean())
> type = sa.Column(sa.SmallInteger())
> note = sa.Column(sa.Text())
> date_created = sa.Column(sa.Date())
> --
> Session = sessionmaker(bind=engine, autocommit=False, autoflush=True,
> expire_on_commit=False, extension=VersionedListener())
> --
>
> When inserting a new user, the error occurs:
> sqlite3:  -=> ('(IntegrityError)
> users.version may not be NULL',)
> postgre:  -=> ('(IntegrityError)
> null
> value in column "version" violates not-null constraint\n',)
>
> The code in history_meta creates the column version with default value 1:
> cls.version = Column('version', Integer, default=1, nullable=False)
>
> What is the reason?
> Thanks.
>
> Suha
>
>
>
> On Wed, Mar 25, 2009 at 17:17, Michael Bayer
> wrote:
>
>>
>> I've placed a recipe for this on the wiki at
>> http://www.sqlalchemy.org/trac/wiki/UsageRecipes/LogVersions
>>  .
>>
>>
>> On Mar 25, 2009, at 10:12 AM, Suha Onay wrote:
>>
>> >
>> > Hi,
>> >
>> > I am using sqlalchemy for a while in a project.
>> > The project has lots of models like User:
>> >
>> --
>> > from mcmodel import MCModel
>> >
>> > Base = declarative_base()
>> >
>> > class User(MCModel, Base):
>> >__tablename__ = 'users'
>> >
>> >id = sa.Column(sa.Integer, primary_key=True)
>> >name = sa.Column(sa.Unicode(12))
>> >fullname = sa.Column(sa.Unicode(40))
>> >password = sa.Column(sa.Unicode(20))
>> >active = sa.Column(sa.Boolean())
>> >type = sa.Column(sa.SmallInteger())
>> >note = sa.Column(sa.Text())
>> >date_created = sa.Column(sa.Date())
>> >
>> --
>> > All of these models inherit from MCModel (nothing doing special).
>> >
>> > I want to save all the changes done to a user in a seperate db table
>> > like "_hist_users".
>> > The new inserts do not need to be in the hist table.
>> > When a user is updated, the old data of the user will be copied to the
>> > hist table with a column declaring this is an update operation.
>> > When a user is deleted, the old data of the user will be moved to the
>> > hist table with a column declaring this is a delete operation.
>> > With these operations, it is possible to know who modified what and
>> > when.
>> >
>> > How can i achieve in this?
>> > By modifying the MCModel to enable all the models aware of history
>> > backup?
>> > Or using class sqlalchemy.orm.interfaces.MapperExtension.after_update
>> > methods? (i do not know how)
>> > Or anything else?
>> >
>> > Thanks in advance.
>> >
>> > Suha
>> >
>> >
>> >
>> >
>> >
>> >
>> > >
>>
>>
>> >
>>
>
> >
>


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Seperate History Tables

2009-03-26 Thread Suha Onay
Thanks for the recipe.I faced with an error.

The model is now:
--
from history_meta import VersionedMeta

Base = declarative_base(metaclass=VersionedMeta)

class User(Base):
__tablename__ = 'users'

id = sa.Column(sa.Integer, primary_key=True)
name = sa.Column(sa.Unicode(12))
fullname = sa.Column(sa.Unicode(40))
password = sa.Column(sa.Unicode(20))
active = sa.Column(sa.Boolean())
type = sa.Column(sa.SmallInteger())
note = sa.Column(sa.Text())
date_created = sa.Column(sa.Date())
--
Session = sessionmaker(bind=engine, autocommit=False, autoflush=True,
expire_on_commit=False, extension=VersionedListener())
--

When inserting a new user, the error occurs:
sqlite3:  -=> ('(IntegrityError)
users.version may not be NULL',)
postgre:  -=> ('(IntegrityError) null
value in column "version" violates not-null constraint\n',)

The code in history_meta creates the column version with default value 1:
cls.version = Column('version', Integer, default=1, nullable=False)

What is the reason?
Thanks.

Suha



On Wed, Mar 25, 2009 at 17:17, Michael Bayer wrote:

>
> I've placed a recipe for this on the wiki at
> http://www.sqlalchemy.org/trac/wiki/UsageRecipes/LogVersions
>  .
>
>
> On Mar 25, 2009, at 10:12 AM, Suha Onay wrote:
>
> >
> > Hi,
> >
> > I am using sqlalchemy for a while in a project.
> > The project has lots of models like User:
> >
> --
> > from mcmodel import MCModel
> >
> > Base = declarative_base()
> >
> > class User(MCModel, Base):
> >__tablename__ = 'users'
> >
> >id = sa.Column(sa.Integer, primary_key=True)
> >name = sa.Column(sa.Unicode(12))
> >fullname = sa.Column(sa.Unicode(40))
> >password = sa.Column(sa.Unicode(20))
> >active = sa.Column(sa.Boolean())
> >type = sa.Column(sa.SmallInteger())
> >note = sa.Column(sa.Text())
> >date_created = sa.Column(sa.Date())
> >
> --
> > All of these models inherit from MCModel (nothing doing special).
> >
> > I want to save all the changes done to a user in a seperate db table
> > like "_hist_users".
> > The new inserts do not need to be in the hist table.
> > When a user is updated, the old data of the user will be copied to the
> > hist table with a column declaring this is an update operation.
> > When a user is deleted, the old data of the user will be moved to the
> > hist table with a column declaring this is a delete operation.
> > With these operations, it is possible to know who modified what and
> > when.
> >
> > How can i achieve in this?
> > By modifying the MCModel to enable all the models aware of history
> > backup?
> > Or using class sqlalchemy.orm.interfaces.MapperExtension.after_update
> > methods? (i do not know how)
> > Or anything else?
> >
> > Thanks in advance.
> >
> > Suha
> >
> >
> >
> >
> >
> >
> > >
>
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Seperate History Tables

2009-03-25 Thread Michael Bayer

I've placed a recipe for this on the wiki at 
http://www.sqlalchemy.org/trac/wiki/UsageRecipes/LogVersions 
  .


On Mar 25, 2009, at 10:12 AM, Suha Onay wrote:

>
> Hi,
>
> I am using sqlalchemy for a while in a project.
> The project has lots of models like User:
> --
> from mcmodel import MCModel
>
> Base = declarative_base()
>
> class User(MCModel, Base):
>__tablename__ = 'users'
>
>id = sa.Column(sa.Integer, primary_key=True)
>name = sa.Column(sa.Unicode(12))
>fullname = sa.Column(sa.Unicode(40))
>password = sa.Column(sa.Unicode(20))
>active = sa.Column(sa.Boolean())
>type = sa.Column(sa.SmallInteger())
>note = sa.Column(sa.Text())
>date_created = sa.Column(sa.Date())
> --
> All of these models inherit from MCModel (nothing doing special).
>
> I want to save all the changes done to a user in a seperate db table
> like "_hist_users".
> The new inserts do not need to be in the hist table.
> When a user is updated, the old data of the user will be copied to the
> hist table with a column declaring this is an update operation.
> When a user is deleted, the old data of the user will be moved to the
> hist table with a column declaring this is a delete operation.
> With these operations, it is possible to know who modified what and
> when.
>
> How can i achieve in this?
> By modifying the MCModel to enable all the models aware of history
> backup?
> Or using class sqlalchemy.orm.interfaces.MapperExtension.after_update
> methods? (i do not know how)
> Or anything else?
>
> Thanks in advance.
>
> Suha
>
>
>
>
>
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---