Skip to content

Commit

Permalink
Implement self-contained archives to import and export entire users b…
Browse files Browse the repository at this point in the history
…etween instances (bookwyrm-social#38)

Co-authored-by: Daniel Burgess <developerdannymate@gmail.com>
Co-authored-by: Hugh Rundle <hugh@hughrundle.net>
Co-authored-by: dannymate <dannymate@noreply.codeberg.org>
Co-authored-by: hughrun <hughrun@noreply.codeberg.org>
Reviewed-on: https://codeberg.org/GuildAlpha/bookwyrm/pulls/38
Co-authored-by: CSDUMMI <csdummi.misquality@simplelogin.co>
Co-committed-by: CSDUMMI <csdummi.misquality@simplelogin.co>
  • Loading branch information
5 people committed Sep 5, 2023
1 parent bc870a3 commit b3086a3
Show file tree
Hide file tree
Showing 26 changed files with 2,669 additions and 7 deletions.
47 changes: 47 additions & 0 deletions .ansible.yml
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
8 changes: 8 additions & 0 deletions .init-playbook.yml
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
4 changes: 4 additions & 0 deletions bookwyrm/forms/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class ImportForm(forms.Form):
csv_file = forms.FileField()


class ImportUserForm(forms.Form):
archive_file = forms.FileField()


class ShelfForm(CustomForm):
class Meta:
model = models.Shelf
Expand Down
1 change: 1 addition & 0 deletions bookwyrm/importers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
""" import classes """

from .importer import Importer
from .bookwyrm_import import BookwyrmImporter
from .calibre_import import CalibreImporter
from .goodreads_import import GoodreadsImporter
from .librarything_import import LibrarythingImporter
Expand Down
18 changes: 18 additions & 0 deletions bookwyrm/importers/bookwyrm_import.py
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
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,
},
),
]
14 changes: 14 additions & 0 deletions bookwyrm/migrations/0182_merge_20230905_2240.py
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 = [
]
1 change: 1 addition & 0 deletions bookwyrm/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from .group import Group, GroupMember, GroupMemberInvitation

from .import_job import ImportJob, ImportItem
from .bookwyrm_import_job import BookwyrmImportJob

from .site import SiteSettings, Theme, SiteInvite
from .site import PasswordReset, InviteRequest
Expand Down
Loading

0 comments on commit b3086a3

Please sign in to comment.