Coverage for modules\email\migrations\0001_initial.py: 100%

7 statements  

« prev     ^ index     » next       coverage.py v7.16.0, created at 2026-09-05 09:24 +0800

1# Generated migration for email models 

2 

3from django.db import migrations, models 

4import django.db.models.deletion 

5import uuid 

6 

7 

8class Migration(migrations.Migration): 

9 

10 initial = True 

11 

12 dependencies = [ 

13 ('authentication', '__first__'), 

14 ] 

15 

16 operations = [ 

17 migrations.CreateModel( 

18 name='EmailAccount', 

19 fields=[ 

20 ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), 

21 ('created_at', models.DateTimeField(auto_now_add=True)), 

22 ('updated_at', models.DateTimeField(auto_now=True)), 

23 ('tenant_id', models.UUIDField(db_index=True)), 

24 ('provider', models.CharField(choices=[('gmail', 'Gmail'), ('outlook', 'Outlook'), ('yahoo', 'Yahoo'), ('other', 'Other')], default='other', max_length=32)), 

25 ('connection_type', models.CharField(choices=[('imap', 'IMAP/SMTP'), ('oauth', 'OAuth2')], default='imap', max_length=16)), 

26 ('email_address', models.EmailField(max_length=254)), 

27 ('display_name', models.CharField(blank=True, max_length=128)), 

28 ('imap_host', models.CharField(blank=True, max_length=256, null=True)), 

29 ('imap_port', models.IntegerField(default=993)), 

30 ('smtp_host', models.CharField(blank=True, max_length=256, null=True)), 

31 ('smtp_port', models.IntegerField(default=587)), 

32 ('encrypted_password', models.CharField(blank=True, max_length=512, null=True)), 

33 ('oauth_token', models.JSONField(blank=True, null=True)), 

34 ('oauth_refresh_token', models.CharField(blank=True, max_length=512, null=True)), 

35 ('is_primary', models.BooleanField(default=False)), 

36 ('sync_enabled', models.BooleanField(default=True)), 

37 ('last_sync_at', models.DateTimeField(blank=True, null=True)), 

38 ('sync_interval', models.IntegerField(default=5)), 

39 ('use_ssl', models.BooleanField(default=True)), 

40 ('is_verified', models.BooleanField(default=False)), 

41 ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='email_accounts', to='authentication.user')), 

42 ], 

43 options={ 

44 'ordering': ['-is_primary', '-created_at'], 

45 }, 

46 ), 

47 migrations.CreateModel( 

48 name='EmailFolder', 

49 fields=[ 

50 ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 

51 ('created_at', models.DateTimeField(auto_now_add=True)), 

52 ('updated_at', models.DateTimeField(auto_now=True)), 

53 ('tenant_id', models.UUIDField(db_index=True)), 

54 ('name', models.CharField(max_length=128)), 

55 ('remote_id', models.CharField(blank=True, max_length=256, null=True)), 

56 ('folder_type', models.CharField(choices=[('inbox', 'Inbox'), ('sent', 'Sent'), ('draft', 'Drafts'), ('trash', 'Trash'), ('spam', 'Spam'), ('custom', 'Custom')], default='custom', max_length=16)), 

57 ('unread_count', models.IntegerField(default=0)), 

58 ('account', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='folders', to='email.emailaccount')), 

59 ], 

60 options={ 

61 'ordering': ['folder_type', 'name'], 

62 'unique_together': {('account', 'remote_id')}, 

63 }, 

64 ), 

