Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Multi-Tenant App -- Duplicating DB structure

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Multi-Tenant App -- Duplicating DB structure

    Web app using 7295.

    I've built a multi-tenant app where each user has their own database. I'm wanting to automate the creation of new databases via a sign up screen. I'm trying to write a stored procedure (that resides in a "control" database) that will create the new database, it's tables, functions, triggers, stored procedures, etc. Getting the syntax correct and dealing with all of the escaping of single quotes has become a nightmare.

    Any one here running a multi-tenant app with multi databases? How are you handing the creation of these databases when a new user signs up?

    In the mean time I have a script that SSMS created for me that runs fine. I just rather have this automated.
    Last edited by mikeallenbrown; 06-18-2021, 02:52 PM. Reason: Updated info.
    Mike Brown - Contact Me
    Programmatic Technologies, LLC
    Programmatic-Technologies.com
    Independent Developer & Consultant​​

    #2
    multi-tenant app uses just one database or it's not multi-tenanted, or am I misunderstanding what you are saying?

    Pete

    Insanity: doing the same thing over and over again and expecting different results.
    Albert Einstein, (attributed)
    US (German-born) physicist (1879 - 1955)

    Comment


      #3
      Originally posted by peteconway View Post
      multi-tenant app uses just one database or it's not multi-tenanted, or am I misunderstanding what you are saying?

      Pete


      From Alpha: https://documentation.alphasoftware....%20Strings.xml

      A multi-tenant application is an application that is shared by many different customers. Salesforce.com is a good example of a multi-tenant application. There are typically two different approaches to building a multi-tenant application. These are:
      • All tenants share the same database, but each table in the database has a 'tenantId' field which identifies the tenant. Every query that is executed includes the tenantId in the WHERE clause. The tentantId is set when the customer logs into the application.
      • Each tenant has its own database. -This is my approach

      The second approach is much easier to code because you don't have worry about adding the 'tenantId' field into every query and insert statement. However, it is less scalable because you need to provision a new database for every tenant.
      Mike Brown - Contact Me
      Programmatic Technologies, LLC
      Programmatic-Technologies.com
      Independent Developer & Consultant​​

      Comment


        #4
        Can't agree with that at all, I'd also say that would have been the view prior the 2018 DEVCON where I demonstrated a Mutl-tennant and Alpha the released a new MT Connection string to do the auto persistence of the TenantID. - Much easier without duplication.
        Just sayin. Pete
        Insanity: doing the same thing over and over again and expecting different results.
        Albert Einstein, (attributed)
        US (German-born) physicist (1879 - 1955)

        Comment


          #5
          In a multi-tenant app with multiple databases, any change to the database structure is going to have to be copied between multiple databases. You do NOT want to deal with that once enough different databases are created.

          Go with the idea of a tenant ID, whether you use Alpha's connection string method or just remember to include it yourself in your selections. (It may not apply to EVERY table, for instance a phone type table would not need different selections for every client.)

          Otherwise, if you insist on doing multiple databases, I would put the bulk of the create/copy code into a stored procedure on the master database. The wonderful thing about SQL is that it is ALL SQL. So all of the creation commands are also SQL and can be run in SQL.

          If a customer wants some truly custom code that would not translate well to any other client, you can hide that functionality from the other clients by tenant ID or you could create a secondary database for them that holds just their custom tables.

          Comment


            #6
            I would suggest that as long as we have strtran and your dbs are accessible under one connections, making the changes should be a minimal effort.
            The code below demonstrates a simple script that creates 3 tables, then alters each table to add a column as well as primary key.
            Knowing there is potential for many more than 3 tables, this could easily be adjusted to make tableList dynamc.
            This script does assume mySQL or mariaDB as the backend. It also assumes a connection named mylab.
            Code:
            dim namedCN as c = "::name::mylab"
            dim tableList as c
            dim sqlCode as p
            dim mtCN as sql::Connection
            dim mtRS as sql::ResultSet
            dim mtARGS as sql::Arguments
            dim itsOpen as l
            dim itWorked as l
            
            tableList = <<%txt%
            AALab.alphaa
            AALab.alphab
            AALab.alphac
            %txt%
            
            sqlCode.createTables = <<%txt%
            create table :tbl(
            firstname varchar(15),
            lastname varchar(30)
            );
            %txt%
            sqlCode.alterTables = <<%txt%
            alter table <tablename> add column seq int not null auto_increment primary key first;
            %txt%
            debug(1)
            itsOpen = mtCN.Open(namedCN)
            for each tbl in tableList
            sqlCode.use=strtran(sqlCode.createTables,":tbl",tbl.value)
            itWorked = mtCN.Execute(sqlCode.use,mtARGS)
            
            next 'tbl
            debug(1) ' check tables
            for each tbl in tableList
            sqlCode.use = strtran(sqlCode.alterTables,"<tablename>",tbl.value)
            itWorked = mtCN.Execute(sqlCode.use)
            next 'tbl
            mtCN.Close()
            
            debug(1)
            Gregg
            https://paiza.io is a great site to test and share sql code

            Comment


              #7
              If you are determined to use multiple databases, then I suggest you create a "master database" with all the tables, triggers, stored procedures, referential integrity, etc. Then when a new person signs up, you use a stored procedure to duplicate the master, not create it table by table.. I've used stored procedures to build tables and they are fast and accurate, but and entire database will be very hard to update and maintain.
              Pat Bremkamp
              MindKicks Consulting

              Comment


                #8
                Hi Mike, our clients require we have a separate database for their information so we have an automation routine we can share if you need it. Big picture, we run a stored procedure to create the new empty database and then another stored procedure that restores a backup of a master database to the new database. The backup of the master also has some pre-populated data to act as a 'sandbox' project for the new clients to review and get use to the system. The whole process which restores 632 tables and 747 views runs in under 10 seconds and is initiated from a ux button push. We have it set up so we can enter a short name for the new clients database and the database is built using that name by passing in an argumet to the stored procedures. You probably will not need this but we also automatically create and ODBC connection between mariadb and sql and then automatically create a linked server connection between the two using the odbc conneciton just created.

                Comment


                  #9
                  Originally posted by nxlcomputers View Post
                  Hi Mike, our clients require we have a separate database for their information so we have an automation routine we can share if you need it. Big picture, we run a stored procedure to create the new empty database and then another stored procedure that restores a backup of a master database to the new database. The backup of the master also has some pre-populated data to act as a 'sandbox' project for the new clients to review and get use to the system. The whole process which restores 632 tables and 747 views runs in under 10 seconds and is initiated from a ux button push. We have it set up so we can enter a short name for the new clients database and the database is built using that name by passing in an argumet to the stored procedures. You probably will not need this but we also automatically create and ODBC connection between mariadb and sql and then automatically create a linked server connection between the two using the odbc conneciton just created.
                  Thanks, I appreciate that. I came up with a more complicated process that I think will work but I'd be interested in your solution. If you don't mind you can email me at: <personal info removed>

                  Thank you.
                  Last edited by Lenny Forziati; 01-11-2022, 01:45 PM. Reason: personal info removed
                  Mike Brown - Contact Me
                  Programmatic Technologies, LLC
                  Programmatic-Technologies.com
                  Independent Developer & Consultant​​

                  Comment


                    #10
                    Hi Mike
                    But in your scenario, doesn't every new tenant need a different copy of your alpha anywhere project? Otherwise assuming it's just a matter of different connection strings for different tenants, how do you point each one to the correct connection string?

                    Jaime

                    Comment


                      #11
                      I've worked extensively on Multi Tenant stuff, and would suggest that a separate Db for each client will end up driving you nuts.
                      If a user has specific requirements for an application - away from your mainstream offering - they really need a separate application just for them.
                      If the aim is to provide a universal app which replicates the functionality and feature upgrades for everyone to enjoy, you are much better off using GUID's - captured at login - to select and display the data for that tenant.
                      In your current scenario, you have to select the Db from a login or IP address or a similar process. Selecting data based on the login is no more difficult and as has been said, you don't need to update multiple Db's when you need another field or process.

                      I understand why you have done the development the way you have Mike, but in the long run, it is likely to be problematic and possibly unsustainable.
                      But that's just my opinion.
                      It may well work for you as you are deeply into it, but I would suggest a bit more research into MT Apps design.
                      See our Hybrid Option here;
                      https://hybridapps.example-software.com/


                      Apologies to anyone I haven't managed to upset yet.
                      You are held in a queue and I will get to you soon.

                      Comment


                        #12
                        We use the same workspace for all the clients but the publishing profile is unique and that's where the connection strings get updated. The negatives are that you have to publish changes to each IIS/Alpha site individually and like everyone is saying, you have to keep your databases in synch (structure). We use NaviCat to manipulate the databases and it has a 'structure synch' tool that we use as a backup method for monthly database compares. Our primary method is to route our database changes through our database admin and she uses scripts to push out the changes to each database simultaneously. We have a 'to-do' item this year to look for a tool to help with Alpha workspace production release automation. I remember a presentation at an Alpha DevCon a few years back that addressed this issue but for the life of me cannot remember the tool they used.

                        Comment


                          #13
                          Originally posted by WindForce View Post
                          Hi Mike
                          But in your scenario, doesn't every new tenant need a different copy of your alpha anywhere project? Otherwise assuming it's just a matter of different connection strings for different tenants, how do you point each one to the correct connection string?

                          Jaime
                          The application is the same for all tenants, however, unlike most apps each tenant gets their own database. Alpha's dynamic connection string method points the user to the correct database after login.

                          https://documentation.alphasoftware....%20Strings.xml
                          Mike Brown - Contact Me
                          Programmatic Technologies, LLC
                          Programmatic-Technologies.com
                          Independent Developer & Consultant​​

                          Comment


                            #14
                            Originally posted by Ted Giles View Post
                            I've worked extensively on Multi Tenant stuff, and would suggest that a separate Db for each client will end up driving you nuts.
                            If a user has specific requirements for an application - away from your mainstream offering - they really need a separate application just for them.
                            If the aim is to provide a universal app which replicates the functionality and feature upgrades for everyone to enjoy, you are much better off using GUID's - captured at login - to select and display the data for that tenant.
                            In your current scenario, you have to select the Db from a login or IP address or a similar process. Selecting data based on the login is no more difficult and as has been said, you don't need to update multiple Db's when you need another field or process.

                            I understand why you have done the development the way you have Mike, but in the long run, it is likely to be problematic and possibly unsustainable.
                            But that's just my opinion.
                            It may well work for you as you are deeply into it, but I would suggest a bit more research into MT Apps design.
                            Thanks Ted, I appreciate the advice. Alpha's dynamic connection string method handles everything for me. That part is working well. As far as keeping the databases in sync I plan on writing an automation routine, in Alpha and SQL, to handle that part.
                            Mike Brown - Contact Me
                            Programmatic Technologies, LLC
                            Programmatic-Technologies.com
                            Independent Developer & Consultant​​

                            Comment


                              #15
                              Good stuff Mike.
                              Can I ask you to humour me on the design.
                              There is no "Right" wayto design an app, so just in case you are trailblazing a new approach, can you share the rationale for your design?
                              See our Hybrid Option here;
                              https://hybridapps.example-software.com/


                              Apologies to anyone I haven't managed to upset yet.
                              You are held in a queue and I will get to you soon.

                              Comment

                              Working...
                              X