4
4
from django .db import migrations , models
5
5
from oauth2_provider .settings import oauth2_settings
6
6
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
+
7
17
class Migration (migrations .Migration ):
8
18
dependencies = [
9
19
("oauth2_provider" , "0011_refreshtoken_token_family" ),
@@ -14,13 +24,17 @@ class Migration(migrations.Migration):
14
24
migrations .AddField (
15
25
model_name = "accesstoken" ,
16
26
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 ),
20
28
),
21
29
migrations .AlterField (
22
30
model_name = "accesstoken" ,
23
31
name = "token" ,
24
32
field = models .TextField (),
25
33
),
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
+ ),
26
40
]
0 commit comments