-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit-mongo.js
More file actions
167 lines (159 loc) · 5.12 KB
/
init-mongo.js
File metadata and controls
167 lines (159 loc) · 5.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// MongoDB initialization script for RMU Attack API
// This script creates the necessary database and collections
// Switch to the application database
db = db.getSiblingDB('rmu-attacks');
// Create collections with validation
db.createCollection('attacks', {
validator: {
$jsonSchema: {
bsonType: 'object',
required: ['actionId', 'sourceId', 'targetId', 'status', 'modifiers'],
properties: {
actionId: {
bsonType: 'string',
description: 'Action ID is required and must be a string'
},
sourceId: {
bsonType: 'string',
description: 'Source ID is required and must be a string'
},
targetId: {
bsonType: 'string',
description: 'Target ID is required and must be a string'
},
status: {
bsonType: 'string',
enum: ['draft', 'ready_to_roll', 'ready_to_critical_roll', 'calculated', 'applied', 'failed'],
description: 'Status must be one of the valid enum values'
},
modifiers: {
bsonType: 'object',
required: ['attackType', 'rollModifiers'],
properties: {
attackType: {
bsonType: 'string',
enum: ['melee', 'ranged'],
description: 'Attack type must be melee or ranged'
},
rollModifiers: {
bsonType: 'object',
description: 'Roll modifiers object'
}
}
},
roll: {
bsonType: ['object', 'null'],
description: 'Roll information, can be null'
},
results: {
bsonType: ['object', 'null'],
description: 'Attack results, can be null'
}
}
}
}
});
db.createCollection('criticals', {
validator: {
$jsonSchema: {
bsonType: 'object',
required: ['type', 'roll', 'result', 'status'],
properties: {
type: {
bsonType: 'string',
description: 'Critical type is required'
},
roll: {
bsonType: 'int',
minimum: 1,
maximum: 100,
description: 'Roll must be between 1 and 100'
},
result: {
bsonType: 'string',
description: 'Result description is required'
},
status: {
bsonType: 'string',
enum: ['pending', 'applied', 'cancelled'],
description: 'Status must be one of the valid enum values'
}
}
}
}
});
// Create indexes for better performance
db.attacks.createIndex({ actionId: 1 });
db.attacks.createIndex({ sourceId: 1 });
db.attacks.createIndex({ targetId: 1 });
db.attacks.createIndex({ status: 1 });
db.attacks.createIndex({ actionId: 1, sourceId: 1, targetId: 1 });
db.criticals.createIndex({ type: 1 });
db.criticals.createIndex({ status: 1 });
// Insert sample data for development/testing
db.attacks.insertMany([
{
actionId: 'action_001',
sourceId: 'character_001',
targetId: 'enemy_001',
status: 'draft',
modifiers: {
attackType: 'melee',
rollModifiers: {
bo: 10,
boInjuryPenalty: 0,
boActionsPointsPenalty: 0,
boPacePenalty: 0,
boFatiguePenalty: 0,
bd: 5,
rangePenalty: 0,
parry: 0,
customBonus: 0
}
},
roll: null,
results: null
},
{
actionId: 'action_002',
sourceId: 'character_002',
targetId: 'enemy_002',
status: 'calculated',
modifiers: {
attackType: 'ranged',
rollModifiers: {
bo: 15,
boInjuryPenalty: -2,
boActionsPointsPenalty: 0,
boPacePenalty: 0,
boFatiguePenalty: -1,
bd: 8,
rangePenalty: -5,
parry: 0,
customBonus: 2
}
},
roll: {
roll: 85
},
results: null
}
]);
db.criticals.insertMany([
{
type: 'A',
roll: 15,
result: 'Minor wound to arm',
status: 'pending'
},
{
type: 'B',
roll: 45,
result: 'Moderate wound to chest',
status: 'applied'
}
]);
print('MongoDB initialization completed successfully!');
print('Collections created: attacks, criticals');
print('Indexes created for optimal performance');
print('Sample data inserted for development');