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

Simplify server to accounts and readmodel #97

Merged
merged 2 commits into from
Jan 4, 2025
Merged
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
2 changes: 0 additions & 2 deletions server/requirements.txt
Original file line number Diff line number Diff line change
@@ -9,6 +9,4 @@ psycopg2-binary
pydantic==2.10.4
pydantic-settings==2.7.0
fastapi[standard]==0.115.6
ariadne
boto3
faker==33.1.0
40 changes: 0 additions & 40 deletions server/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -25,15 +25,7 @@
from the_history_atlas.apps.accounts.schema import Base as AccountsBase, User

from the_history_atlas.apps.config import Config
from the_history_atlas.apps.eventstore.event_schema import Base as EventsAppBase
from the_history_atlas.apps.readmodel.schema import Base as ReadModelBase
from the_history_atlas.apps.writemodel.state_manager.database import (
Database as WriteModelDB,
)
from the_history_atlas.apps.writemodel.state_manager.schema import (
Base as WriteModelBase,
GUID,
)


@pytest.fixture
@@ -52,17 +44,11 @@ def config():
def engine(config):
engine = create_engine(config.DB_URI, echo=config.DEBUG, future=True)
AccountsBase.metadata.create_all(engine)
WriteModelBase.metadata.create_all(engine)
EventsAppBase.metadata.create_all(engine)
ReadModelBase.metadata.create_all(engine)

