old_contents: from __future__ import absolute_import
  
  import logging
  
  from sqlalchemy import create_engine
  from sqlalchemy.ext.declarative import declarative_base
  
  from sqlalchemy.orm import sessionmaker
  from sqlalchemy import Column, String, DateTime
  
  from sqlalchemy.dialects.postgresql import JSON
  
  from scrapi import events
  from scrapi.processing.base import BaseProcessor
  
  logger = logging.getLogger(__name__)
  
  engine = create_engine('postgresql://localhost/scrapi', echo=True)
  session = sessionmaker(bind=engine)()
  Base = declarative_base(bind=engine)
  
  
  class PostgresProcessor(BaseProcessor):
      NAME = 'postgres'
  
      def __init__(self, *args, **kwargs):
          Base.metadata.create_all()
          session.commit()
          super(PostgresProcessor, self).__init__(*args, **kwargs)
  
      @events.logged(events.PROCESSING, 'raw.postgres')
      def process_raw(self, raw_doc):
          source, docID = raw_doc['source'], raw_doc['docID']
          document = self._get_by_source_id(Document, source, docID) or Document(source=source, docID=docID)
  
          document.raw = raw_doc.attributes
          session.add(document)
          session.commit()
  
      @events.logged(events.PROCESSING, 'normalized.postgres')
      def process_normalized(self, raw_doc, normalized):
          source, docID = raw_doc['source'], raw_doc['docID']
          document = self._get_by_source_id(Document, source, docID) or Document(source=source, docID=docID)
  
          document.normalized = normalized.attributes
          document.providerUpdatedDateTime = normalized['providerUpdatedDateTime']
  
          session.add(document)
          session.commit()
  
          session.close()
  
      def _get_by_source_id(self, model, source, docID):
          return session.query(model).filter_by(source=source, docID=docID).first()
  
  
  class Document(Base):
      __tablename__ = 'documents'
  
      source = Column(String, primary_key=True)
      docID = Column(String, primary_key=True)
      providerUpdatedDateTime = Column(DateTime, primary_key=True)
  
      raw = Column(JSON)
      normalized = Column(JSON)
  
new_contents: from __future__ import absolute_import
  
  import logging
  
  from sqlalchemy import create_engine
  from sqlalchemy.ext.declarative import declarative_base
  
  from sqlalchemy.orm import sessionmaker
  from sqlalchemy import Column, String, DateTime, Integer, Sequence
  
  from sqlalchemy.dialects.postgresql import JSON
  
  from scrapi import events
  from scrapi.processing.base import BaseProcessor
  
  logger = logging.getLogger(__name__)
  
  engine = create_engine('postgresql://localhost/scrapi', echo=True)
  session = sessionmaker(bind=engine)()
  Base = declarative_base(bind=engine)
  
  
  class PostgresProcessor(BaseProcessor):
      NAME = 'postgres'
  
      def __init__(self, *args, **kwargs):
          Base.metadata.create_all()
          session.commit()
          super(PostgresProcessor, self).__init__(*args, **kwargs)
  
      @events.logged(events.PROCESSING, 'raw.postgres')
      def process_raw(self, raw_doc):
          source, docID = raw_doc['source'], raw_doc['docID']
          document = self._get_by_source_id(Document, source, docID) or Document(source=source, docID=docID)
  
          document.raw = raw_doc.attributes
          session.add(document)
          session.commit()
  
      @events.logged(events.PROCESSING, 'normalized.postgres')
      def process_normalized(self, raw_doc, normalized):
          source, docID = raw_doc['source'], raw_doc['docID']
          document = self._get_by_source_id(Document, source, docID) or Document(source=source, docID=docID)
  
          document.normalized = normalized.attributes
          document.providerUpdatedDateTime = normalized['providerUpdatedDateTime']
  
          session.add(document)
          session.commit()
  
      def _get_by_source_id(self, model, source, docID):
          return session.query(model).filter_by(source=source, docID=docID).first()
  
  
  class Document(Base):
      __tablename__ = 'documents'
  
      source = Column(String, primary_key=True)
      docID = Column(String, primary_key=True)
      shareID = Column(Integer, Sequence('shareid_seq'), primary_key=True)
  
      providerUpdatedDateTime = Column(DateTime)
  
      raw = Column(JSON)
      normalized = Column(JSON)
  
subject: Add auto-incrementing IDs