AlterModelOnSyncDB: patchstorageengines.txt

File patchstorageengines.txt, 2.9 KB (added by prz, 16 years ago)

Alternate Patch adding _Meta option

Line 
1<p>For that I have another approach I took, I modified the settings file & added in Meta an option. To give you
2an idea here's the patch
3against Revision: 5773.
4</p>
5<pre class="wiki"># use a consistant MySQL storage type for all apps, all models
6
7Index: django/db/models/options.py
8===================================================================
9--- django/db/models/options.py (revision 5773)
10+++ django/db/models/options.py (working copy)
11@@ -15,7 +15,7 @@
12
13 DEFAULT_NAMES = ('verbose_name', 'db_table', 'ordering',
14 'unique_together', 'permissions', 'get_latest_by',
15- 'order_with_respect_to', 'app_label', 'db_tablespace')
16+ 'order_with_respect_to', 'app_label', 'db_tablespace', 'db_storage_engine')
17
18 class Options(object):
19 def __init__(self, meta):
20@@ -30,6 +30,7 @@
21 self.get_latest_by = None
22 self.order_with_respect_to = None
23 self.db_tablespace = None
24+ self.db_storage_engine = None
25 self.admin = None
26 self.meta = meta
27 self.pk = None
28Index: django/db/backends/mysql/base.py
29===================================================================
30--- django/db/backends/mysql/base.py (revision 5773)
31+++ django/db/backends/mysql/base.py (working copy)
32@@ -141,6 +141,7 @@
33 needs_upper_for_iops = False
34 supports_constraints = True
35 supports_tablespaces = False
36+supports_storage_engines = True
37 uses_case_insensitive_names = False
38
39 def quote_name(name):
40@@ -207,6 +208,9 @@
41 def get_autoinc_sql(table):
42 return None
43
44+def get_storageengine_sql(engine):
45+ return "ENGINE = %s" % engine
46+
47 def get_sql_flush(style, tables, sequences):
48 """Return a list of SQL statements required to remove all data from
49 all tables in the database (without actually removing the tables
50Index: django/core/management.py
51===================================================================
52--- django/core/management.py (revision 5773)
53+++ django/core/management.py (working copy)
54@@ -153,6 +153,7 @@
55 Returns list_of_sql, pending_references_dict
56 """
57 from django.db import backend, models
58+ from django.conf import settings
59
60 opts = model._meta
61 final_output = []
62@@ -203,6 +204,9 @@
63 full_statement.append(')')
64 if opts.db_tablespace and backend.supports_tablespaces:
65 full_statement.append(backend.get_tablespace_sql(opts.db_tablespace))
66+ if backend.supports_storage_engines:
67+ storage = opts.db_storage_engine or settings.DATABASE_STORAGE_ENGINE
68+ full_statement.append(backend.get_storageengine_sql(storage))
69 full_statement.append(';')
70 final_output.append('\n'.join(full_statement))
71
72</pre>
73
74<p>
75For brevity's sake, Only works for SQL here, other backends would need to simply set the <tt>supports_storage_engines = False</tt>.
76</p>
77<p>
78If enough interest arises, I can modify that into a proper patch against <tt>HEAD</tt>
79</p>
80<verbatim>
81 --- tony
82</verbatim>
83
Back to Top