mirror of
https://github.com/Jetsparrow/karmabot.git
synced 2026-01-21 00:56:09 +03:00
Add database changes
This commit is contained in:
parent
29af7c9183
commit
afc6306c9b
@ -10,7 +10,7 @@ namespace JetKarmaBot.Models
|
||||
public long ChatId { get; set; }
|
||||
public int FromId { get; set; }
|
||||
public int ToId { get; set; }
|
||||
public sbyte AwardTypeId { get; set; }
|
||||
public sbyte? AwardTypeId { get; set; }
|
||||
public sbyte Amount { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
[ForeignKey("AwardTypeId")]
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace JetKarmaBot.Models
|
||||
{
|
||||
@ -12,10 +13,13 @@ namespace JetKarmaBot.Models
|
||||
|
||||
public sbyte AwardTypeId { get; set; }
|
||||
public string CommandName { get; set; }
|
||||
public long ChatId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Symbol { get; set; }
|
||||
public string Description { get; set; }
|
||||
|
||||
public virtual ICollection<Award> Awards { get; set; }
|
||||
[ForeignKey("ChatId")]
|
||||
public virtual Chat Chat { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,15 +5,11 @@ namespace JetKarmaBot.Models
|
||||
{
|
||||
public partial class Chat
|
||||
{
|
||||
public Chat()
|
||||
{
|
||||
Awards = new HashSet<Award>();
|
||||
}
|
||||
|
||||
public long ChatId { get; set; }
|
||||
public string Locale { get; set; }
|
||||
public bool IsAdministrator { get; set; }
|
||||
|
||||
public virtual ICollection<Award> Awards { get; set; }
|
||||
public virtual ICollection<AwardType> AwardTypes { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,8 +112,8 @@ namespace JetKarmaBot.Models
|
||||
.HasName("awardtypeid_UNIQUE")
|
||||
.IsUnique();
|
||||
|
||||
entity.HasIndex(e => e.CommandName)
|
||||
.HasName("commandname_UNIQUE")
|
||||
entity.HasIndex(e => new { e.CommandName, e.ChatId })
|
||||
.HasName("un_cnandchat")
|
||||
.IsUnique();
|
||||
|
||||
entity.Property(e => e.AwardTypeId)
|
||||
@ -139,6 +139,12 @@ namespace JetKarmaBot.Models
|
||||
.IsRequired()
|
||||
.HasColumnName("symbol")
|
||||
.HasColumnType("varchar(16)");
|
||||
|
||||
entity.HasOne(d => d.Chat)
|
||||
.WithMany(p => p.AwardTypes)
|
||||
.HasForeignKey(d => d.ChatId)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("fk_chat");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Chat>(entity =>
|
||||
|
||||
19
karma.sql
19
karma.sql
@ -3,17 +3,15 @@
|
||||
|
||||
DROP TABLE IF EXISTS `awardtype`;
|
||||
CREATE TABLE `awardtype` (
|
||||
`awardtypeid` tinyint(3) NOT NULL PRIMARY KEY,
|
||||
`commandname` varchar(35) NOT NULL UNIQUE,
|
||||
`awardtypeid` tinyint(3) NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
`commandname` varchar(35) NOT NULL,
|
||||
`chatid` bigint(20) NOT NULL REFERENCES `chat` (`chatid`),
|
||||
`name` varchar(32) NOT NULL,
|
||||
`symbol` varchar(16) NOT NULL,
|
||||
`description` text NOT NULL
|
||||
`description` text NOT NULL,
|
||||
UNIQUE KEY `un_cnandchat` (`commandname`, `chatid`)
|
||||
);
|
||||
|
||||
LOCK TABLES `awardtype` WRITE;
|
||||
INSERT INTO `awardtype` VALUES (1,'example','Example','Examples','An example');
|
||||
UNLOCK TABLES;
|
||||
|
||||
DROP TABLE IF EXISTS `chat`;
|
||||
CREATE TABLE `chat` (
|
||||
`chatid` bigint(20) NOT NULL PRIMARY KEY,
|
||||
@ -23,9 +21,8 @@ CREATE TABLE `chat` (
|
||||
|
||||
DROP TABLE IF EXISTS `user`;
|
||||
CREATE TABLE `user` (
|
||||
`userid` bigint(20) NOT NULL,
|
||||
`username` varchar(45) DEFAULT NULL,
|
||||
PRIMARY KEY (`userid`)
|
||||
`userid` bigint(20) NOT NULL PRIMARY KEY,
|
||||
`username` varchar(45) DEFAULT NULL
|
||||
);
|
||||
|
||||
DROP TABLE IF EXISTS `award`;
|
||||
@ -34,7 +31,7 @@ CREATE TABLE `award` (
|
||||
`chatid` bigint(20) NOT NULL REFERENCES `chat` (`chatid`),
|
||||
`fromid` bigint(20) NOT NULL REFERENCES `user` (`userid`),
|
||||
`toid` bigint(20) NOT NULL REFERENCES `user` (`userid`),
|
||||
`awardtypeid` tinyint(3) NOT NULL REFERENCES `awardtype` (`awardtypeid`),
|
||||
`awardtypeid` tinyint(3) REFERENCES `awardtype` (`awardtypeid`),
|
||||
`amount` tinyint(3) NOT NULL DEFAULT 1,
|
||||
`date` datetime NOT NULL DEFAULT current_timestamp()
|
||||
);
|
||||
Loading…
Reference in New Issue
Block a user