spotters: activity (per-country score) and seen (collection) tables for cars, planes, trains, wildlife
All checks were successful
Deploy production / deploy (push) Successful in 1m7s

This commit is contained in:
2026-10-25 13:09:02 +00:00
parent 85c6f89e36
commit f86c8ef294
6 changed files with 26384 additions and 4 deletions

View File

@@ -8,7 +8,9 @@ import {
smallint,
text,
timestamp,
uniqueIndex
uniqueIndex,
date,
primaryKey
} from 'drizzle-orm/pg-core';
import { carsSchema } from './schemas';
import { id, timestamps } from './helpers';
@@ -178,3 +180,34 @@ export const carPhotos = carsSchema.table(
},
(t) => [uniqueIndex('photos_model_position_key').on(t.modelId, t.position)]
);
/**
* How active each entry is per country or region (scripts/spotters-activity.ts), so the
* dex can be sorted by "most active in NL / Germany / Europe ..." without live joins.
* `area` is a lowercase ISO 3166-1 alpha-2 code ("nl") or a region code ("europe",
* see src/lib/spotting/areas.ts). Missing row = no known activity there.
*/
export const carActivity = carsSchema.table(
'activity',
{
modelId: integer('model_id')
.notNull()
.references(() => carModels.id, { onDelete: 'cascade' }),
area: text('area').notNull(),
score: real('score').notNull()
},
(t) => [
primaryKey({ columns: [t.area, t.modelId] }),
index('activity_area_score_idx').on(t.area, t.score)
]
);
/** Stan's collection: entries he has seen / collected (owner-only writes, public reads). */
export const carSeen = carsSchema.table('seen', {
modelId: integer('model_id')
.primaryKey()
.references(() => carModels.id, { onDelete: 'cascade' }),
seenOn: date('seen_on'),
note: text('note'),
...timestamps
});

View File

@@ -8,7 +8,9 @@ import {
text,
timestamp,
uniqueIndex,
type AnyPgColumn
type AnyPgColumn,
date,
primaryKey
} from 'drizzle-orm/pg-core';
import { planesSchema } from './schemas';
import { id, timestamps } from './helpers';
@@ -155,3 +157,34 @@ export const planePhotos = planesSchema.table(
},
(t) => [uniqueIndex('photos_type_position_key').on(t.typeId, t.position)]
);
/**
* How active each entry is per country or region (scripts/spotters-activity.ts), so the
* dex can be sorted by "most active in NL / Germany / Europe ..." without live joins.
* `area` is a lowercase ISO 3166-1 alpha-2 code ("nl") or a region code ("europe",
* see src/lib/spotting/areas.ts). Missing row = no known activity there.
*/
export const planeActivity = planesSchema.table(
'activity',
{
typeId: integer('type_id')
.notNull()
.references(() => planeTypes.id, { onDelete: 'cascade' }),
area: text('area').notNull(),
score: real('score').notNull()
},
(t) => [
primaryKey({ columns: [t.area, t.typeId] }),
index('activity_area_score_idx').on(t.area, t.score)
]
);
/** Stan's collection: entries he has seen / collected (owner-only writes, public reads). */
export const planeSeen = planesSchema.table('seen', {
typeId: integer('type_id')
.primaryKey()
.references(() => planeTypes.id, { onDelete: 'cascade' }),
seenOn: date('seen_on'),
note: text('note'),
...timestamps
});

View File

@@ -9,7 +9,8 @@ import {
text,
timestamp,
uniqueIndex,
type AnyPgColumn
type AnyPgColumn,
date
} from 'drizzle-orm/pg-core';
import { trainsSchema } from './schemas';
import { id, timestamps } from './helpers';
@@ -185,3 +186,34 @@ export const trainPhotos = trainsSchema.table(
},
(t) => [uniqueIndex('photos_type_position_key').on(t.typeId, t.position)]
);
/**
* How active each entry is per country or region (scripts/spotters-activity.ts), so the
* dex can be sorted by "most active in NL / Germany / Europe ..." without live joins.
* `area` is a lowercase ISO 3166-1 alpha-2 code ("nl") or a region code ("europe",
* see src/lib/spotting/areas.ts). Missing row = no known activity there.
*/
export const trainActivity = trainsSchema.table(
'activity',
{
typeId: integer('type_id')
.notNull()
.references(() => trainTypes.id, { onDelete: 'cascade' }),
area: text('area').notNull(),
score: real('score').notNull()
},
(t) => [
primaryKey({ columns: [t.area, t.typeId] }),
index('activity_area_score_idx').on(t.area, t.score)
]
);
/** Stan's collection: entries he has seen / collected (owner-only writes, public reads). */
export const trainSeen = trainsSchema.table('seen', {
typeId: integer('type_id')
.primaryKey()
.references(() => trainTypes.id, { onDelete: 'cascade' }),
seenOn: date('seen_on'),
note: text('note'),
...timestamps
});

View File

@@ -7,7 +7,9 @@ import {
smallint,
text,
timestamp,
uniqueIndex
uniqueIndex,
date,
primaryKey
} from 'drizzle-orm/pg-core';
import { wildlifeSchema } from './schemas';
import { id, timestamps } from './helpers';
@@ -133,3 +135,34 @@ export const wildlifePhotos = wildlifeSchema.table(
uniqueIndex('photos_species_photo_key').on(t.speciesId, t.photoId)
]
);
/**
* How active each entry is per country or region (scripts/spotters-activity.ts), so the
* dex can be sorted by "most active in NL / Germany / Europe ..." without live joins.
* `area` is a lowercase ISO 3166-1 alpha-2 code ("nl") or a region code ("europe",
* see src/lib/spotting/areas.ts). Missing row = no known activity there.
*/
export const wildlifeActivity = wildlifeSchema.table(
'activity',
{
speciesId: integer('species_id')
.notNull()
.references(() => wildlifeSpecies.id, { onDelete: 'cascade' }),
area: text('area').notNull(),
score: real('score').notNull()
},
(t) => [
primaryKey({ columns: [t.area, t.speciesId] }),
index('activity_area_score_idx').on(t.area, t.score)
]
);
/** Stan's collection: entries he has seen / collected (owner-only writes, public reads). */
export const wildlifeSeen = wildlifeSchema.table('seen', {
speciesId: integer('species_id')
.primaryKey()
.references(() => wildlifeSpecies.id, { onDelete: 'cascade' }),
seenOn: date('seen_on'),
note: text('note'),
...timestamps
});