Skip to content
This repository
Browse code

Adding notes on add/drop/rename sql

  • Loading branch information...
commit 4d2c37f9424d4ca4f37f9a30dc4ab786b961cd49 1 parent 35e3547
Charles Leifer authored August 21, 2012
13  docs/peewee/cookbook.rst
Source Rendered
@@ -747,3 +747,16 @@ pwiz will generate code for:
747 747
 * models that were introspected from the database tables
748 748
 
749 749
 The generated code is written to stdout.
  750
+
  751
+
  752
+Schema migrations
  753
+-----------------
  754
+
  755
+Currently peewee does not have support for automatic schema migrations. Peewee
  756
+does, however, come with a few helper functions:
  757
+
  758
+* :py:meth:`Database.add_column_sql`
  759
+* :py:meth:`Database.rename_column_sql`
  760
+* :py:meth:`Database.drop_column_sql`
  761
+
  762
+Honestly, your best bet is to script any migrations and use plain ol' SQL.
35  docs/peewee/database.rst
Source Rendered
@@ -316,10 +316,10 @@ Database and its subclasses
316 316
         :param model_class: :py:class:`Model` class to create table for
317 317
         :param safe: if ``True``, query will add a ``IF NOT EXISTS`` clause
318 318
 
319  
-    .. py:method:: create_index(model_class, field_name[, unique=False])
  319
+    .. py:method:: create_index(model_class, field_names[, unique=False])
320 320
 
321 321
         :param model_class: :py:class:`Model` table on which to create index
322  
-        :param field_name: name of field to create index on
  322
+        :param field_name: name of field(s) to create index on (a string or list)
323 323
         :param unique: whether the index should enforce uniqueness
324 324
 
325 325
     .. py:method:: create_foreign_key(model_class, field)
@@ -337,6 +337,37 @@ Database and its subclasses
337 337
             exists that prevents a table being dropped, you will need to handle
338 338
             that in application logic.
339 339
 
  340
+    .. py:method:: add_column_sql(model_class, field_name)
  341
+
  342
+        :param model_class: :py:class:`Model` which we are adding a column to
  343
+        :param string field_name: the name of the field we are adding
  344
+
  345
+        :rtype: SQL suitable for adding the column
  346
+
  347
+        .. note::
  348
+            Adding a non-null column to a table with rows may cause an IntegrityError.
  349
+
  350
+    .. py:method:: rename_column_sql(model_class, field_name, new_name)
  351
+
  352
+        :param model_class: :py:class:`Model` instance
  353
+        :param string field_name: the current name of the field
  354
+        :param string new_name: new name for the field
  355
+
  356
+        :rtype: SQL suitable for renaming the column
  357
+
  358
+        .. note::
  359
+            There must be a field instance named ``field_name`` at the time this SQL
  360
+            is generated.
  361
+
  362
+        .. note:: SQLite does not support renaming columns
  363
+
  364
+    .. py:method:: drop_column_sql(model_class, field_name)
  365
+
  366
+        :param model_class: :py:class:`Model` instance
  367
+        :param string field_name: the name of the field to drop
  368
+
  369
+        .. note:: SQLite does not support dropping columns
  370
+
340 371
     .. py:method:: create_sequence(sequence_name)
341 372
 
342 373
         :param sequence_name: name of sequence to create

0 notes on commit 4d2c37f

Please sign in to comment.
Something went wrong with that request. Please try again.