<div dir="ltr"><div><font face="arial, helvetica, sans-serif">Pony ORM 0.4.9 is released!</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">In this release we added new functionality which was requested by Pony users. The main features include the possibility to delete tables in the database and recreate tables with all necessary foreign key constraints and indexes. Let’s see how it works in detail.</font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Drop tables</font></div><div><font face="arial, helvetica, sans-serif">----------------</font></div><div><font face="arial, helvetica, sans-serif"><br>
</font></div><div><font face="arial, helvetica, sans-serif">There are 4 methods for removing tables in the database, which you can use now:</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div>
<font face="arial, helvetica, sans-serif">db.drop_all_tables(with_all_data=False)</font></div><div><font face="arial, helvetica, sans-serif">Where db is an instance of the Database class.</font></div><div><font face="arial, helvetica, sans-serif"><br>
</font></div><div><font face="arial, helvetica, sans-serif">This method drops all tables, which are related to the current mapping. When this method is called without parameters, Pony will remove tables only if none of them contain any data. In case at least one of them is not empty the method will raise the TableIsNotEmpty exception without dropping any table. In order to drop tables with the data you should pass the parameter with_all_data=True: drop_all_tables(with_all_data=True).</font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">If you specify with_all_data=True, then Pony will remove all tables which are mapped to declared entities even if they have data. This parameter has the same meaning for all methods below.</font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">db.drop_table(table_name, if_exists=False, with_all_data=False)</font></div><div><font face="arial, helvetica, sans-serif">Where db is an instance of the Database class.</font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">This method drops a table. If such table doesn’t exist the method raises the exception TableDoesNotExist. Note, that table_name is case sensitive. If the parameter if_exists is set to True, then it will not raise the TableDoesNotExist exception if there is no such table in the database.</font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">MyEntity.drop_table(with_all_data=False)</font></div><div><font face="arial, helvetica, sans-serif">Where MyEntity is a declared entity class.</font></div>
<div><font face="arial, helvetica, sans-serif">This method removes a table which is mapped to the entity.</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">MyEntity.my_collection.drop_table(with_all_data=False)</font></div>
<div><font face="arial, helvetica, sans-serif">Where MyEntity is a declared entity class and my_collection is a Set attribute:</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">    class MyEntity(db.Entity):</font></div>
<div><font face="arial, helvetica, sans-serif">        ...</font></div><div><font face="arial, helvetica, sans-serif">        my_collection = Set(…)</font></div><div><font face="arial, helvetica, sans-serif">        ...</font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">This method drops a table, which is associated with the Set attribute. The primary role of this method is to drop an intermediate table, which is used for establishing many-to-many relationship between two Set attributes. But if you call this method for many-to-one relationship, it will try to remove the table used for the entity at the other side of the many-to-one relationship.</font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Create tables</font></div><div><font face="arial, helvetica, sans-serif">--------------------</font></div><div>
<font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Pony now has a separate method for creating tables and corresponding foreign keys and indexes:</font></div><div><font face="arial, helvetica, sans-serif"><br>
</font></div><div><font face="arial, helvetica, sans-serif">db.create_tables()</font></div><div><font face="arial, helvetica, sans-serif">Where db is an instance of the Database class.</font></div><div><font face="arial, helvetica, sans-serif">This method checks the existing mapping and creates tables for entities if they don’t exist. Also, Pony will check if foreign keys and indexes exist and create them if they are missing.</font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">In previous releases the method generate_mapping() always checked if the tables in the database match with the entities. Now you can switch this check off. This can be useful if you want just generate mapping and create tables later.</font></div>
<div><font face="arial, helvetica, sans-serif">This gives you the following options for mapping generation:</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">- db.generate_mapping(create_tables=True) – create tables, foreign key references and indexes if they don’t exist</font></div>
<div><font face="arial, helvetica, sans-serif">- db.generate_mapping() – assuming that tables are already exist, check if the existing tables match with the enitites</font></div><div><font face="arial, helvetica, sans-serif">- db.generate_mapping(check_tables=False) – neither create nor check tables, useful if you plan to call db.create_tables() later.</font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Other new features</font></div><div><font face="arial, helvetica, sans-serif">----------------------------</font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Starting with the release 0.4.9, Pony automatically enables foreign key support in SQLite. By default SQLite doesn’t check foreign key constraints, and in previous Pony releases foreign key constraints in SQLite were not enforced.</font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">db.disconnect()</font></div><div><font face="arial, helvetica, sans-serif">Where db is an instance of the Database class.</font></div>
<div><font face="arial, helvetica, sans-serif">Close the database connection for the current thread if it was opened.</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Comparison methods for the Entity class were added. Now entity instances can be sorted by its primary key values.</font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Entity.exists(…) method was added. You can check the entity attributes for equality:</font></div><div><font face="arial, helvetica, sans-serif">    User.exists(username="Jon")</font></div>
<div><font face="arial, helvetica, sans-serif">or use a lambda condition:</font></div><div><font face="arial, helvetica, sans-serif">    Order.exists(lambda o: o.total_price > 500 and count(o.items) <=3)<br></font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Reported bugs were fixed, new tests were added.</font></div><div><font face="arial, helvetica, sans-serif"><br>
</font></div><div><font face="arial, helvetica, sans-serif">Thanks to all Pony users for sending us their feedback and telling us how they are using Pony. We appreciate it!</font></div></div>