Subscription plans
This commit is contained in:
parent
09b7c75dac
commit
f72d94f30f
@ -53,6 +53,15 @@ namespace ManagerService.Controllers
|
|||||||
if (appInstance == null || !appInstance.IsAssistant)
|
if (appInstance == null || !appInstance.IsAssistant)
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
|
var monthKey = DateTime.UtcNow.ToString("yyyy-MM");
|
||||||
|
if (instance.AiUsageMonthKey != monthKey)
|
||||||
|
{
|
||||||
|
instance.AiRequestsThisMonth = 0;
|
||||||
|
instance.AiUsageMonthKey = monthKey;
|
||||||
|
}
|
||||||
|
instance.AiRequestsThisMonth++;
|
||||||
|
_context.SaveChanges();
|
||||||
|
|
||||||
var result = await _assistantService.ChatAsync(request);
|
var result = await _assistantService.ChatAsync(request);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,6 +10,7 @@ using ManagerService.Services;
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using NSwag.Annotations;
|
using NSwag.Annotations;
|
||||||
|
|
||||||
namespace ManagerService.Controllers
|
namespace ManagerService.Controllers
|
||||||
@ -170,6 +171,10 @@ namespace ManagerService.Controllers
|
|||||||
instance.DateCreation = updatedInstance.dateCreation != null ? updatedInstance.dateCreation.Value : instance.DateCreation;
|
instance.DateCreation = updatedInstance.dateCreation != null ? updatedInstance.dateCreation.Value : instance.DateCreation;
|
||||||
instance.Name= updatedInstance.name != null ? updatedInstance.name : instance.Name;
|
instance.Name= updatedInstance.name != null ? updatedInstance.name : instance.Name;
|
||||||
instance.PinCode = updatedInstance.pinCode != null ? updatedInstance.pinCode : instance.PinCode;
|
instance.PinCode = updatedInstance.pinCode != null ? updatedInstance.pinCode : instance.PinCode;
|
||||||
|
if (updatedInstance.subscriptionPlanId == "")
|
||||||
|
instance.SubscriptionPlanId = null;
|
||||||
|
else if (updatedInstance.subscriptionPlanId != null)
|
||||||
|
instance.SubscriptionPlanId = updatedInstance.subscriptionPlanId;
|
||||||
|
|
||||||
//OldInstance instanceModified = _instanceService.Update(updatedInstance.Id, instance);
|
//OldInstance instanceModified = _instanceService.Update(updatedInstance.Id, instance);
|
||||||
_myInfoMateDbContext.SaveChanges();
|
_myInfoMateDbContext.SaveChanges();
|
||||||
@ -253,6 +258,47 @@ namespace ManagerService.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get quota usage for an instance
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Id instance</param>
|
||||||
|
[Authorize(Policy = ManagerService.Service.Security.Policies.Viewer)]
|
||||||
|
[ProducesResponseType(typeof(InstanceQuotaDTO), 200)]
|
||||||
|
[ProducesResponseType(typeof(string), 404)]
|
||||||
|
[ProducesResponseType(typeof(string), 500)]
|
||||||
|
[HttpGet("{id}/quota")]
|
||||||
|
public ObjectResult GetQuota(string id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var instance = _myInfoMateDbContext.Instances
|
||||||
|
.Include(i => i.SubscriptionPlan)
|
||||||
|
.FirstOrDefault(i => i.Id == id);
|
||||||
|
|
||||||
|
if (instance == null)
|
||||||
|
return new NotFoundObjectResult("Instance not found");
|
||||||
|
|
||||||
|
var storageUsed = _myInfoMateDbContext.Resources
|
||||||
|
.Where(r => r.InstanceId == id)
|
||||||
|
.Sum(r => (long?)r.SizeBytes) ?? 0;
|
||||||
|
|
||||||
|
var monthKey = DateTime.UtcNow.ToString("yyyy-MM");
|
||||||
|
var aiUsed = instance.AiUsageMonthKey == monthKey ? instance.AiRequestsThisMonth : 0;
|
||||||
|
|
||||||
|
return new OkObjectResult(new InstanceQuotaDTO
|
||||||
|
{
|
||||||
|
storageUsedBytes = storageUsed,
|
||||||
|
storageQuotaBytes = instance.SubscriptionPlan?.StorageQuotaBytes ?? 0,
|
||||||
|
aiRequestsUsed = aiUsed,
|
||||||
|
aiRequestsPerMonth = instance.SubscriptionPlan?.AiRequestsPerMonth ?? 0
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete an instance
|
/// Delete an instance
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -269,6 +269,7 @@ namespace ManagerService.Controllers
|
|||||||
resource.DateCreation = DateTime.Now.ToUniversalTime();
|
resource.DateCreation = DateTime.Now.ToUniversalTime();
|
||||||
resource.InstanceId = instanceId;
|
resource.InstanceId = instanceId;
|
||||||
resource.Id = idService.GenerateHexId();
|
resource.Id = idService.GenerateHexId();
|
||||||
|
resource.SizeBytes = file.Length;
|
||||||
|
|
||||||
_myInfoMateDbContext.Add(resource);
|
_myInfoMateDbContext.Add(resource);
|
||||||
_myInfoMateDbContext.SaveChanges();
|
_myInfoMateDbContext.SaveChanges();
|
||||||
|
|||||||
150
ManagerService/Controllers/SubscriptionPlanController.cs
Normal file
150
ManagerService/Controllers/SubscriptionPlanController.cs
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
using ManagerService.Data;
|
||||||
|
using ManagerService.DTOs;
|
||||||
|
using ManagerService.Helpers;
|
||||||
|
using ManagerService.Services;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using NSwag.Annotations;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace ManagerService.Controllers
|
||||||
|
{
|
||||||
|
[Authorize(Policy = ManagerService.Service.Security.Policies.SuperAdmin)]
|
||||||
|
[ApiController, Route("api/[controller]")]
|
||||||
|
[OpenApiTag("SubscriptionPlan", Description = "Subscription plan management")]
|
||||||
|
public class SubscriptionPlanController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly MyInfoMateDbContext _myInfoMateDbContext;
|
||||||
|
private readonly ILogger<SubscriptionPlanController> _logger;
|
||||||
|
IHexIdGeneratorService idService = new HexIdGeneratorService();
|
||||||
|
|
||||||
|
public SubscriptionPlanController(ILogger<SubscriptionPlanController> logger, MyInfoMateDbContext myInfoMateDbContext)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_myInfoMateDbContext = myInfoMateDbContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
[ProducesResponseType(typeof(List<SubscriptionPlanDTO>), 200)]
|
||||||
|
[ProducesResponseType(typeof(string), 500)]
|
||||||
|
[HttpGet]
|
||||||
|
public ObjectResult Get()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var plans = _myInfoMateDbContext.SubscriptionPlans.ToList();
|
||||||
|
return new OkObjectResult(plans.Select(p => p.ToDTO()).ToList());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[ProducesResponseType(typeof(SubscriptionPlanDTO), 200)]
|
||||||
|
[ProducesResponseType(typeof(string), 404)]
|
||||||
|
[ProducesResponseType(typeof(string), 500)]
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public ObjectResult GetById(string id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var plan = _myInfoMateDbContext.SubscriptionPlans.FirstOrDefault(p => p.Id == id);
|
||||||
|
if (plan == null)
|
||||||
|
return new NotFoundObjectResult("Subscription plan not found");
|
||||||
|
|
||||||
|
return new OkObjectResult(plan.ToDTO());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[ProducesResponseType(typeof(SubscriptionPlanDTO), 200)]
|
||||||
|
[ProducesResponseType(typeof(string), 400)]
|
||||||
|
[ProducesResponseType(typeof(string), 500)]
|
||||||
|
[HttpPost]
|
||||||
|
public ObjectResult Create([FromBody] SubscriptionPlanDTO dto)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (dto == null)
|
||||||
|
return new BadRequestObjectResult("Plan data is required");
|
||||||
|
|
||||||
|
var plan = new SubscriptionPlan().FromDTO(dto);
|
||||||
|
plan.Id = idService.GenerateHexId();
|
||||||
|
|
||||||
|
_myInfoMateDbContext.SubscriptionPlans.Add(plan);
|
||||||
|
_myInfoMateDbContext.SaveChanges();
|
||||||
|
|
||||||
|
return new OkObjectResult(plan.ToDTO());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[ProducesResponseType(typeof(SubscriptionPlanDTO), 200)]
|
||||||
|
[ProducesResponseType(typeof(string), 400)]
|
||||||
|
[ProducesResponseType(typeof(string), 404)]
|
||||||
|
[ProducesResponseType(typeof(string), 500)]
|
||||||
|
[HttpPut]
|
||||||
|
public ObjectResult Update([FromBody] SubscriptionPlanDTO dto)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (dto == null || dto.id == null)
|
||||||
|
return new BadRequestObjectResult("Plan id is required");
|
||||||
|
|
||||||
|
var plan = _myInfoMateDbContext.SubscriptionPlans.FirstOrDefault(p => p.Id == dto.id);
|
||||||
|
if (plan == null)
|
||||||
|
return new NotFoundObjectResult("Subscription plan not found");
|
||||||
|
|
||||||
|
plan.FromDTO(dto);
|
||||||
|
_myInfoMateDbContext.SaveChanges();
|
||||||
|
|
||||||
|
return new OkObjectResult(plan.ToDTO());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[ProducesResponseType(typeof(string), 202)]
|
||||||
|
[ProducesResponseType(typeof(string), 400)]
|
||||||
|
[ProducesResponseType(typeof(string), 404)]
|
||||||
|
[ProducesResponseType(typeof(string), 409)]
|
||||||
|
[ProducesResponseType(typeof(string), 500)]
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
public ObjectResult Delete(string id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (id == null)
|
||||||
|
return new BadRequestObjectResult("Plan id is required");
|
||||||
|
|
||||||
|
var plan = _myInfoMateDbContext.SubscriptionPlans.FirstOrDefault(p => p.Id == id);
|
||||||
|
if (plan == null)
|
||||||
|
return new NotFoundObjectResult("Subscription plan not found");
|
||||||
|
|
||||||
|
var isUsed = _myInfoMateDbContext.Instances.Any(i => i.SubscriptionPlanId == id);
|
||||||
|
if (isUsed)
|
||||||
|
return new ConflictObjectResult("This plan is assigned to one or more instances");
|
||||||
|
|
||||||
|
_myInfoMateDbContext.SubscriptionPlans.Remove(plan);
|
||||||
|
_myInfoMateDbContext.SaveChanges();
|
||||||
|
|
||||||
|
return new ObjectResult("The subscription plan has been deleted") { StatusCode = 202 };
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -18,6 +18,11 @@ namespace ManagerService.DTOs
|
|||||||
|
|
||||||
public bool isAssistant { get; set; }
|
public bool isAssistant { get; set; }
|
||||||
|
|
||||||
|
public string? subscriptionPlanId { get; set; }
|
||||||
|
public SubscriptionPlanDTO? subscriptionPlan { get; set; }
|
||||||
|
public int aiRequestsThisMonth { get; set; }
|
||||||
|
public string? aiUsageMonthKey { get; set; }
|
||||||
|
|
||||||
public List<ApplicationInstanceDTO> applicationInstanceDTOs { get; set; }
|
public List<ApplicationInstanceDTO> applicationInstanceDTOs { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
ManagerService/DTOs/InstanceQuotaDTO.cs
Normal file
10
ManagerService/DTOs/InstanceQuotaDTO.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
namespace ManagerService.DTOs
|
||||||
|
{
|
||||||
|
public class InstanceQuotaDTO
|
||||||
|
{
|
||||||
|
public long storageUsedBytes { get; set; }
|
||||||
|
public long storageQuotaBytes { get; set; }
|
||||||
|
public int aiRequestsUsed { get; set; }
|
||||||
|
public int aiRequestsPerMonth { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -11,5 +11,6 @@ namespace ManagerService.DTOs
|
|||||||
public string url { get; set; } // firebase url
|
public string url { get; set; } // firebase url
|
||||||
public DateTime dateCreation { get; set; }
|
public DateTime dateCreation { get; set; }
|
||||||
public string instanceId { get; set; }
|
public string instanceId { get; set; }
|
||||||
|
public long sizeBytes { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
ManagerService/DTOs/SubscriptionPlanDTO.cs
Normal file
10
ManagerService/DTOs/SubscriptionPlanDTO.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
namespace ManagerService.DTOs
|
||||||
|
{
|
||||||
|
public class SubscriptionPlanDTO
|
||||||
|
{
|
||||||
|
public string? id { get; set; }
|
||||||
|
public string name { get; set; }
|
||||||
|
public long storageQuotaBytes { get; set; }
|
||||||
|
public int aiRequestsPerMonth { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,6 +2,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
namespace ManagerService.Data
|
namespace ManagerService.Data
|
||||||
{
|
{
|
||||||
@ -35,6 +36,15 @@ namespace ManagerService.Data
|
|||||||
|
|
||||||
public bool IsAssistant { get; set; }
|
public bool IsAssistant { get; set; }
|
||||||
|
|
||||||
|
public string? SubscriptionPlanId { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey("SubscriptionPlanId")]
|
||||||
|
public SubscriptionPlan? SubscriptionPlan { get; set; }
|
||||||
|
|
||||||
|
public int AiRequestsThisMonth { get; set; } = 0;
|
||||||
|
|
||||||
|
public string AiUsageMonthKey { get; set; } = "";
|
||||||
|
|
||||||
|
|
||||||
public InstanceDTO ToDTO(List<ApplicationInstanceDTO> applicationInstanceDTOs)
|
public InstanceDTO ToDTO(List<ApplicationInstanceDTO> applicationInstanceDTOs)
|
||||||
{
|
{
|
||||||
@ -51,6 +61,10 @@ namespace ManagerService.Data
|
|||||||
isWeb = IsWeb,
|
isWeb = IsWeb,
|
||||||
isVR = IsVR,
|
isVR = IsVR,
|
||||||
isAssistant = IsAssistant,
|
isAssistant = IsAssistant,
|
||||||
|
subscriptionPlanId = SubscriptionPlanId,
|
||||||
|
subscriptionPlan = SubscriptionPlan?.ToDTO(),
|
||||||
|
aiRequestsThisMonth = AiRequestsThisMonth,
|
||||||
|
aiUsageMonthKey = AiUsageMonthKey,
|
||||||
applicationInstanceDTOs = applicationInstanceDTOs
|
applicationInstanceDTOs = applicationInstanceDTOs
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -67,6 +81,8 @@ namespace ManagerService.Data
|
|||||||
IsWeb = instanceDTO.isWeb;
|
IsWeb = instanceDTO.isWeb;
|
||||||
IsVR = instanceDTO.isVR;
|
IsVR = instanceDTO.isVR;
|
||||||
IsAssistant = instanceDTO.isAssistant;
|
IsAssistant = instanceDTO.isAssistant;
|
||||||
|
if (instanceDTO.subscriptionPlanId != null)
|
||||||
|
SubscriptionPlanId = instanceDTO.subscriptionPlanId;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,6 +13,7 @@ namespace ManagerService.Data
|
|||||||
public MyInfoMateDbContext(DbContextOptions<MyInfoMateDbContext> options) : base(options) { }
|
public MyInfoMateDbContext(DbContextOptions<MyInfoMateDbContext> options) : base(options) { }
|
||||||
|
|
||||||
public DbSet<Instance> Instances { get; set; }
|
public DbSet<Instance> Instances { get; set; }
|
||||||
|
public DbSet<SubscriptionPlan> SubscriptionPlans { get; set; }
|
||||||
public DbSet<Configuration> Configurations { get; set; }
|
public DbSet<Configuration> Configurations { get; set; }
|
||||||
public DbSet<Section> Sections { get; set; }
|
public DbSet<Section> Sections { get; set; }
|
||||||
public DbSet<Device> Devices { get; set; }
|
public DbSet<Device> Devices { get; set; }
|
||||||
|
|||||||
@ -36,7 +36,9 @@ namespace ManagerService.Data
|
|||||||
/*[BsonElement("URL")]*/
|
/*[BsonElement("URL")]*/
|
||||||
public string Url { get; set; } // Firebase url
|
public string Url { get; set; } // Firebase url
|
||||||
|
|
||||||
public ResourceDTO ToDTO()
|
public long SizeBytes { get; set; } = 0;
|
||||||
|
|
||||||
|
public ResourceDTO ToDTO()
|
||||||
{
|
{
|
||||||
return new ResourceDTO()
|
return new ResourceDTO()
|
||||||
{
|
{
|
||||||
@ -45,7 +47,8 @@ namespace ManagerService.Data
|
|||||||
type = Type,
|
type = Type,
|
||||||
url = Url,
|
url = Url,
|
||||||
dateCreation = DateCreation,
|
dateCreation = DateCreation,
|
||||||
instanceId = InstanceId
|
instanceId = InstanceId,
|
||||||
|
sizeBytes = SizeBytes
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
38
ManagerService/Data/SubscriptionPlan.cs
Normal file
38
ManagerService/Data/SubscriptionPlan.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using ManagerService.DTOs;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace ManagerService.Data
|
||||||
|
{
|
||||||
|
public class SubscriptionPlan
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
[Required]
|
||||||
|
public string Id { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public long StorageQuotaBytes { get; set; } = 0;
|
||||||
|
|
||||||
|
public int AiRequestsPerMonth { get; set; } = 0;
|
||||||
|
|
||||||
|
public SubscriptionPlanDTO ToDTO()
|
||||||
|
{
|
||||||
|
return new SubscriptionPlanDTO
|
||||||
|
{
|
||||||
|
id = Id,
|
||||||
|
name = Name,
|
||||||
|
storageQuotaBytes = StorageQuotaBytes,
|
||||||
|
aiRequestsPerMonth = AiRequestsPerMonth
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public SubscriptionPlan FromDTO(SubscriptionPlanDTO dto)
|
||||||
|
{
|
||||||
|
Name = dto.name;
|
||||||
|
StorageQuotaBytes = dto.storageQuotaBytes;
|
||||||
|
AiRequestsPerMonth = dto.aiRequestsPerMonth;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
1482
ManagerService/Migrations/20260401140706_AddSubscriptionPlanAndQuota.Designer.cs
generated
Normal file
1482
ManagerService/Migrations/20260401140706_AddSubscriptionPlanAndQuota.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,97 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace ManagerService.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddSubscriptionPlanAndQuota : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<long>(
|
||||||
|
name: "SizeBytes",
|
||||||
|
table: "Resources",
|
||||||
|
type: "bigint",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0L);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "AiRequestsThisMonth",
|
||||||
|
table: "Instances",
|
||||||
|
type: "integer",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "AiUsageMonthKey",
|
||||||
|
table: "Instances",
|
||||||
|
type: "text",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "SubscriptionPlanId",
|
||||||
|
table: "Instances",
|
||||||
|
type: "text",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "SubscriptionPlans",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<string>(type: "text", nullable: false),
|
||||||
|
Name = table.Column<string>(type: "text", nullable: false),
|
||||||
|
StorageQuotaBytes = table.Column<long>(type: "bigint", nullable: false),
|
||||||
|
AiRequestsPerMonth = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_SubscriptionPlans", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Instances_SubscriptionPlanId",
|
||||||
|
table: "Instances",
|
||||||
|
column: "SubscriptionPlanId");
|
||||||
|
|
||||||
|
migrationBuilder.AddForeignKey(
|
||||||
|
name: "FK_Instances_SubscriptionPlans_SubscriptionPlanId",
|
||||||
|
table: "Instances",
|
||||||
|
column: "SubscriptionPlanId",
|
||||||
|
principalTable: "SubscriptionPlans",
|
||||||
|
principalColumn: "Id");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropForeignKey(
|
||||||
|
name: "FK_Instances_SubscriptionPlans_SubscriptionPlanId",
|
||||||
|
table: "Instances");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "SubscriptionPlans");
|
||||||
|
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_Instances_SubscriptionPlanId",
|
||||||
|
table: "Instances");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "SizeBytes",
|
||||||
|
table: "Resources");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "AiRequestsThisMonth",
|
||||||
|
table: "Instances");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "AiUsageMonthKey",
|
||||||
|
table: "Instances");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "SubscriptionPlanId",
|
||||||
|
table: "Instances");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -296,6 +296,12 @@ namespace ManagerService.Migrations
|
|||||||
b.Property<string>("Id")
|
b.Property<string>("Id")
|
||||||
.HasColumnType("text");
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int>("AiRequestsThisMonth")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("AiUsageMonthKey")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
b.Property<DateTime>("DateCreation")
|
b.Property<DateTime>("DateCreation")
|
||||||
.HasColumnType("timestamp with time zone");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
@ -327,8 +333,13 @@ namespace ManagerService.Migrations
|
|||||||
b.Property<string>("PinCode")
|
b.Property<string>("PinCode")
|
||||||
.HasColumnType("text");
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("SubscriptionPlanId")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("SubscriptionPlanId");
|
||||||
|
|
||||||
b.ToTable("Instances");
|
b.ToTable("Instances");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -391,6 +402,9 @@ namespace ManagerService.Migrations
|
|||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("text");
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<long>("SizeBytes")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
b.Property<int>("Type")
|
b.Property<int>("Type")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
@ -857,6 +871,26 @@ namespace ManagerService.Migrations
|
|||||||
b.ToTable("ProgrammeBlocks");
|
b.ToTable("ProgrammeBlocks");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ManagerService.Data.SubscriptionPlan", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Id")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int>("AiRequestsPerMonth")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<long>("StorageQuotaBytes")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("SubscriptionPlans");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("ManagerService.Data.User", b =>
|
modelBuilder.Entity("ManagerService.Data.User", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("Id")
|
b.Property<string>("Id")
|
||||||
@ -1217,6 +1251,15 @@ namespace ManagerService.Migrations
|
|||||||
b.Navigation("Configuration");
|
b.Navigation("Configuration");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ManagerService.Data.Instance", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("ManagerService.Data.SubscriptionPlan", "SubscriptionPlan")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("SubscriptionPlanId");
|
||||||
|
|
||||||
|
b.Navigation("SubscriptionPlan");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("ManagerService.Data.Section", b =>
|
modelBuilder.Entity("ManagerService.Data.Section", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("ManagerService.Data.SubSection.SectionMenu", null)
|
b.HasOne("ManagerService.Data.SubSection.SectionMenu", null)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user