Skip to content

Commit

Permalink
N21-1029 renaming of collections (#4547)
Browse files Browse the repository at this point in the history
* renames some collections:
user_login_migrations  -> user-login-migrations
external_tools -> external-tools
context_external_tools -> context-external-tools
school_external_tools -> school-external-tools
  • Loading branch information
arnegns authored Nov 10, 2023
1 parent 4a7cb71 commit a407c71
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ data:
}'

# Add Bettermarks' tools configuration as an external tool
# (stored in the 'external_tools' collection) that uses OAuth.
mongosh $DATABASE__URL --eval 'db.external_tools.replaceOne(
# (stored in the 'external-tools' collection) that uses OAuth.
mongosh $DATABASE__URL --eval 'db.external-tools.replaceOne(
{
"name": "bettermarks",
"config_type": "oauth2"
Expand Down Expand Up @@ -486,9 +486,9 @@ data:
echo "POSTed nextcloud to hydra."

# Add Nextcloud' tools configuration as an external tool
# (stored in the 'external_tools' collection) that uses OAuth.
echo "Inserting nextcloud to external_tools..."
mongosh $DATABASE__URL --eval 'db.external_tools.update(
# (stored in the 'external-tools' collection) that uses OAuth.
echo "Inserting nextcloud to external-tools..."
mongosh $DATABASE__URL --eval 'db.external-tools.update(
{
"name": "nextcloud",
"config_type": "oauth2"
Expand All @@ -512,7 +512,7 @@ data:
"upsert": true
}
);'
echo "Inserted nextcloud to external_tools."
echo "Inserted nextcloud to external-tools."

echo "Nextcloud config data init performed successfully."
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export enum AuthorizableReferenceType {
'Lesson' = 'lessons',
'Team' = 'teams',
'Submission' = 'submissions',
'SchoolExternalToolEntity' = 'school_external_tools',
'SchoolExternalToolEntity' = 'school-external-tools',
'BoardNode' = 'boardnodes',
'ContextExternalToolEntity' = 'context_external_tools',
'ContextExternalToolEntity' = 'context-external-tools',
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface IContextExternalToolProperties {
toolVersion: number;
}

@Entity({ tableName: 'context_external_tools' })
@Entity({ tableName: 'context-external-tools' })
export class ContextExternalToolEntity extends BaseEntityWithTimestamps {
@ManyToOne()
schoolTool: SchoolExternalToolEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { BasicToolConfigEntity, Lti11ToolConfigEntity, Oauth2ToolConfigEntity }

export type IExternalToolProperties = Readonly<Omit<ExternalToolEntity, keyof BaseEntityWithTimestamps>>;

@Entity({ tableName: 'external_tools' })
@Entity({ tableName: 'external-tools' })
export class ExternalToolEntity extends BaseEntityWithTimestamps {
@Unique()
@Property()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface ISchoolExternalToolProperties {
toolVersion: number;
}

@Entity({ tableName: 'school_external_tools' })
@Entity({ tableName: 'school-external-tools' })
export class SchoolExternalToolEntity extends BaseEntityWithTimestamps {
@ManyToOne()
tool: ExternalToolEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BaseEntityWithTimestamps } from './base.entity';

export type IUserLoginMigration = Readonly<Omit<UserLoginMigrationEntity, keyof BaseEntityWithTimestamps>>;

@Entity({ tableName: 'user_login_migrations' })
@Entity({ tableName: 'user-login-migrations' })
export class UserLoginMigrationEntity extends BaseEntityWithTimestamps {
@OneToOne(() => SchoolEntity, undefined, { nullable: false })
school: SchoolEntity;
Expand Down
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions backup/setup/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -339,5 +339,16 @@
"$date": "2023-10-26T13:06:27.322Z"
},
"__v": 0
},
{
"_id": {
"$oid": "654cc2326b83f786c4227b21"
},
"state": "up",
"name": "tool-and-user-login-migration-renamings",
"createdAt": {
"$date": "2023-11-09T11:27:46.062Z"
},
"__v": 0
}
]
File renamed without changes.
1 change: 1 addition & 0 deletions backup/setup/user-login-migrations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const mongoose = require('mongoose');
const { info, error } = require('../src/logger');

const { connect, close } = require('../src/utils/database');

async function renameCollection(oldName, newName) {
try {
await mongoose.connection.collection(oldName).rename(newName);
info(`Renamed collection ${oldName} to ${newName}`);
} catch (err) {
error(`Error renaming collection ${oldName} to ${newName}: ${err.message}`);
throw err;
}
}

module.exports = {
up: async function up() {
await connect();

await renameCollection('user_login_migrations', 'user-login-migrations');

await renameCollection('external_tools', 'external-tools');

await renameCollection('context_external_tools', 'context-external-tools');

await renameCollection('school_external_tools', 'school-external-tools');

await close();
},

down: async function down() {
await connect();

await renameCollection('user-login-migrations', 'user_login_migrations');

await renameCollection('external-tools', 'external_tools');

await renameCollection('context-external-tools', 'context_external_tools');

await renameCollection('school-external-tools', 'school_external_tools');

await close();
},
};
2 changes: 1 addition & 1 deletion src/services/school/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ const gradeLevelSchema = new Schema({
});

const schoolModel = mongoose.model('school', schoolSchema);
const userLoginMigrationModel = mongoose.model('userLoginMigration', userLoginMigrationSchema, 'user_login_migrations');
const userLoginMigrationModel = mongoose.model('userLoginMigration', userLoginMigrationSchema, 'user-login-migrations');
const schoolGroupModel = mongoose.model('schoolGroup', schoolGroupSchema);
const yearModel = mongoose.model('year', yearSchema);
const gradeLevelModel = mongoose.model('gradeLevel', gradeLevelSchema);
Expand Down

0 comments on commit a407c71

Please sign in to comment.