-
-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement self-contained archives to import and export entire users b…
…etween instances (#38) Co-authored-by: Daniel Burgess <[email protected]> Co-authored-by: Hugh Rundle <[email protected]> Co-authored-by: dannymate <[email protected]> Co-authored-by: hughrun <[email protected]> Reviewed-on: https://codeberg.org/GuildAlpha/bookwyrm/pulls/38 Co-authored-by: CSDUMMI <[email protected]> Co-committed-by: CSDUMMI <[email protected]>
- Loading branch information
1 parent
bc870a3
commit b3086a3
Showing
26 changed files
with
2,669 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
- name: Run Bookwyrm Service | ||
hosts: localhost | ||
gather_facts: false | ||
tasks: | ||
- name: Create Nginx default.conf | ||
ansible.builtin.copy: | ||
src: ./nginx/development | ||
dest: ./nginx/default.conf | ||
mode: u=rw,g=r,o=r # Ensuring correct permissions for the copied file | ||
force: no # We don't want to overwrite .env every run as we may have made changes | ||
|
||
- name: Create .env file | ||
ansible.builtin.copy: | ||
src: ./.env.example | ||
dest: ./.env | ||
mode: u=rw,g=r,o=r | ||
force: no | ||
|
||
- name: Set .env to debug | ||
ansible.builtin.lineinfile: | ||
path: ./.env | ||
regexp: "^DEBUG=" | ||
line: DEBUG=true | ||
|
||
- name: Install py-docker | ||
pip: | ||
name: | ||
- docker | ||
- pyyaml | ||
- docker-compose | ||
state: present | ||
|
||
- name: Tear down existing services | ||
community.docker.docker_compose: | ||
project_src: . | ||
state: absent | ||
|
||
- name: Initialize the database and run migrations | ||
ansible.builtin.shell: | ||
cmd: ./bw-dev setup && touch .migrated | ||
creates: .migrated | ||
|
||
|
||
- name: Initialize the database and run migrations | ||
community.docker.docker_compose: | ||
project_src: . | ||
state: present |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
- name: Initalise Python Environment for development | ||
hosts: localhost | ||
tasks: | ||
- name: Create venv | ||
command: python -m venv ./venv | ||
|
||
- name: Install Requirements | ||
command: python venv/bin/pip3 install -r requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"""Import data from Bookwyrm export files""" | ||
from bookwyrm import settings | ||
from bookwyrm.models.bookwyrm_import_job import BookwyrmImportJob | ||
|
||
class BookwyrmImporter: | ||
"""Import a Bookwyrm User export JSON file. | ||
This is kind of a combination of an importer and a connector. | ||
""" | ||
|
||
def process_import(self, user, archive_file, settings): | ||
"""import user data from a Bookwyrm export file""" | ||
|
||
required = [k for k in settings if settings.get(k) == "on"] | ||
|
||
job = BookwyrmImportJob.objects.create( | ||
user=user, archive_file=archive_file, required=required | ||
) | ||
return job |
71 changes: 71 additions & 0 deletions
71
bookwyrm/migrations/0179_bookwyrmexportjob_bookwyrmimportjob_childjob_parentjob.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Generated by Django 3.2.19 on 2023-08-31 22:57 | ||
|
||
from django.conf import settings | ||
import django.contrib.postgres.fields | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import django.utils.timezone | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('bookwyrm', '0178_auto_20230328_2132'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='ParentJob', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('task_id', models.UUIDField(blank=True, null=True, unique=True)), | ||
('created_date', models.DateTimeField(default=django.utils.timezone.now)), | ||
('updated_date', models.DateTimeField(default=django.utils.timezone.now)), | ||
('complete', models.BooleanField(default=False)), | ||
('status', models.CharField(choices=[('pending', 'Pending'), ('active', 'Active'), ('complete', 'Complete'), ('stopped', 'Stopped')], default='pending', max_length=50, null=True)), | ||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='BookwyrmExportJob', | ||
fields=[ | ||
('parentjob_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='bookwyrm.parentjob')), | ||
('export_data', models.FileField(null=True, upload_to='')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
bases=('bookwyrm.parentjob',), | ||
), | ||
migrations.CreateModel( | ||
name='BookwyrmImportJob', | ||
fields=[ | ||
('parentjob_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='bookwyrm.parentjob')), | ||
('archive_file', models.FileField(blank=True, null=True, upload_to='')), | ||
('import_data', models.JSONField(null=True)), | ||
('required', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(blank=True, max_length=50), blank=True, size=None)), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
bases=('bookwyrm.parentjob',), | ||
), | ||
migrations.CreateModel( | ||
name='ChildJob', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('task_id', models.UUIDField(blank=True, null=True, unique=True)), | ||
('created_date', models.DateTimeField(default=django.utils.timezone.now)), | ||
('updated_date', models.DateTimeField(default=django.utils.timezone.now)), | ||
('complete', models.BooleanField(default=False)), | ||
('status', models.CharField(choices=[('pending', 'Pending'), ('active', 'Active'), ('complete', 'Complete'), ('stopped', 'Stopped')], default='pending', max_length=50, null=True)), | ||
('parent_job', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='child_jobs', to='bookwyrm.parentjob')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Generated by Django 3.2.19 on 2023-09-05 22:40 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('bookwyrm', '0179_bookwyrmexportjob_bookwyrmimportjob_childjob_parentjob'), | ||
('bookwyrm', '0181_merge_20230806_2302'), | ||
] | ||
|
||
operations = [ | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.