65 migrations.CreateModel( 

66 name='EmailMessage', 

67 fields=[ 

68 ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), 

69 ('created_at', models.DateTimeField(auto_now_add=True)), 

70 ('updated_at', models.DateTimeField(auto_now=True)), 

71 ('tenant_id', models.UUIDField(db_index=True)), 

72 ('message_id', models.CharField(max_length=512)), 

73 ('uid', models.CharField(blank=True, max_length=256, null=True)), 

74 ('from_address', models.CharField(max_length=256)), 

75 ('from_name', models.CharField(blank=True, max_length=128, null=True)), 

76 ('to_addresses', models.JSONField(default=list)), 

77 ('cc_addresses', models.JSONField(blank=True, null=True)), 

78 ('bcc_addresses', models.JSONField(blank=True, null=True)), 

79 ('subject', models.CharField(max_length=512)), 

80 ('snippet', models.CharField(blank=True, max_length=256)), 

81 ('body_text', models.TextField(blank=True, null=True)), 

82 ('body_html', models.TextField(blank=True, null=True)), 

83 ('is_read', models.BooleanField(default=False)), 

84 ('is_starred', models.BooleanField(default=False)), 

85 ('is_draft', models.BooleanField(default=False)), 

86 ('is_sent', models.BooleanField(default=False)), 

87 ('is_internal', models.BooleanField(default=False)), 

88 ('is_flagged', models.BooleanField(default=False)), 

89 ('sent_at', models.DateTimeField(blank=True, null=True)), 

90 ('received_at', models.DateTimeField(blank=True, null=True)), 

91 ('size_bytes', models.IntegerField(default=0)), 

92 ('account', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='messages', to='email.emailaccount')), 

93 ('folder', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='messages', to='email.emailfolder')), 

94 ], 

95 options={ 

96 'ordering': ['-received_at', '-created_at'], 

97 }, 

98 ), 

99 migrations.AddIndex( 

100 model_name='emailmessage', 

101 index=models.Index(fields=['tenant_id', 'folder', '-received_at'], name='email_messag_tenant__idx'), 

102 ), 

103 migrations.AddIndex( 

104 model_name='emailmessage', 

105 index=models.Index(fields=['tenant_id', 'account', '-received_at'], name='email_messag_tenant__idx2'), 

106 ), 

107 migrations.CreateModel( 

108 name='EmailAttachment', 

109 fields=[ 

110 ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), 

111 ('created_at', models.DateTimeField(auto_now_add=True)), 

112 ('updated_at', models.DateTimeField(auto_now=True)), 

113 ('tenant_id', models.UUIDField(db_index=True)), 

114 ('file_name', models.CharField(max_length=256)), 

115 ('content_type', models.CharField(max_length=128)), 

116 ('size_bytes', models.IntegerField(default=0)), 

117 ('remote_id', models.CharField(blank=True, max_length=256, null=True)), 

118 ('file_path', models.CharField(blank=True, max_length=512, null=True)), 

119 ('message', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attachments', to='email.emailmessage')), 

120 ], 

121 ), 

122 migrations.CreateModel( 

123 name='InternalEmail', 

124 fields=[ 

125 ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), 

126 ('created_at', models.DateTimeField(auto_now_add=True)), 

127 ('updated_at', models.DateTimeField(auto_now=True)), 

128 ('tenant_id', models.UUIDField(db_index=True)), 

129 ('subject', models.CharField(max_length=512)), 

130 ('body', models.TextField()), 

131 ('sent_at', models.DateTimeField(auto_now_add=True)), 

132 ('sender', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='sent_internal_emails', to='authentication.user')), 

133 ], 

134 options={ 

135 'ordering': ['-sent_at'], 

136 }, 

137 ), 

138 migrations.CreateModel( 

139 name='InternalEmailRecipient', 

140 fields=[ 

141 ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), 

142 ('created_at', models.DateTimeField(auto_now_add=True)), 

143 ('updated_at', models.DateTimeField(auto_now=True)), 

144 ('tenant_id', models.UUIDField(db_index=True)), 

145 ('is_read', models.BooleanField(default=False)), 

146 ('read_at', models.DateTimeField(blank=True, null=True)), 

147 ('email', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='recipients', to='email.internalemail')), 

148 ('recipient', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='email_recipients', to='authentication.user')), 

149 ], 

150 options={ 

151 'unique_together': {('email', 'recipient')}, 

152 }, 

153 ), 

154 ]