oedb-backend/CHANGES.md
2025-09-26 15:08:33 +02:00

2.8 KiB

Changes Implemented

1. Delete Button for Events

The delete button was already implemented in the event edit page:

  • The button exists in /oedb/resources/demo/templates/edit.html (line 77)
  • The JavaScript functionality to send a DELETE request is implemented in /oedb/resources/demo/static/edit.js (lines 167-209)
  • When clicked, the button sends a DELETE request to /event/{id} and handles the response

2. Force Atlas Graph in Live Page

Modified the force atlas graph in the live page to use event types from the last 1000 events:

  • Updated the API URL in /oedb/resources/live.py from:
    const API_URL = 'https://api.openeventdatabase.org/event?when=last7days&limit=2000';
    
    to:
    const API_URL = 'https://api.openeventdatabase.org/event?limit=1000';
    
  • The existing implementation already groups events by "what" field in the buildFamilyGraph function (lines 321-348)

3. Database Dump Endpoints

Created new endpoints for database dumps:

  1. Created a new file /oedb/resources/db_dump.py with two resource classes:

    • DbDumpListResource: Lists existing database dumps
    • DbDumpCreateResource: Creates new dumps in SQL and GeoJSON formats
  2. Implemented features:

    • Created a directory to store database dumps
    • Used pg_dump to create SQL dumps
    • Queried the database and converted to GeoJSON for GeoJSON dumps
    • Included timestamps in the filenames (e.g., oedb_dump_20250926_145800.sql)
    • Added proper error handling and logging
  3. Updated /backend.py to:

    • Import the new resources
    • Register the new endpoints:
      • /db/dumps: Lists all available database dumps
      • /db/dumps/create: Creates new database dumps

Usage

Listing Database Dumps

Send a GET request to /db/dumps to get a list of all available database dumps:

GET /db/dumps

Response:

{
  "dumps": [
    {
      "filename": "oedb_dump_20250926_145800.sql",
      "path": "/db/dumps/oedb_dump_20250926_145800.sql",
      "size": 1234567,
      "created": "2025-09-26T14:58:00",
      "type": "sql"
    },
    {
      "filename": "oedb_dump_20250926_145800.geojson",
      "path": "/db/dumps/oedb_dump_20250926_145800.geojson",
      "size": 7654321,
      "created": "2025-09-26T14:58:00",
      "type": "geojson"
    }
  ]
}

Creating Database Dumps

Send a POST request to /db/dumps/create to create new database dumps:

POST /db/dumps/create

Response:

{
  "message": "Database dumps created successfully",
  "dumps": [
    {
      "filename": "oedb_dump_20250926_145800.sql",
      "path": "/db/dumps/oedb_dump_20250926_145800.sql",
      "type": "sql",
      "size": 1234567
    },
    {
      "filename": "oedb_dump_20250926_145800.geojson",
      "path": "/db/dumps/oedb_dump_20250926_145800.geojson",
      "type": "geojson",
      "size": 7654321
    }
  ]
}