Added extraction of MP3 info when saving Book models.
[wolnelektury.git] / apps / south / db / mysql.py
1
2 from django.db import connection
3 from south.db import generic
4
5 class DatabaseOperations(generic.DatabaseOperations):
6
7     """
8     MySQL implementation of database operations.
9     """
10     
11     alter_string_set_type = ''
12     alter_string_set_null = 'MODIFY %(column)s %(type)s NULL;'
13     alter_string_drop_null = 'MODIFY %(column)s %(type)s NOT NULL;'
14
15     def rename_column(self, table_name, old, new):
16         if old == new:
17             return []
18         
19         qn = connection.ops.quote_name
20         
21         rows = [x for x in self.execute('DESCRIBE %s' % (qn(table_name),)) if x[0] == old]
22         
23         if not rows:
24             raise ValueError("No column '%s' in '%s'." % (old, table_name))
25         
26         params = (
27             qn(table_name),
28             qn(old),
29             qn(new),
30             "%s %s %s %s %s" % (
31                 rows[0][1],
32                 rows[0][2] == "YES" and "NULL" or "NOT NULL",
33                 rows[0][3] == "PRI" and "PRIMARY KEY" or "",
34                 rows[0][4] and "DEFAULT %s" % rows[0][4] or "",
35                 rows[0][5] or "",
36             ),
37         )
38         self.execute('ALTER TABLE %s CHANGE COLUMN %s %s %s;' % params)
39
40
41     def rename_table(self, old_table_name, table_name):
42         """
43         Renames the table 'old_table_name' to 'table_name'.
44         """
45         if old_table_name == table_name:
46             # No Operation
47             return
48         qn = connection.ops.quote_name
49         params = (qn(old_table_name), qn(table_name))
50         self.execute('RENAME TABLE %s TO %s;' % params)