Home

Awesome

gorm-multitenancy

Mentioned in Awesome Go Go Reference Release Go Report Card codecov Tests GitHub issues License

<p align="center"> <img src="https://i.imgur.com/bOZB8St.png" title="GORM Multitenancy" alt="GORM Multitenancy"> </p> <p align="center"> <sub><small>Photo by <a href="https://github.com/ashleymcnamara">Ashley McNamara</a>, via <a href="https://github.com/ashleymcnamara/gophers">ashleymcnamara/gophers</a> (CC BY-NC-SA 4.0)</small></sub> </p>

Overview

Gorm-multitenancy provides a Go framework for building multi-tenant applications, streamlining tenant management and model migrations. It abstracts multitenancy complexities through a unified, database-agnostic API compatible with GORM.

Multitenancy Approaches

There are three common approaches to multitenancy in a database:

Depending on the database in use, this package utilizes either the "shared database, separate schemas" or "separate databases" strategy, ensuring a smooth integration with your existing database configuration through the provision of tailored drivers.

Features

Supported Databases

DatabaseApproach
PostgreSQLShared database, separate schemas
MySQLSeparate databases

Router Integration

Installation

Install the core package:

go get -u github.com/bartventer/gorm-multitenancy/v8

Install the database-specific driver:

# PostgreSQL
go get -u github.com/bartventer/gorm-multitenancy/postgres/v8

# MySQL
go get -u github.com/bartventer/gorm-multitenancy/mysql/v8

Optionally, install the router-specific middleware:

# Echo
go get -u github.com/bartventer/gorm-multitenancy/middleware/echo/v8

# Gin
go get -u github.com/bartventer/gorm-multitenancy/middleware/gin/v8

# Iris
go get -u github.com/bartventer/gorm-multitenancy/middleware/iris/v8

# Net/HTTP
go get -u github.com/bartventer/gorm-multitenancy/middleware/nethttp/v8

Getting Started

Check out the pkg.go.dev documentation for comprehensive guides and API references.

Running the Example Application

For a practical demonstration, you can run the example application. It showcases various configurations and usage scenarios.

Contributing

All contributions are welcome! See the Contributing Guide for more details.

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.