[sqlalchemy] Re: Database with audit trail table

2009-08-22 Thread Adrian von Bidder
On Saturday 22 August 2009 01.08:05 David Bolen wrote:
 Adrian von Bidder avbid...@fortytwo.ch writes:
  Ideas  comments?

 For what it's worth, I'd think that the best sort of audit would be
 something done in the database itself, since it would audit any
 changes whether done through any interface.

Yes and no...

I see your point (and since I know pg better than sqla/python I'd probably 
even be quicker doing it in SQL), but the application has more knowledge 
about what's going on.

My audit table should not just version the db content, but I plan to 
record additional stuff that comes from the application (like: who 
authorized the change? etc.) which is not readily available at the db level.

(And then there's the fact that I'm writing this toy project to learn about 
sqlalchemy, so going ahead and writing an SQL audit trail framework misses 
this goal completely :-)

cheers
-- vbi
(Off to play around with SeesionExtension some more ...)


-- 
featured link: http://www.pool.ntp.org


signature.asc
Description: This is a digitally signed message part.


[sqlalchemy] Re: Multiple Mappers for the same class in different databases [solved]

2009-08-22 Thread Johannes Knopp

Hello Michael,
thank you for that answer, it was exactly what I was looking for!
Regards,
Johannes

--~--~-~--~~~---~--~~
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: index in SA

2009-08-22 Thread Michael Bayer

Index() is not a Table argument.As in DDL where CREATE INDEX is  
its own declaration outside of CREATE TABLE, Index() is setup  
independently:

class MyClass(Base):
 ... columns


Index(my_index, MyClass.__table__.c.foo)

or

Index(my_index, MyClass.foo)





On Aug 21, 2009, at 5:25 AM, rajasekhar911 wrote:


 i tried

 class MyClass:
   __tablename__ = 'my_table'

id = Column(Integer, primary_key=True)
name = Column(String, nullable=False)
type = Column(String, nullable=False)
__table_args__ = (
Index('ix_name_type', name , type ,unique=True)
)

 it errors out

 __table_args__ = (
  File /usr/lib/python2.4/site-packages/SQLAlchemy-0.5.5-py2.4.egg/
 sqlalchemy/schema.py, line 1461, in __init__
self._init_items(*columns)
  File /usr/lib/python2.4/site-packages/SQLAlchemy-0.5.5-py2.4.egg/
 sqlalchemy/schema.py, line 1465, in _init_items
self.append_column(_to_schema_column(column))
  File /usr/lib/python2.4/site-packages/SQLAlchemy-0.5.5-py2.4.egg/
 sqlalchemy/schema.py, line 1476, in append_column
self._set_parent(column.table)
  File /usr/lib/python2.4/site-packages/SQLAlchemy-0.5.5-py2.4.egg/
 sqlalchemy/schema.py, line 1469, in _set_parent
self.metadata = table.metadata
 AttributeError: 'NoneType' object has no attribute 'metadata'

 thanks

 On Aug 21, 2:22 pm, rajasekhar911 rajasekhar...@gmail.com wrote:
 hi thanks for the reply..
 but one doubt
 how will i access the MyClass inside MyClass

 i tried
 ndex('ix_name_type',
 MyClass.__table__.c.name,MyClass.__table__.c.type, unique=True)
 it is giving the error
 NameError: name 'MyClass' is not defined

 thanks

 On Aug 21, 2:04 pm, King Simon-NFHD78 simon.k...@motorola.com
 wrote:

 -Original Message-
 From: sqlalchemy@googlegroups.com
 [mailto:sqlalch...@googlegroups.com] On Behalf Of rajasekhar911
 Sent: 21 August 2009 07:30
 To: sqlalchemy
 Subject: [sqlalchemy] Re: index in SA

 i want to add a composite index to the class inherited from
 declarative_base

 I tried this,

 class MyClass:
__tablename__ = 'my_table'

 id = Column(Integer, primary_key=True)
 name = Column(String, nullable=False)
 type = Column(String, nullable=False)
 __table_args__ = (
 Index('ix_name_type','name','type',unique=True)
 )

 gave me an error,
 File /m2svn/trunk/src/model/MyClass.py, line 32, in MyClass
 __table_args__ = (
   File /usr/lib/python2.4/site-packages/SQLAlchemy-0.5.5- 
 py2.4.egg/
 sqlalchemy/schema.py, line 1461, in __init__
 self._init_items(*columns)
   File /usr/lib/python2.4/site-packages/SQLAlchemy-0.5.5- 
 py2.4.egg/
 sqlalchemy/schema.py, line 1465, in _init_items
 self.append_column(_to_schema_column(column))
   File /usr/lib/python2.4/site-packages/SQLAlchemy-0.5.5- 
 py2.4.egg/
 sqlalchemy/schema.py, line 2145, in _to_schema_column
 raise exc.ArgumentError(schema.Column object expected)
 sqlalchemy.exc.ArgumentError: schema.Column object expected

 I'm not sure if this is the root cause of your error, but  
 __table_args__
 must either be a dictionary or a tuple where the last element is a
 dictionary (according 
 tohttp://www.sqlalchemy.org/docs/05/reference/ext/declarative.html#table-c
 onfiguration)

 Also, I think Index may require actual column parameters rather than
 strings (according 
 tohttp://www.sqlalchemy.org/docs/05/metadata.html#indexes) 
 . You may be
 able to use something like the following after your class  
 definition:

   Index('ix_name_type', MyClass.__table__.c.name,
 MyClass.__table__.c.type, unique=True)

 or even

   Index('ix_name_type', MyClass.name, MyClass.type, unique=True)

 Hope that helps,

 Simon
 


--~--~-~--~~~---~--~~
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] thanks all while I was gone !

2009-08-22 Thread Michael Bayer

*HUGE*  thanks to Simon, Ants, Mike Conley, Philip Jenvey, and  
everyone else for fielding the mailing list questions while I was  
gone ! Its like a real mailing list now, I should take more  
vacations.



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---