admin_log.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. package models
  2. import (
  3. "database/sql"
  4. "time"
  5. "github.com/google/uuid"
  6. "github.com/guregu/null"
  7. "gorm.io/gorm"
  8. )
  9. var (
  10. _ = time.Second
  11. _ = sql.LevelDefault
  12. _ = null.Bool{}
  13. _ = uuid.UUID{}
  14. )
  15. /*
  16. DB Table Details
  17. -------------------------------------
  18. CREATE TABLE `admin_log` (
  19. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  20. `admin_id` bigint(20) unsigned NOT NULL,
  21. `action_type` enum('user','artist','collection','curation','system','admin') COLLATE utf8mb4_bin NOT NULL,
  22. `sub_action_type` enum('created','modified','deleted') COLLATE utf8mb4_bin NOT NULL,
  23. `actioned_at` timestamp NOT NULL,
  24. `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  25. `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  26. `deleted_at` timestamp NULL DEFAULT NULL,
  27. `message` varchar(256) COLLATE utf8mb4_bin NOT NULL,
  28. PRIMARY KEY (`id`),
  29. UNIQUE KEY `id_UNIQUE` (`id`),
  30. KEY `fk_template_table_admin1_idx` (`admin_id`),
  31. CONSTRAINT `fk_template_table_admin1` FOREIGN KEY (`admin_id`) REFERENCES `admin` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
  32. ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
  33. JSON Sample
  34. -------------------------------------
  35. { "id": 4, "admin_id": 30, "action_type": "cBmoqqFyEiFMooFcyJlZTCDbP", "sub_action_type": "vZlCmKpZChXYCloLDfhJldygF", "actioned_at": "2303-04-02T20:29:25.82546921+09:00", "created_at": "2306-04-30T13:49:17.570249449+09:00", "updated_at": "2157-05-21T06:34:54.550292418+09:00", "deleted_at": "2063-01-31T00:11:20.025696792+09:00", "message": "yYfyCNgbaxEDTwFQddalnKtLb"}
  36. Comments
  37. -------------------------------------
  38. [ 0] column is set for unsigned
  39. [ 1] column is set for unsigned
  40. */
  41. // AdminLog struct is a row record of the admin_log table in the metarare database
  42. type AdminLog struct {
  43. //[ 0] id ubigint null: false primary: true isArray: false auto: true col: ubigint len: -1 default: []
  44. ID uint64 `gorm:"primary_key;AUTO_INCREMENT;column:id;type:ubigint;" json:"id"`
  45. //[ 1] admin_id ubigint null: false primary: false isArray: false auto: false col: ubigint len: -1 default: []
  46. AdminID uint64 `gorm:"column:admin_id;type:ubigint;" json:"admin_id"`
  47. //[ 2] action_type char(10) null: false primary: false isArray: false auto: false col: char len: 10 default: []
  48. ActionType string `gorm:"column:action_type;type:char;size:10;" json:"action_type"`
  49. //[ 3] sub_action_type char(8) null: false primary: false isArray: false auto: false col: char len: 8 default: []
  50. SubActionType string `gorm:"column:sub_action_type;type:char;size:8;" json:"sub_action_type"`
  51. //[ 4] actioned_at timestamp null: false primary: false isArray: false auto: false col: timestamp len: -1 default: []
  52. ActionedAt time.Time `gorm:"column:actioned_at;type:timestamp;" json:"actioned_at"`
  53. //[ 5] created_at timestamp null: false primary: false isArray: false auto: false col: timestamp len: -1 default: [CURRENT_TIMESTAMP]
  54. CreatedAt time.Time `gorm:"column:created_at;type:timestamp;default:CURRENT_TIMESTAMP;" json:"created_at"`
  55. //[ 6] updated_at timestamp null: false primary: false isArray: false auto: false col: timestamp len: -1 default: [CURRENT_TIMESTAMP]
  56. UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;default:CURRENT_TIMESTAMP;" json:"updated_at"`
  57. //[ 7] deleted_at timestamp null: true primary: false isArray: false auto: false col: timestamp len: -1 default: []
  58. DeletedAt null.Time `gorm:"column:deleted_at;type:timestamp;" json:"deleted_at"`
  59. //[ 8] message varchar(256) null: false primary: false isArray: false auto: false col: varchar len: 256 default: []
  60. Message string `gorm:"column:message;type:varchar;size:256;" json:"message"`
  61. }
  62. var admin_logTableInfo = &TableInfo{
  63. Name: "admin_log",
  64. Columns: []*ColumnInfo{
  65. &ColumnInfo{
  66. Index: 0,
  67. Name: "id",
  68. Comment: ``,
  69. Notes: `column is set for unsigned`,
  70. Nullable: false,
  71. DatabaseTypeName: "ubigint",
  72. DatabaseTypePretty: "ubigint",
  73. IsPrimaryKey: true,
  74. IsAutoIncrement: true,
  75. IsArray: false,
  76. ColumnType: "ubigint",
  77. ColumnLength: -1,
  78. GoFieldName: "ID",
  79. GoFieldType: "uint64",
  80. JSONFieldName: "id",
  81. ProtobufFieldName: "id",
  82. ProtobufType: "uint64",
  83. ProtobufPos: 1,
  84. },
  85. &ColumnInfo{
  86. Index: 1,
  87. Name: "admin_id",
  88. Comment: ``,
  89. Notes: `column is set for unsigned`,
  90. Nullable: false,
  91. DatabaseTypeName: "ubigint",
  92. DatabaseTypePretty: "ubigint",
  93. IsPrimaryKey: false,
  94. IsAutoIncrement: false,
  95. IsArray: false,
  96. ColumnType: "ubigint",
  97. ColumnLength: -1,
  98. GoFieldName: "AdminID",
  99. GoFieldType: "uint64",
  100. JSONFieldName: "admin_id",
  101. ProtobufFieldName: "admin_id",
  102. ProtobufType: "uint64",
  103. ProtobufPos: 2,
  104. },
  105. &ColumnInfo{
  106. Index: 2,
  107. Name: "action_type",
  108. Comment: ``,
  109. Notes: ``,
  110. Nullable: false,
  111. DatabaseTypeName: "char",
  112. DatabaseTypePretty: "char(10)",
  113. IsPrimaryKey: false,
  114. IsAutoIncrement: false,
  115. IsArray: false,
  116. ColumnType: "char",
  117. ColumnLength: 10,
  118. GoFieldName: "ActionType",
  119. GoFieldType: "string",
  120. JSONFieldName: "action_type",
  121. ProtobufFieldName: "action_type",
  122. ProtobufType: "string",
  123. ProtobufPos: 3,
  124. },
  125. &ColumnInfo{
  126. Index: 3,
  127. Name: "sub_action_type",
  128. Comment: ``,
  129. Notes: ``,
  130. Nullable: false,
  131. DatabaseTypeName: "char",
  132. DatabaseTypePretty: "char(8)",
  133. IsPrimaryKey: false,
  134. IsAutoIncrement: false,
  135. IsArray: false,
  136. ColumnType: "char",
  137. ColumnLength: 8,
  138. GoFieldName: "SubActionType",
  139. GoFieldType: "string",
  140. JSONFieldName: "sub_action_type",
  141. ProtobufFieldName: "sub_action_type",
  142. ProtobufType: "string",
  143. ProtobufPos: 4,
  144. },
  145. &ColumnInfo{
  146. Index: 4,
  147. Name: "actioned_at",
  148. Comment: ``,
  149. Notes: ``,
  150. Nullable: false,
  151. DatabaseTypeName: "timestamp",
  152. DatabaseTypePretty: "timestamp",
  153. IsPrimaryKey: false,
  154. IsAutoIncrement: false,
  155. IsArray: false,
  156. ColumnType: "timestamp",
  157. ColumnLength: -1,
  158. GoFieldName: "ActionedAt",
  159. GoFieldType: "time.Time",
  160. JSONFieldName: "actioned_at",
  161. ProtobufFieldName: "actioned_at",
  162. ProtobufType: "uint64",
  163. ProtobufPos: 5,
  164. },
  165. &ColumnInfo{
  166. Index: 5,
  167. Name: "created_at",
  168. Comment: ``,
  169. Notes: ``,
  170. Nullable: false,
  171. DatabaseTypeName: "timestamp",
  172. DatabaseTypePretty: "timestamp",
  173. IsPrimaryKey: false,
  174. IsAutoIncrement: false,
  175. IsArray: false,
  176. ColumnType: "timestamp",
  177. ColumnLength: -1,
  178. GoFieldName: "CreatedAt",
  179. GoFieldType: "time.Time",
  180. JSONFieldName: "created_at",
  181. ProtobufFieldName: "created_at",
  182. ProtobufType: "uint64",
  183. ProtobufPos: 6,
  184. },
  185. &ColumnInfo{
  186. Index: 6,
  187. Name: "updated_at",
  188. Comment: ``,
  189. Notes: ``,
  190. Nullable: false,
  191. DatabaseTypeName: "timestamp",
  192. DatabaseTypePretty: "timestamp",
  193. IsPrimaryKey: false,
  194. IsAutoIncrement: false,
  195. IsArray: false,
  196. ColumnType: "timestamp",
  197. ColumnLength: -1,
  198. GoFieldName: "UpdatedAt",
  199. GoFieldType: "time.Time",
  200. JSONFieldName: "updated_at",
  201. ProtobufFieldName: "updated_at",
  202. ProtobufType: "uint64",
  203. ProtobufPos: 7,
  204. },
  205. &ColumnInfo{
  206. Index: 7,
  207. Name: "deleted_at",
  208. Comment: ``,
  209. Notes: ``,
  210. Nullable: true,
  211. DatabaseTypeName: "timestamp",
  212. DatabaseTypePretty: "timestamp",
  213. IsPrimaryKey: false,
  214. IsAutoIncrement: false,
  215. IsArray: false,
  216. ColumnType: "timestamp",
  217. ColumnLength: -1,
  218. GoFieldName: "DeletedAt",
  219. GoFieldType: "null.Time",
  220. JSONFieldName: "deleted_at",
  221. ProtobufFieldName: "deleted_at",
  222. ProtobufType: "uint64",
  223. ProtobufPos: 8,
  224. },
  225. &ColumnInfo{
  226. Index: 8,
  227. Name: "message",
  228. Comment: ``,
  229. Notes: ``,
  230. Nullable: false,
  231. DatabaseTypeName: "varchar",
  232. DatabaseTypePretty: "varchar(256)",
  233. IsPrimaryKey: false,
  234. IsAutoIncrement: false,
  235. IsArray: false,
  236. ColumnType: "varchar",
  237. ColumnLength: 256,
  238. GoFieldName: "Message",
  239. GoFieldType: "string",
  240. JSONFieldName: "message",
  241. ProtobufFieldName: "message",
  242. ProtobufType: "string",
  243. ProtobufPos: 9,
  244. },
  245. },
  246. }
  247. // TableName sets the insert table name for this struct type
  248. func (a *AdminLog) TableName() string {
  249. return "admin_log"
  250. }
  251. // BeforeSave invoked before saving, return an error if field is not populated.
  252. func (a *AdminLog) BeforeSave(*gorm.DB) error {
  253. return nil
  254. }
  255. // Prepare invoked before saving, can be used to populate fields etc.
  256. func (a *AdminLog) Prepare() {
  257. }
  258. // Validate invoked before performing action, return an error if field is not populated.
  259. func (a *AdminLog) Validate(action Action) error {
  260. return nil
  261. }
  262. // TableInfo return table meta data
  263. func (a *AdminLog) TableInfo() *TableInfo {
  264. return admin_logTableInfo
  265. }