truncate_stmt = """
truncate users cascade;
truncate citation_hashes cascade;
truncate citations cascade;
truncate events cascade;
truncate guids cascade;
truncate history cascade;
truncate names cascade;
truncate person cascade;
truncate place cascade;
@@ -283,29 +269,3 @@ def recursively_redact(d):

recursively_redact(data)
return data


@pytest.fixture
def writemodel_db(
engine,
existing_summary_id,
existing_meta_id,
existing_time_id,
existing_place_id,
existing_person_id,
):
db = WriteModelDB(database_client=engine, stm_timeout=0)

with Session(engine, future=True) as session:
session.add_all(
[
GUID(value=existing_summary_id, type="SUMMARY"),
GUID(value=existing_meta_id, type="META"),
GUID(value=existing_person_id, type="PERSON"),
GUID(value=existing_place_id, type="PLACE"),
GUID(value=existing_time_id, type="TIME"),
]
)
session.commit()

return db
1 change: 0 additions & 1 deletion server/tests/seed/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from .synthetic_events import SYNTHETIC_EVENTS
from .commands import PUBLISH_CITATION_DOMAIN_OBJECTS
from .events import EVENTS
261 changes: 0 additions & 261 deletions server/tests/seed/commands.py

This file was deleted.

Empty file removed server/tests/test_api/__init__.py
Empty file.
Empty file.
35 changes: 0 additions & 35 deletions server/tests/test_api/test_resolvers/conftest.py

This file was deleted.

Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Empty file.

This file was deleted.

Empty file.
29 changes: 0 additions & 29 deletions server/tests/test_api/test_schema/conftest.py

This file was deleted.

9 changes: 0 additions & 9 deletions server/tests/test_api/test_schema/test_build_schema.py

This file was deleted.

402 changes: 0 additions & 402 deletions server/tests/test_api/test_schema/test_mutation.py

This file was deleted.

Empty file.
Empty file.
42 changes: 0 additions & 42 deletions server/tests/test_apps/eventstore/conftest.py

This file was deleted.

33 changes: 0 additions & 33 deletions server/tests/test_apps/eventstore/test_eventstore.py

This file was deleted.

110 changes: 0 additions & 110 deletions server/tests/test_apps/readmodel/test_gql_schema.py

This file was deleted.

Empty file.
35 changes: 0 additions & 35 deletions server/tests/test_apps/writemodel/conftest.py

This file was deleted.

404 changes: 0 additions & 404 deletions server/tests/test_apps/writemodel/test_command_handler.py

This file was deleted.

85 changes: 0 additions & 85 deletions server/tests/test_apps/writemodel/test_database.py

This file was deleted.

87 changes: 0 additions & 87 deletions server/tests/test_apps/writemodel/test_event_handler.py

This file was deleted.

69 changes: 0 additions & 69 deletions server/tests/test_apps/writemodel/test_text_processor.py

This file was deleted.

26 changes: 0 additions & 26 deletions server/the_history_atlas/api/context.py

This file was deleted.

6 changes: 0 additions & 6 deletions server/the_history_atlas/api/main.py
Original file line number Diff line number Diff line change
@@ -4,18 +4,12 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

from the_history_atlas.api.context import get_context
from the_history_atlas.api.rest import register_rest_endpoints
from the_history_atlas.api.schema import build_schema
from the_history_atlas.apps.app_manager import AppManager


def mount_api(app: FastAPI, app_manager: AppManager) -> FastAPI:
app = register_rest_endpoints(app)
schema = build_schema()
get_context_value = partial(get_context, _apps=app_manager)
graphql = GraphQL(schema, debug=True, context_value=get_context_value)
app.mount("/graphql/", graphql)
origins = ["http://localhost:3000", "https://urchin-app-f6n6t.ondigitalocean.app"]
app.add_middleware(
CORSMiddleware,
49 changes: 0 additions & 49 deletions server/the_history_atlas/api/resolvers/__init__.py

This file was deleted.

Empty file.
14 changes: 0 additions & 14 deletions server/the_history_atlas/api/resolvers/accounts/add_user.py

This file was deleted.

11 changes: 0 additions & 11 deletions server/the_history_atlas/api/resolvers/accounts/confirm_account.py

This file was deleted.

This file was deleted.

12 changes: 0 additions & 12 deletions server/the_history_atlas/api/resolvers/accounts/get_user.py

This file was deleted.

This file was deleted.

9 changes: 0 additions & 9 deletions server/the_history_atlas/api/resolvers/accounts/login.py

This file was deleted.

19 changes: 0 additions & 19 deletions server/the_history_atlas/api/resolvers/accounts/update_user.py

This file was deleted.

Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 0 additions & 11 deletions server/the_history_atlas/api/resolvers/readmodel/get_manifest.py

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 0 additions & 11 deletions server/the_history_atlas/api/resolvers/readmodel/search_sources.py

This file was deleted.

Empty file.

This file was deleted.

21 changes: 14 additions & 7 deletions server/the_history_atlas/api/rest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from fastapi import FastAPI
from pydantic import BaseModel
from typing import List, Union
@@ -17,9 +16,11 @@ class Point(BaseModel):
longitude: float
name: str


class Location(Point):
pass


class Source(BaseModel):
id: str
text: str
@@ -28,11 +29,13 @@ class Source(BaseModel):
publisher: str
pubDate: str


class CalendarDate(BaseModel):
time: str
calendar: str
precision: int


class Tag(BaseModel):
id: str
type: str
@@ -41,9 +44,11 @@ class Tag(BaseModel):
name: str
defaultStoryId: str


class Map(BaseModel):
locations: List[Location]


class HistoryEvent(BaseModel):
id: str
text: str
@@ -56,12 +61,14 @@ class HistoryEvent(BaseModel):
storyTitle: str
stories: List[str] = []


class Story(BaseModel):
id: str
name: str
events: List[HistoryEvent]
index: int


# Helper Functions
def build_story_title():
time_name = fake.date_this_century().strftime("%Y-%m-%d")
@@ -72,11 +79,13 @@ def build_story_title():
]
return random.choice(story_templates)()


def build_date(exact: bool, base_date=None):
if exact:
return base_date or fake.date_this_century()
return fake.date_between(start_date="-60y", end_date="today")


def build_source():
return Source(
id=str(uuid4()),
@@ -87,6 +96,7 @@ def build_source():
pubDate=str(fake.date_this_decade()),
)


def build_tags(text, map_options):
person_name = fake.name()
point = build_point(map_options)
@@ -121,6 +131,7 @@ def build_tags(text, map_options):
),
], tagged_text


def build_point(map_options):
latitude, longitude = fake.local_latlng(country_code="US", coords_only=True)
return Location(
@@ -151,15 +162,11 @@ def build_event(map_options, story_title):
stories=[],
)


def build_story():
story_title = build_story_title()
events = [build_event({}, story_title) for _ in range(10)]
return Story(
id=str(uuid4()),
name=story_title,
events=events,
index=5
)
return Story(id=str(uuid4()), name=story_title, events=events, index=5)


def register_rest_endpoints(app: FastAPI) -> FastAPI:
1 change: 0 additions & 1 deletion server/the_history_atlas/api/schema/__init__.py

This file was deleted.

21 changes: 0 additions & 21 deletions server/the_history_atlas/api/schema/build_schema.py

This file was deleted.

23 changes: 0 additions & 23 deletions server/the_history_atlas/api/schema/mutation.py

This file was deleted.

46 changes: 0 additions & 46 deletions server/the_history_atlas/api/schema/query.py

This file was deleted.

24 changes: 0 additions & 24 deletions server/the_history_atlas/api/schema/scalars.py

This file was deleted.

44 changes: 0 additions & 44 deletions server/the_history_atlas/api/types/accounts.graphql

This file was deleted.

24 changes: 0 additions & 24 deletions server/the_history_atlas/api/types/mutation.graphql

This file was deleted.

26 changes: 0 additions & 26 deletions server/the_history_atlas/api/types/nlp.graphql

This file was deleted.

34 changes: 0 additions & 34 deletions server/the_history_atlas/api/types/query.graphql

This file was deleted.

197 changes: 0 additions & 197 deletions server/the_history_atlas/api/types/readmodel.graphql

This file was deleted.

43 changes: 0 additions & 43 deletions server/the_history_atlas/api/types/writemodel.graphql

This file was deleted.

14 changes: 1 addition & 13 deletions server/the_history_atlas/apps/app_manager.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
from the_history_atlas.apps.accounts.accounts import Accounts
from the_history_atlas.apps.config import Config
from the_history_atlas.apps.database import DatabaseApp
from the_history_atlas.apps.eventstore import EventStore
from the_history_atlas.apps.readmodel import ReadModelApp
from the_history_atlas.apps.writemodel import WriteModelApp


class AppManager:
config_app: Config
database_app: DatabaseApp
events_app: EventStore
accounts_app: Accounts
writemodel_app: WriteModelApp
readmodel_app: ReadModelApp

def __init__(self, config_app: Config):
self.config_app = config_app
self.database_app = DatabaseApp(config_app=self.config_app)
self.events_app = EventStore(
config=self.config_app, database_client=self.database_app.client()
)
self.accounts_app = Accounts(
config=self.config_app, database_client=self.database_app.client()
)
self.writemodel_app = WriteModelApp(
config=self.config_app,
database_client=self.database_app.client(),
events_app=self.events_app,
accounts_app=self.accounts_app,
)

self.readmodel_app = ReadModelApp(
config_app=self.config_app,
database_client=self.database_app.client(),
162 changes: 0 additions & 162 deletions server/the_history_atlas/apps/eventstore/README.md

This file was deleted.

2 changes: 0 additions & 2 deletions server/the_history_atlas/apps/eventstore/__init__.py

This file was deleted.

45 changes: 0 additions & 45 deletions server/the_history_atlas/apps/eventstore/database.py

This file was deleted.

37 changes: 0 additions & 37 deletions server/the_history_atlas/apps/eventstore/event_schema.py

This file was deleted.

35 changes: 0 additions & 35 deletions server/the_history_atlas/apps/eventstore/event_store.py

This file was deleted.

118 changes: 0 additions & 118 deletions server/the_history_atlas/apps/readmodel/README.md

This file was deleted.

1 change: 0 additions & 1 deletion server/the_history_atlas/apps/readmodel/api/__init__.py

This file was deleted.

57 changes: 0 additions & 57 deletions server/the_history_atlas/apps/readmodel/api/api.py

This file was deleted.

26 changes: 0 additions & 26 deletions server/the_history_atlas/apps/readmodel/api/types.py

This file was deleted.

3 changes: 1 addition & 2 deletions server/the_history_atlas/apps/readmodel/database.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
from collections import defaultdict
from datetime import datetime
from typing import Tuple, Union, Optional, List, Dict
from typing import Tuple, Union, Optional, List
from uuid import uuid4, UUID

from sqlalchemy import select, func, text
@@ -30,7 +30,6 @@
from the_history_atlas.apps.readmodel.schema import (
Base,
Citation,
History,
Name,
Person,
Place,
19 changes: 0 additions & 19 deletions server/the_history_atlas/apps/readmodel/schema.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
from enum import Enum

from sqlalchemy import Column, String, TIMESTAMP
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.sql.schema import ForeignKey, Table
from sqlalchemy.dialects.postgresql import VARCHAR, INTEGER, FLOAT, UUID, JSONB
from the_history_atlas.apps.readmodel.errors import EmptyNameError

Base = declarative_base()

@@ -143,28 +140,12 @@ def __repr__(self):
return f"Place(latitude: {self.latitude}, longitude: {self.longitude})"


class Language(Base):
__tablename__ = "languages"

id = Column(UUID(as_uuid=True), primary_key=True)
code = Column(VARCHAR, nullable=False)


class Name(Base):
__tablename__ = "names"

id = Column(UUID(as_uuid=True), primary_key=True)
name = Column(VARCHAR, unique=True, nullable=False)
# lang_id = Column(UUID(as_uuid=True), ForeignKey("languages.id"), nullable=False)
tags = relationship("Tag", secondary=tag_name_assoc, back_populates="names")

def __repr__(self):
return f"Name(id: {self.id}, name: {self.name})"


class History(Base):

__tablename__ = "history"

id = Column(INTEGER, primary_key=True)
latest_event_id = Column(INTEGER, default=0)
45 changes: 0 additions & 45 deletions server/the_history_atlas/apps/writemodel/README.md

This file was deleted.

1 change: 0 additions & 1 deletion server/the_history_atlas/apps/writemodel/__init__.py

This file was deleted.

2 changes: 0 additions & 2 deletions server/the_history_atlas/apps/writemodel/api/README.md

This file was deleted.

Empty file.
142 changes: 0 additions & 142 deletions server/the_history_atlas/apps/writemodel/api/api.py

This file was deleted.

59 changes: 0 additions & 59 deletions server/the_history_atlas/apps/writemodel/api/types.py

This file was deleted.

37 changes: 0 additions & 37 deletions server/the_history_atlas/apps/writemodel/server.py

This file was deleted.

Empty file.

This file was deleted.

113 changes: 0 additions & 113 deletions server/the_history_atlas/apps/writemodel/state_manager/database.py

This file was deleted.

Loading