Closed (fixed)
Project:
Login Security
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
12 Mar 2009 at 07:53 UTC
Updated:
26 Jun 2014 at 14:55 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
ilo commentedI need someone with pgsql to test this patch. Just do what stated in the subject, updates database schema, and changes db_query('INSERT to drupal_write_record.
Comment #2
ilo commentedPrevious patch didn't include the schema changes needed in the .install file for the drupal_write_record to find the schema.
Comment #3
deekayen commentedI'll be easier for most people to review this during development if it's in the snapshot, so I committed it.
Comment #4
ilo commentedThanks deekayen, I guess something went wrong because of the issue #492800: Incorrect table definition, not sure if this is fixed at all..
Comment #5
deekayen commentedI moved the index creation around in the initial commit because the API documentation says the keys should all be dropped before calling db_change_field, then re-created. That probably means the index creation probably needs a little more work since they are not re-created during change_field or after.
#492800: Incorrect table definition was caused by me moving the index creation down to the bottom of the update function. When I moved the creation down to the bottom, there was then no key for it to drop, which caused the error. The error was generated because #2 creates a key id then turns around and drops it on the next line. Why?
This is more like what I expected (untested):
Comment #6
ilo commentedNot exactly, line 3 deletes the Index of the id field, not the key.. The problem here is just trying to alter the table (drop index id) with a serial field (id) and not primary key (just dropped in line 1).
Problem was: Previous database schema is wrong..
http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/login_secur...
1) timestamp can't be primary key, two login attempts can happend at the same timestamp
2) id is indexed, timestamp is not indexed, but queries require tstamp index.
So, the tasks were:
- primary key should be remove from timestamp
- primary key should be created for ID
- index id is deleted
- index timestamp is created.
as shown in the final schema:
The howto was:
We can just change the primary key and move the index part to the end as you did, or use the parameter $new_keys in the first alter.
http://api.drupal.org/api/function/db_change_field/6:
"On MySQL, all type 'serial' fields must be part of at least one key or index as soon as they are created. You cannot use db_add_{primary_key,unique_key,index}() for this purpose because the ALTER TABLE command will fail to add the column without a key or index specification. The solution is to use the optional $new_keys argument to create the key or index at the same time as field."
Your code should work (didn't test also, I'll give a try asap) just like this, leaving the db_add_primary_key at the begining..
Note that I just kept the primary key add before the alter. I guess, since we have a serial field, we should db_add_primary_key just inmediatly before the db_drop_primary_key.
Comment #7
ilo commentedIn fact, I've tested this:
- Uninstall module
- update login_security module to date 27-Feb-2009 (previous to db changes)
- Intall module
- Update login_security module to 6-1 branch
- Apply this patch
- perform update
And the result is:
The following queries were executed
login_security module
Update #6001
* ALTER TABLE {login_security_track} DROP PRIMARY KEY
* ALTER TABLE {login_security_track} ADD PRIMARY KEY (id)
* ALTER TABLE {login_security_track} DROP INDEX name
* ALTER TABLE {login_security_track} DROP INDEX id
* ALTER TABLE {login_security_track} CHANGE name `name` VARCHAR(64) NOT NULL DEFAULT ''
* ALTER TABLE {login_security_track} CHANGE timestamp `timestamp` INT NOT NULL DEFAULT 0
* ALTER TABLE {login_security_track} ADD INDEX name (name)
* ALTER TABLE {login_security_track} ADD INDEX timestamp (timestamp)
This is the update funtion
Comment #8
deekayen commentedFYI, I've been committing to both HEAD and DRUPAL-6--1.
Comment #9
ilo commentedgood!. Thanks for your help and support in the module's queue, deekayen.
Comment #10
deekayen commentedcommitted