Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9dbb5bb
change server db to session db that handles session auth
minump Aug 4, 2025
90f94ed
changed to sessiondb
minump Aug 5, 2025
1866715
rctdb schema and connection
minump Aug 5, 2025
270b0fe
rctdb routes
minump Aug 5, 2025
be92b40
drizzle test
minump Aug 5, 2025
11b7945
use nodeenv in dockerfile
minump Aug 5, 2025
ff12d77
readme for rctdb server side
minump Aug 5, 2025
0813947
setuser in topBar
minump Aug 5, 2025
ba8f71c
rctdb axios client
minump Aug 5, 2025
e676bdd
Merge branch 'main' into 89-read-from-postgres-db-drizzle
minump Aug 7, 2025
d9c6387
update version
minump Aug 7, 2025
9f7614e
update package-lock with npm i
minump Aug 7, 2025
0d394ca
changes to schema and dbqueries
minump Aug 13, 2025
f759b38
schema changes
minump Aug 21, 2025
1a706a3
update table
minump Aug 21, 2025
6dd0c42
schema changes
minump Aug 23, 2025
93a1a3a
parameter username when submitting for extraction
minump Aug 25, 2025
cc3142c
rctdbclient export function
minump Aug 26, 2025
26e3895
more queries and routes for rctdbclient
minump Aug 26, 2025
9e8cd79
add axios in server packagejson
minump Aug 26, 2025
cf20b01
db drizzle migration and db testing on server app start
minump Aug 26, 2025
fd404af
change in schema
minump Aug 26, 2025
a241dcf
remove old schema file
minump Aug 26, 2025
d2f0ea6
rctdb queries and routes
minump Aug 26, 2025
3e2290d
client side actions
minump Aug 26, 2025
10d12b3
minor changes
minump Aug 26, 2025
98550a1
make checklist formatted json from db records
minump Aug 26, 2025
09f0cd6
ignore random output files
minump Aug 26, 2025
9e66389
Merge branch 'main' into 89-read-from-postgres-db-drizzle
minump Sep 4, 2025
f138ffc
removed from readme
minump Sep 4, 2025
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ yarn-error.log*
# data folder
/data


