Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend metadata for Document- and Dossiersyncer #8095

Draft
wants to merge 6 commits into
base: export-ng
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added opengever/exportng/__init__.py
Empty file.
43 changes: 43 additions & 0 deletions opengever/exportng/db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from sqlalchemy import Boolean
from sqlalchemy import Column
from sqlalchemy import create_engine
from sqlalchemy import Date
from sqlalchemy import DateTime
from sqlalchemy import Integer
from sqlalchemy import MetaData
from sqlalchemy import String
from sqlalchemy import Table
from sqlalchemy import Text
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.sql import func


COLUMN_TYPES = {
'varchar': String,
'text': Text,
'jsonb': JSONB,
'integer': Integer,
'date': Date,
'datetime': DateTime,
'boolean': Boolean,
}

engine = create_engine('postgresql:///exportng')
metadata = MetaData(bind=engine)


def create_table(table, mapping):
if table in metadata.tables:
return
cols = []
for attr in mapping:
cols.append(Column(
attr.col_name,
COLUMN_TYPES[attr.col_type],
nullable=True,
))
cols.append(Column('_created_at', DateTime, index=True, server_default=func.now()))
cols.append(Column('_modified_at', DateTime, index=True, onupdate=func.now()))
cols.append(Column('_synced_at', DateTime, index=True, onupdate=func.now()))
cols.append(Column('_deleted', Boolean, index=True, default=False))
Table(table, metadata, *cols)
21 changes: 21 additions & 0 deletions opengever/exportng/mapping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
from openpyxl import load_workbook
import itertools
import os.path


def read_mapping(mapping_file):
filename = os.path.join(
os.path.dirname(__file__), mapping_file)
wb = load_workbook(filename=filename)
sheet = wb.active
rows = []
colnames = [cell.value for cell in sheet[1]]
for row in sheet.iter_rows(min_row=2):
data = {k: row[idx].value for idx, k in enumerate(colnames)}
rows.append(data)

mappings = {}
for k, v in itertools.groupby(rows, lambda x: x['table_name']):
mappings[k] = list(v)
return mappings
Loading