abstract class Moongoon::Database::Scripts::Base
- Moongoon::Database::Scripts::Base
- Reference
- Object
Overview
Scripts inherit from this class.
Example
class Moongoon::Database::Scripts::Test < Moongoon::Database::Scripts::Base
# Scripts run in ascending order.
# Default order if not specified is 1.
order Time.utc(2020, 3, 11).to_unix
# Use :retry to retry the script next time moongoon connects if the script raises.
on_error :discard
def process(db : Mongo::Database)
# Dummy code that will add a ban flag for users that are called 'John'.
# This code uses the `cryomongo` syntax, but Models could
# be used for convenience despite a performance overhead.
db["users"].update_many(
filter: {name: "John"},
update: {"$set": {"banned": true}},
)
end
end
Usage
Any class that inherits from Moongoon::Database::Scripts::Base
will be registered as a script.
Scripts are run when calling Moongoon::Database.connect
and after a successful database connection.
They are run a single time and the outcome is be written in the scripts
collection.
If multiple instances of the server are started simultaneously they will wait until all the scripts are processed before resuming execution.
Defined in:
Class Method Summary
-
.on_error : Action
The action to perform on failure.
-
.on_error=(on_error : Action)
The action to perform on failure.
-
.on_success : Action
The action to perform on success.
-
.on_success=(on_success : Action)
The action to perform on success.
-
.order : Int64
The order in which the scripts are run.
-
.order=(order : Int64)
The order in which the scripts are run.
Instance Method Summary
-
#process(db : Mongo::Database)
Will be executed once after a successful database connection and if it has never been run against the target database before.
Class Method Detail
The action to perform on failure. Set to :retry to run the script again the next time the program starts.
The action to perform on failure. Set to :retry to run the script again the next time the program starts.
The action to perform on success. Set to :retry to run the script again the next time the program starts.
The action to perform on success. Set to :retry to run the script again the next time the program starts.
Instance Method Detail
Will be executed once after a successful database connection and if it has never been run against the target database before.