Skip to content

Commit 9e48b82

Browse files
authored
Merge pull request doccano#422 from CatalystCode/enhancement/mysql
Enhancement/Add support for MySQL
2 parents f0de656 + 1dd2e2b commit 9e48b82

9 files changed

+61
-129
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ env:
77
- DATABASE=sqlite
88
- DATABASE=postgres
99
- DATABASE=mssql
10+
- DATABASE=mysql
1011

1112
services:
1213
- docker
@@ -22,6 +23,10 @@ before_install:
2223
docker run --rm --name=mssql --network=doccano -d -e ACCEPT_EULA=y -e SA_PASSWORD=sUp3rS3cr3t mcr.microsoft.com/mssql/server:2017-latest
2324
docker exec -it mssql sh -c "while ! /opt/mssql-tools/bin/sqlcmd -U SA -P sUp3rS3cr3t -Q 'CREATE DATABASE db;'; do sleep 3; done"
2425
export DATABASE_URL="mssql://SA:sUp3rS3cr3t@mssql:1433/db?sslmode=disable"
26+
27+
elif [[ "${DATABASE}" = "mysql" ]]; then
28+
docker run --rm --name=mysql --network=doccano -d -e MYSQL_DATABASE=db -e MYSQL_ROOT_PASSWORD=mysqlr00t mysql:5.7
29+
export DATABASE_URL="mysql://root:mysqlr00t@mysql:3306/db"
2530
fi
2631
2732
install:

app/api/migrations/0001_initial.py

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by Django 2.1.7 on 2019-06-21 06:05
1+
# Generated by Django 2.1.7 on 2019-10-25 16:26
22

33
from django.conf import settings
44
from django.db import migrations, models
@@ -10,8 +10,8 @@ class Migration(migrations.Migration):
1010
initial = True
1111

1212
dependencies = [
13-
('contenttypes', '0002_remove_content_type_name'),
1413
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
14+
('contenttypes', '0002_remove_content_type_name'),
1515
]
1616

1717
operations = [
@@ -23,6 +23,7 @@ class Migration(migrations.Migration):
2323
('meta', models.TextField(default='{}')),
2424
('created_at', models.DateTimeField(auto_now_add=True)),
2525
('updated_at', models.DateTimeField(auto_now=True)),
26+
('annotations_approved_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
2627
],
2728
),
2829
migrations.CreateModel(
@@ -60,12 +61,31 @@ class Migration(migrations.Migration):
6061
('updated_at', models.DateTimeField(auto_now=True)),
6162
('project_type', models.CharField(choices=[('DocumentClassification', 'document classification'), ('SequenceLabeling', 'sequence labeling'), ('Seq2seq', 'sequence to sequence')], max_length=30)),
6263
('randomize_document_order', models.BooleanField(default=False)),
64+
('collaborative_annotation', models.BooleanField(default=False)),
6365
],
6466
options={
6567
'abstract': False,
6668
'base_manager_name': 'objects',
6769
},
6870
),
71+
migrations.CreateModel(
72+
name='Role',
73+
fields=[
74+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
75+
('name', models.CharField(max_length=100, unique=True)),
76+
('description', models.TextField(default='')),
77+
('created_at', models.DateTimeField(auto_now_add=True)),
78+
('updated_at', models.DateTimeField(auto_now=True)),
79+
],
80+
),
81+
migrations.CreateModel(
82+
name='RoleMapping',
83+
fields=[
84+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
85+
('created_at', models.DateTimeField(auto_now_add=True)),
86+
('updated_at', models.DateTimeField(auto_now=True)),
87+
],
88+
),
6989
migrations.CreateModel(
7090
name='Seq2seqAnnotation',
7191
fields=[
@@ -74,7 +94,7 @@ class Migration(migrations.Migration):
7494
('manual', models.BooleanField(default=False)),
7595
('created_at', models.DateTimeField(auto_now_add=True)),
7696
('updated_at', models.DateTimeField(auto_now=True)),
77-
('text', models.TextField()),
97+
('text', models.CharField(max_length=500)),
7898
('document', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='seq2seq_annotations', to='api.Document')),
7999
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
80100
],
@@ -127,6 +147,21 @@ class Migration(migrations.Migration):
127147
},
128148
bases=('api.project',),
129149
),
150+
migrations.AddField(
151+
model_name='rolemapping',
152+
name='project',
153+
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='role_mappings', to='api.Project'),
154+
),
155+
migrations.AddField(
156+
model_name='rolemapping',
157+
name='role',
158+
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.Role'),
159+
),
160+
migrations.AddField(
161+
model_name='rolemapping',
162+
name='user',
163+
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='role_mappings', to=settings.AUTH_USER_MODEL),
164+
),
130165
migrations.AddField(
131166
model_name='project',
132167
name='polymorphic_ctype',
@@ -161,9 +196,17 @@ class Migration(migrations.Migration):
161196
name='sequenceannotation',
162197
unique_together={('document', 'user', 'label', 'start_offset', 'end_offset')},
163198
),
199+
migrations.AlterUniqueTogether(
200+
name='seq2seqannotation',
201+
unique_together={('document', 'user', 'text')},
202+
),
203+
migrations.AlterUniqueTogether(
204+
name='rolemapping',
205+
unique_together={('user', 'project', 'role')},
206+
),
164207
migrations.AlterUniqueTogether(
165208
name='label',
166-
unique_together={('project', 'text'), ('project', 'prefix_key', 'suffix_key')},
209+
unique_together={('project', 'text')},
167210
),
168211
migrations.AlterUniqueTogether(
169212
name='documentannotation',

app/api/migrations/0002_approve_document_labels.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

app/api/migrations/0003_support_sql_server.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

app/api/migrations/0004_project_collaborative_annotation.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

app/api/migrations/0004_roles.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

app/api/migrations/0005_merge_20191021_1548.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

app/app/settings.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,16 @@
263263
if DATABASES['default'].get('ENGINE') == 'django.db.backends.sqlite3':
264264
DATABASES['default'].get('OPTIONS', {}).pop('sslmode', None)
265265

266+
# work-around for dj-database-url: patch ssl for mysql
267+
if DATABASES['default'].get('ENGINE') == 'django.db.backends.mysql':
268+
DATABASES['default'].get('OPTIONS', {}).pop('sslmode', None)
269+
if env('MYSQL_SSL_CA', None):
270+
DATABASES['default'].setdefault('OPTIONS', {})\
271+
.setdefault('ssl', {}).setdefault('ca', env('MYSQL_SSL_CA', None))
272+
266273
# default to a sensible modern driver for Azure SQL
267274
if DATABASES['default'].get('ENGINE') == 'sql_server.pyodbc':
268-
db_options = DATABASES['default'].setdefault('OPTIONS', {})\
275+
DATABASES['default'].setdefault('OPTIONS', {})\
269276
.setdefault('driver', 'ODBC Driver 17 for SQL Server')
270277

271278
# Honor the 'X-Forwarded-Proto' header for request.is_secure()

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ furl==2.0.0
2424
gunicorn==19.9.0
2525
lockfile==0.12.2
2626
model-mommy==1.6.0
27+
mysqlclient==1.4.2.post1
2728
psycopg2-binary==2.7.7
2829
pyexcel==0.5.14
2930
pyexcel-xlsx==0.5.7

0 commit comments

Comments
 (0)