whiskeylover / idreamoftoast

idreamoftoast
Apache License 2.0
1 stars 0 forks source link

Remove/alter quoted entries from dream table #16

Closed danriti closed 11 years ago

danriti commented 11 years ago

Based on our previous conversation:

mysql> select id, name from dream;
+----+--------------------------+
| id | name                     |
+----+--------------------------+
|  1 | pizza                    |
|  2 | being%20a%20nerd         |
|  3 | falafel                  |
|  4 | dreams                   |
|  5 | toast                    |
|  6 | asdf                     |
|  7 | banana                   |
|  8 | foo                      |
|  9 | yo%20mama                |
| 10 | bananas                  |
| 11 | muffins                  |
| 12 | poopies                  |
| 13 | coffee                   |
| 14 | facebook                 |
| 15 | myspace                  |
| 16 | f                        |
| 17 | food                     |
| 18 | boobs                    |
| 19 | bewbs                    |
| 20 | waffles                  |
| 21 | money                    |
| 22 | stuff                    |
| 23 | pie                      |
| 24 | smacking%20your%20system |
| 25 | computers                |
| 26 | sex                      |
| 27 | butts                    |
| 28 | bongs                    |
| 29 | meat                     |
| 30 | a b c                    |
| 35 | smacking your system     |
| 36 | x y z                    |
+----+--------------------------+
32 rows in set (0.00 sec)

Also note that rows 24 and 35 will be duplicates!

whiskeylover commented 11 years ago

We should also put a unique constraint on the [code]name[/code] column

danriti commented 11 years ago

http://peewee.readthedocs.org/en/latest/peewee/api.html#fields-api

Looks like it's as easy to setup on the name field, however it might only do this upon table creation:

unique (bool) – whether to create a unique index for this column when creating the table

whiskeylover commented 11 years ago

We can change the model on the peewee side so the name field is unique. And manually alter the table on the DB side.

danriti commented 11 years ago

Perfect...sounds great!

danriti commented 11 years ago

So just a heads up, did some poking around to see if peewee supported migrations, and unfortunately it looks like the answer is no:

http://peewee.readthedocs.org/en/latest/peewee/cookbook.html#schema-migrations

However, there are plenty of methods available to the Database class that would let us write stand alone Python scripts that can act as migrations, such as:

http://peewee.readthedocs.org/en/latest/peewee/api.html#Database.create_index

It's a bit overkill for this issue, however it might be a cool idea/side project to work on in the future?

whiskeylover commented 11 years ago

Table update. Use this query in the future in case dups end up in the table.

update dream set name = replace(name, '%20', ' ');

Also, table altered -- unique key created on the dream table

alter table dream add unique key (name);