How to Create New Database, Namespace and Web Application for InterSystems IRIS programmatically

Here is an ObjectScript snippet which lets to create database, namespace and a web application for InterSystems IRIS:

    set currentNS = $namespace

    zn "%SYS"

    write "Create DB ...",!
    set dbName="testDB"
    set dbProperties("Directory") = "/InterSystems/IRIS/mgr/testDB"
    set status=##Class(Config.Databases).Create(dbName,.dbProperties)
    write:'status $system.Status.DisplayError(status)
    write "DB """_dbName_""" was created!",!!


    write "Create namespace ...",!
    set nsName="testNS"
    //DB for globals
    set nsProperties("Globals") = dbName
    //DB for routines
    set nsProperties("Routines") = dbName
    set status=##Class(Config.Namespaces).Create(nsName,.nsProperties)
    write:'status $system.Status.DisplayError(status)
    write "Namespace """_nsName_""" was created!",!!


    write "Create web application ...",!
    set webName = "/csp/testApplication"
    set webProperties("NameSpace") = nsName
    set webProperties("Enabled") = $$$YES
    set webProperties("IsNameSpaceDefault") = $$$YES
    set webProperties("CSPZENEnabled") = $$$YES
    set webProperties("DeepSeeEnabled") = $$$YES
    set webProperties("AutheEnabled") = $$$AutheCache
    set status = ##class(Security.Applications).Create(webName, .webProperties)
    write:'status $system.Status.DisplayError(status)
    write "Web application """webName""" was created!",!

    zn currentNS

Also check these manuals:

Comments

Thank you!  It's great having all 3 examples in one place :)

Just a quick note.

I found that when creating a new database it was best to initially use SYS.Database so you can specifiy max size etc..

db=##class(SYS.Database).%New()
db.Directory=directory
db.Size=initialSize
db.MaxSize=maxSize
db.GlobalJournalState=3
Status=db.%Save()

Then finalise with Config.Database

Properties("Directory")=directory
Status=##Class(Config.Databases).Create(name,.Properties)
Obj=##Class(Config.Databases).Open(name)
Obj.MountRequired=1
Status=Obj.%Save()

This might not be the best way to do it, I'm open to improvements.