# random files
**/*.pdf
**/*.json
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "consort-frontend",
"version": "0.15.0",
"version": "0.17.0",
"description": "",
"engines": {
"npm": ">=10",
Expand All @@ -25,11 +25,13 @@
"lint:fix": "npm run lint -- --fix",
"codegen": "./node_modules/.bin/openapi -i https://consort.clowderframework.org/clowder/swagger -o src/openapi/v1",
"codegen:dev": "./node_modules/.bin/openapi -i {CLOWDER_REMOTE_HOSTNAME}/swagger -o src/openapi/v1",
"docs": "typedoc"
"docs": "typedoc",
"rctdb:examples": "babel-node src/utils/rctdb-client-example.js"
},
"author": "NCSA",
"dependencies": {
"@allenai/pdf-components": "^1.0.1",
"axios": "^1.6.0",
"@emotion/react": "^11.7.1",
"@emotion/styled": "^11.6.0",
"@material-ui/core": "^4.12.3",
Expand Down
11 changes: 11 additions & 0 deletions server/.templateenv
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
# Database Configuration
PGSERVER='localhost'
PGPORT=5432
PGUSER=postgres
PGPASSWORD=postgres
PGDATABASE=consort
PGSSL=false

# Authentication Configuration
CILOGON_CLIENT_ID=
CILOGON_CLIENT_SECRET=
CILOGON_CALLBACK_URL=''
UI_URL=

# Clowder Configuration
CLOWDER_PREFIX=''
CLOWDER_REMOTE_HOSTNAME=
APIKEY=
166 changes: 166 additions & 0 deletions server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# CONSORT Server with Drizzle ORM

This server uses Drizzle ORM with PostgreSQL to manage the CONSORT database schema.

## Setup

### 1. Environment Configuration

Copy the template environment file and configure your database settings:

```bash
cp .templateenv .env
```

Update the database configuration in `.env`:

```env
# Database Configuration
PGSERVER='localhost'
PGPORT=5432
PGUSER=postgres
PGPASSWORD=strong_password_here
PGDATABASE=consort
PGSSL=false
```

### 2. Database Setup

Make sure you have PostgreSQL running and create the database:

```sql
CREATE DATABASE consort;
```

### 3. Install Dependencies

If you need drizzle-kit for advanced features:

```bash
npm install drizzle-kit
```

### 4. Run Database Migration

Initialize the database with the schema:

```bash
npm run db:migrate
```

### 5. Test Database Connection

```bash
npm run db:test
```

### 6. Check Database Health

```bash
npm run db:health
```

## Usage

### Starting the Server

```bash
npm start
```

### Running Examples

To see the database operations in action:

```bash
npm run db:examples
```

### API Endpoints

The server provides the following API endpoints:

#### Users
- `GET /api/users` - Get all users
- `POST /api/users` - Create a new user
- `GET /api/users/:uuid` - Get user by UUID

#### Publications
- `GET /api/publications` - Get all publications with user info
- `POST /api/publications` - Create a new publication
- `GET /api/publications/:uuid` - Get publication by UUID
- `GET /api/publications/:uuid/annotations` - Get annotations for a publication

#### Annotations
- `POST /api/annotations` - Create a new annotation
- `PUT /api/annotations/:uuid` - Update an annotation

#### Feedback
- `POST /api/feedback` - Create feedback for an annotation
- `GET /api/annotations/:uuid/feedback` - Get feedback for an annotation

#### Health Check
- `GET /api/health` - Check database connection status

## Database Schema

The database schema includes the following tables:

- **users** - User information
- **publication** - Research publications/papers
- **section** - Document sections
- **sentence** - Individual sentences with coordinates
- **annotation** - ML annotations for sentences
- **annotationfeedback** - User feedback on annotations
- **statement_section** - CONSORT/SPIRIT statement sections
- **statement_topic** - CONSORT/SPIRIT statement topics

## File Structure

```
server/
├── db/
│ ├── schema.js # Drizzle ORM schema definitions
│ ├── connection.js # Database connection setup
│ ├── queries.js # Common database queries
│ ├── migrate.js # Database migration script
│ └── examples.js # Usage examples
├── routes/
│ ├── api.js # API routes using Drizzle ORM
│ ├── auth.js # Authentication routes
│ └── index.js # Main routes
├── drizzle.config.js # Drizzle configuration
```

## Development

### Query Operations

Use the pre-built query functions from `db/queries.js`:

```javascript
const { userQueries, publicationQueries } = require('./db/queries');

// Create a user
const user = await userQueries.createUser({
name: 'John Doe',
email: 'john@example.com',
role: 'researcher'
});

// Get publications by user
const publications = await publicationQueries.getPublicationsByUser(userUuid);
```

### Direct Database Access

For custom queries, use the database instance:

```javascript
const { db } = require('./db/connection');
const { users } = require('./db/schema');
const { eq } = require('drizzle-orm');

const result = await db.select().from(users).where(eq(users.email, 'test@example.com'));
```

42 changes: 41 additions & 1 deletion server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,39 @@ var SQLiteStore = require('connect-sqlite3')(session);

var indexRouter = require('./routes/index');
var authRouter = require('./routes/auth');
var rctdbRouter = require('./routes/rctdb');

// Import database connection and migration functions
var { rctdbTestConnection } = require('./rctdb/connection');
var { rctdbMigrate } = require('./rctdb/migrate');

var app = express();

// Database initialization function
async function initializeDatabase() {
try {
console.log('🔍 Testing database connection...');
const isConnected = await rctdbTestConnection();

if (!isConnected) {
throw new Error('Database connection failed');
}

console.log('🚀 Running database migrations...');
await rctdbMigrate();
console.log('✅ Database initialized successfully');

} catch (error) {
console.error('❌ Database initialization failed:', error.message);
console.error('Application will continue but database features may not work properly');
// Don't exit the process - let the app start even if DB fails
// This allows for graceful degradation
}
}

// Initialize database on startup
initializeDatabase();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
Expand All @@ -39,7 +69,13 @@ app.use(session({
saveUninitialized: false, // don't create session until something stored
store: new SQLiteStore({ db: 'sessions.db', dir: './var/db' })
}));
app.use(csrf());
// Apply CSRF protection to all routes except API routes
app.use((req, res, next) => {
if (req.path.startsWith('/api/rctdb')) {
return next();
}
return csrf()(req, res, next);
});
app.use(passport.authenticate('session'));
app.use(function(req, res, next) {
var msgs = req.session.messages || [];
Expand All @@ -49,13 +85,17 @@ app.use(function(req, res, next) {
next();
});
app.use(function(req, res, next) {
if (req.path.startsWith('/api/rctdb')) {
return next();
}
res.locals.csrfToken = req.csrfToken();
next();
});

//const baseUrl = process.env.BASE_URL;
app.use('/', indexRouter);
app.use('/', authRouter);
app.use('/api/rctdb', rctdbRouter);

// redirect any other route back to home route /
// app.use((req,res,next)=>{
Expand Down
19 changes: 19 additions & 0 deletions server/drizzle.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require('dotenv').config();

module.exports = {
schema: './rctdb/schema.js',
out: './drizzle',
dialect: 'postgresql',
dbCredentials: {
host: process.env.PGSERVER || 'localhost',
port: process.env.PGPORT || 5432,
user: process.env.PGUSER || 'postgres',
password: process.env.PGPASSWORD,
database: process.env.PGDATABASE || 'consort',
ssl: process.env.PGSSL === 'true' ? { rejectUnauthorized: false } : false,
},
migrations: {
table: 'drizzle_migrations',
schema: 'public'
}
};
Loading