Automatic create new Postgre DB

  1. 12 months ago

    I would like to know if I can dynamically create a new PostGreeSQL database direct from Xojo.

    I'm new in Xojo, and my idea is to create one database by company; like:

    Company 1 --> DATABASE1
    Company 2 --> DATABASE2
    ...
    Company n --> DATABASEn

    Is this possible?

  2. Kem T

    29 Oct 2018 Pre-Release Testers, Xojo Pro, XDC Speakers Connecticut

    Not directly, but you can use the Shell to do this using the command line tools that come with PostgreSQL.

    But reconsider this. If you are using the same database structure in a central database, you are better off combining all the data into one database and limiting access to each company. Potentially, you can use Row Level Security to make this transparent.

    Otherwise, every time you make a change to the db structure, you will have to apply it to every copy of the database.

  3. Jay M

    29 Oct 2018 Pre-Release Testers, Xojo Pro NC, USA

    @Kem T Not directly

    Actually, you can: Create Database . But, you have to be connected as a superuser, which could have some security implications (hopefully you're not normally using a superuser for connecting from Xojo - you should be using an appropriately limited user for each database).

    But, as Kem points out, you need to consider the cost of structure changes. But, if this is really the direction you need to take, you do get the benefit of optionally basing the new database on a template db that you have created.

  4. Kem T

    29 Oct 2018 Pre-Release Testers, Xojo Pro, XDC Speakers Connecticut

    Jay, I'm not by my machine to check myself. Are you sure that's available in PostreSQL?

  5. Jay M

    29 Oct 2018 Pre-Release Testers, Xojo Pro NC, USA

    Yes, I linked to the docs that shows the SQL command. In fact, it states that the command line tool createdb is just a wrapper for this SQL command.

  6. Tim P

    29 Oct 2018 Pre-Release Testers Rochester, NY

    Have a like for linking to documentation!

  7. Kem T

    29 Oct 2018 Pre-Release Testers, Xojo Pro, XDC Speakers Connecticut

    Ah, I see. Thanks.

or Sign Up to reply!