44from  django .db  import  migrations , models 
55from  oauth2_provider .settings  import  oauth2_settings 
66
7+ def  forwards_func (apps , schema_editor ):
8+     """ 
9+     Forward migration touches every "old" accesstoken.token which will cause the checksum to be computed. 
10+     """ 
11+     AccessToken  =  apps .get_model (oauth2_settings .ACCESS_TOKEN_MODEL )
12+     accesstokens  =  AccessToken ._default_manager .all ()
13+     for  accesstoken  in  accesstokens :
14+         accesstoken .save (update_fields = ['token_checksum' ])
15+ 
16+ 
717class  Migration (migrations .Migration ):
818    dependencies  =  [
919        ("oauth2_provider" , "0011_refreshtoken_token_family" ),
@@ -14,13 +24,17 @@ class Migration(migrations.Migration):
1424        migrations .AddField (
1525            model_name = "accesstoken" ,
1626            name = "token_checksum" ,
17-             field = oauth2_provider .models .TokenChecksumField (
18-                 blank = True , db_index = True , max_length = 64 , unique = True 
19-             ),
27+             field = oauth2_provider .models .TokenChecksumField (blank = True , null = True , max_length = 64 ),
2028        ),
2129        migrations .AlterField (
2230            model_name = "accesstoken" ,
2331            name = "token" ,
2432            field = models .TextField (),
2533        ),
34+         migrations .RunPython (forwards_func , migrations .RunPython .noop ),
35+         migrations .AlterField (
36+             model_name = 'accesstoken' ,
37+             name = 'token_checksum' ,
38+             field = oauth2_provider .models .TokenChecksumField (blank = False , max_length = 64 ,  db_index = True , unique = True ),
39+         ),
2640    ]
0 commit comments