mirror of
https://github.com/jcreek/LivingDexTracker.git
synced 2026-07-13 02:53:45 +00:00
feat(*): Complete MongoDB to Supabase migration cleanup
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
import mongoose, { Schema, Document } from 'mongoose';
|
||||
|
||||
export interface PokedexMetadata extends Document {
|
||||
lastModified: Date;
|
||||
}
|
||||
|
||||
const pokedexMetadataSchema = new Schema<PokedexMetadata>({
|
||||
lastModified: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
}
|
||||
});
|
||||
|
||||
export default mongoose.model<PokedexMetadata>('PokedexMetadata', pokedexMetadataSchema);
|
||||
@@ -1,13 +1,13 @@
|
||||
import mongoose, { Schema, Document } from 'mongoose';
|
||||
|
||||
export interface RegionGameMapping extends Document {
|
||||
// Supabase-based RegionGameMapping interface
|
||||
export interface RegionGameMapping {
|
||||
id?: number;
|
||||
region: string;
|
||||
games: string[];
|
||||
game: string; // Note: Different from MongoDB version which had 'games' array
|
||||
}
|
||||
|
||||
const regionGameMappingSchema = new Schema<RegionGameMapping>({
|
||||
region: String,
|
||||
games: Array<string>
|
||||
});
|
||||
|
||||
export default mongoose.model<RegionGameMapping>('RegionGameMapping', regionGameMappingSchema);
|
||||
// Database record type for Supabase
|
||||
export interface RegionGameMappingDB {
|
||||
id: number;
|
||||
region: string;
|
||||
game: string;
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
import mongoose, { Schema, Document } from 'mongoose';
|
||||
|
||||
export interface User extends Document {
|
||||
username: string;
|
||||
// Add other user-related fields as needed
|
||||
}
|
||||
|
||||
const userSchema = new Schema<User>({
|
||||
username: String
|
||||
// Add other user-related fields as needed
|
||||
});
|
||||
|
||||
export default mongoose.model<User>('User', userSchema);
|
||||
@@ -1,19 +0,0 @@
|
||||
import mongoose, { Schema, Document } from 'mongoose';
|
||||
|
||||
export interface UserCatchEntry extends Document {
|
||||
userId: mongoose.Types.ObjectId; // Reference to the user
|
||||
pokedexEntryId: mongoose.Types.ObjectId; // Reference to the pokedex entry
|
||||
haveToEvolve: boolean;
|
||||
caught: boolean;
|
||||
inHome: boolean;
|
||||
}
|
||||
|
||||
const userCatchEntrySchema = new Schema<UserCatchEntry>({
|
||||
userId: { type: mongoose.Types.ObjectId, ref: 'User' },
|
||||
pokedexEntryId: { type: mongoose.Types.ObjectId, ref: 'PokedexEntry' },
|
||||
haveToEvolve: Boolean,
|
||||
caught: Boolean,
|
||||
inHome: Boolean
|
||||
});
|
||||
|
||||
export default mongoose.model<UserCatchEntry>('UserCatchEntry', userCatchEntrySchema);
|
||||
@@ -1,48 +0,0 @@
|
||||
import mongoose from 'mongoose';
|
||||
import { getEnv } from '$lib/utils/env';
|
||||
const env = getEnv();
|
||||
|
||||
/*
|
||||
0 - disconnected
|
||||
1 - connected
|
||||
2 - connecting
|
||||
3 - disconnecting
|
||||
4 - uninitialized
|
||||
*/
|
||||
let mongoConnectionState = 0;
|
||||
|
||||
export const dbConnect = async () => {
|
||||
if (mongoConnectionState === 1) {
|
||||
console.log('Connection already established');
|
||||
return;
|
||||
}
|
||||
|
||||
if (mongoose.connections.length > 0) {
|
||||
mongoConnectionState = mongoose.connections[0].readyState;
|
||||
if (mongoConnectionState === 1) {
|
||||
console.log('Using existing connection');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
await mongoose.connect(env.MONGO_URL, {
|
||||
serverApi: { version: '1', strict: true, deprecationErrors: true }
|
||||
});
|
||||
await mongoose.connection.db.admin().command({ ping: 1 });
|
||||
console.log('Pinged your deployment. You successfully connected to MongoDB!');
|
||||
mongoConnectionState = 1;
|
||||
} catch (error) {
|
||||
console.error('Error connecting to MongoDB:', error);
|
||||
mongoConnectionState = 0;
|
||||
}
|
||||
};
|
||||
|
||||
export const dbDisconnect = async () => {
|
||||
if (process.env.NODE_ENV === 'development') return;
|
||||
if (mongoConnectionState === 0) return;
|
||||
|
||||
await mongoose.disconnect();
|
||||
mongoConnectionState = 0;
|
||||
console.log('disconnected from mongodb');
|
||||
};
|
||||
@@ -1,7 +1,3 @@
|
||||
export function getEnv() {
|
||||
return process.env.hasOwnProperty('MONGO_URL')
|
||||
? process.env
|
||||
: {
|
||||
MONGO_URL: import.meta.env.VITE_MONGO_URL
|
||||
};
|
||||
return process.env;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user