CREATE TABLE `communities` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `currency` varchar(3) NOT NULL, `created` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; CREATE TABLE `community_members` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `community_id` int(10) unsigned NOT NULL, `user_id` int(10) unsigned DEFAULT NULL, `owner` tinyint(1) NOT NULL DEFAULT 0, PRIMARY KEY (`id`), UNIQUE KEY `unique_user_for_community` (`community_id`, `user_id`), KEY `community_id` (`community_id`), KEY `user_id` (`user_id`), CONSTRAINT `community_members_community_id` FOREIGN KEY (`community_id`) REFERENCES `communities` (`id`), CONSTRAINT `community_members_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;