admin_permission.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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_permission` (
  19. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  20. `admin_id` bigint(20) unsigned NOT NULL,
  21. `user` tinyint(4) NOT NULL DEFAULT '0',
  22. `collection` tinyint(4) NOT NULL DEFAULT '0',
  23. `system` tinyint(4) NOT NULL DEFAULT '0',
  24. `admin` tinyint(4) NOT NULL DEFAULT '0',
  25. `log` tinyint(4) NOT NULL DEFAULT '0',
  26. `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  27. `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  28. `deleted_at` timestamp NULL DEFAULT NULL,
  29. PRIMARY KEY (`id`),
  30. UNIQUE KEY `id_UNIQUE` (`id`),
  31. KEY `fk_admin_permission_admin_idx` (`admin_id`),
  32. CONSTRAINT `fk_admin_permission_admin` FOREIGN KEY (`admin_id`) REFERENCES `admin` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
  33. ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
  34. JSON Sample
  35. -------------------------------------
  36. { "id": 46, "admin_id": 92, "user": 62, "collection": 83, "system": 22, "admin": 93, "log": 19, "created_at": "2180-07-06T16:12:34.96190249+09:00", "updated_at": "2180-10-15T05:55:35.50110137+09:00", "deleted_at": "2104-09-07T06:08:47.931462761+09:00"}
  37. Comments
  38. -------------------------------------
  39. [ 0] column is set for unsigned
  40. [ 1] column is set for unsigned
  41. */
  42. // AdminPermission struct is a row record of the admin_permission table in the metarare database
  43. type AdminPermission struct {
  44. //[ 0] id ubigint null: false primary: true isArray: false auto: true col: ubigint len: -1 default: []
  45. ID uint64 `gorm:"primary_key;AUTO_INCREMENT;column:id;type:ubigint;" json:"id"`
  46. //[ 1] admin_id ubigint null: false primary: false isArray: false auto: false col: ubigint len: -1 default: []
  47. AdminID uint64 `gorm:"column:admin_id;type:ubigint;" json:"admin_id"`
  48. //[ 2] user tinyint null: false primary: false isArray: false auto: false col: tinyint len: -1 default: [0]
  49. User int32 `gorm:"column:user;type:tinyint;default:0;" json:"user"`
  50. //[ 3] collection tinyint null: false primary: false isArray: false auto: false col: tinyint len: -1 default: [0]
  51. Collection int32 `gorm:"column:collection;type:tinyint;default:0;" json:"collection"`
  52. //[ 4] system tinyint null: false primary: false isArray: false auto: false col: tinyint len: -1 default: [0]
  53. System int32 `gorm:"column:system;type:tinyint;default:0;" json:"system"`
  54. //[ 5] admin tinyint null: false primary: false isArray: false auto: false col: tinyint len: -1 default: [0]
  55. Admin int32 `gorm:"column:admin;type:tinyint;default:0;" json:"admin"`
  56. //[ 6] log tinyint null: false primary: false isArray: false auto: false col: tinyint len: -1 default: [0]
  57. Log int32 `gorm:"column:log;type:tinyint;default:0;" json:"log"`
  58. //[ 7] created_at timestamp null: false primary: false isArray: false auto: false col: timestamp len: -1 default: [CURRENT_TIMESTAMP]
  59. CreatedAt time.Time `gorm:"column:created_at;type:timestamp;default:CURRENT_TIMESTAMP;" json:"created_at"`
  60. //[ 8] updated_at timestamp null: false primary: false isArray: false auto: false col: timestamp len: -1 default: [CURRENT_TIMESTAMP]
  61. UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;default:CURRENT_TIMESTAMP;" json:"updated_at"`
  62. //[ 9] deleted_at timestamp null: true primary: false isArray: false auto: false col: timestamp len: -1 default: []
  63. DeletedAt null.Time `gorm:"column:deleted_at;type:timestamp;" json:"deleted_at"`
  64. }
  65. var admin_permissionTableInfo = &TableInfo{
  66. Name: "admin_permission",
  67. Columns: []*ColumnInfo{
  68. &ColumnInfo{
  69. Index: 0,
  70. Name: "id",
  71. Comment: ``,
  72. Notes: `column is set for unsigned`,
  73. Nullable: false,
  74. DatabaseTypeName: "ubigint",
  75. DatabaseTypePretty: "ubigint",
  76. IsPrimaryKey: true,
  77. IsAutoIncrement: true,
  78. IsArray: false,
  79. ColumnType: "ubigint",
  80. ColumnLength: -1,
  81. GoFieldName: "ID",
  82. GoFieldType: "uint64",
  83. JSONFieldName: "id",
  84. ProtobufFieldName: "id",
  85. ProtobufType: "uint64",
  86. ProtobufPos: 1,
  87. },
  88. &ColumnInfo{
  89. Index: 1,
  90. Name: "admin_id",
  91. Comment: ``,
  92. Notes: `column is set for unsigned`,
  93. Nullable: false,
  94. DatabaseTypeName: "ubigint",
  95. DatabaseTypePretty: "ubigint",
  96. IsPrimaryKey: false,
  97. IsAutoIncrement: false,
  98. IsArray: false,
  99. ColumnType: "ubigint",
  100. ColumnLength: -1,
  101. GoFieldName: "AdminID",
  102. GoFieldType: "uint64",
  103. JSONFieldName: "admin_id",
  104. ProtobufFieldName: "admin_id",
  105. ProtobufType: "uint64",
  106. ProtobufPos: 2,
  107. },
  108. &ColumnInfo{
  109. Index: 2,
  110. Name: "user",
  111. Comment: ``,
  112. Notes: ``,
  113. Nullable: false,
  114. DatabaseTypeName: "tinyint",
  115. DatabaseTypePretty: "tinyint",
  116. IsPrimaryKey: false,
  117. IsAutoIncrement: false,
  118. IsArray: false,
  119. ColumnType: "tinyint",
  120. ColumnLength: -1,
  121. GoFieldName: "User",
  122. GoFieldType: "int32",
  123. JSONFieldName: "user",
  124. ProtobufFieldName: "user",
  125. ProtobufType: "int32",
  126. ProtobufPos: 3,
  127. },
  128. &ColumnInfo{
  129. Index: 3,
  130. Name: "collection",
  131. Comment: ``,
  132. Notes: ``,
  133. Nullable: false,
  134. DatabaseTypeName: "tinyint",
  135. DatabaseTypePretty: "tinyint",
  136. IsPrimaryKey: false,
  137. IsAutoIncrement: false,
  138. IsArray: false,
  139. ColumnType: "tinyint",
  140. ColumnLength: -1,
  141. GoFieldName: "Collection",
  142. GoFieldType: "int32",
  143. JSONFieldName: "collection",
  144. ProtobufFieldName: "collection",
  145. ProtobufType: "int32",
  146. ProtobufPos: 4,
  147. },
  148. &ColumnInfo{
  149. Index: 4,
  150. Name: "system",
  151. Comment: ``,
  152. Notes: ``,
  153. Nullable: false,
  154. DatabaseTypeName: "tinyint",
  155. DatabaseTypePretty: "tinyint",
  156. IsPrimaryKey: false,
  157. IsAutoIncrement: false,
  158. IsArray: false,
  159. ColumnType: "tinyint",
  160. ColumnLength: -1,
  161. GoFieldName: "System",
  162. GoFieldType: "int32",
  163. JSONFieldName: "system",
  164. ProtobufFieldName: "system",
  165. ProtobufType: "int32",
  166. ProtobufPos: 5,
  167. },
  168. &ColumnInfo{
  169. Index: 5,
  170. Name: "admin",
  171. Comment: ``,
  172. Notes: ``,
  173. Nullable: false,
  174. DatabaseTypeName: "tinyint",
  175. DatabaseTypePretty: "tinyint",
  176. IsPrimaryKey: false,
  177. IsAutoIncrement: false,
  178. IsArray: false,
  179. ColumnType: "tinyint",
  180. ColumnLength: -1,
  181. GoFieldName: "Admin",
  182. GoFieldType: "int32",
  183. JSONFieldName: "admin",
  184. ProtobufFieldName: "admin",
  185. ProtobufType: "int32",
  186. ProtobufPos: 6,
  187. },
  188. &ColumnInfo{
  189. Index: 6,
  190. Name: "log",
  191. Comment: ``,
  192. Notes: ``,
  193. Nullable: false,
  194. DatabaseTypeName: "tinyint",
  195. DatabaseTypePretty: "tinyint",
  196. IsPrimaryKey: false,
  197. IsAutoIncrement: false,
  198. IsArray: false,
  199. ColumnType: "tinyint",
  200. ColumnLength: -1,
  201. GoFieldName: "Log",
  202. GoFieldType: "int32",
  203. JSONFieldName: "log",
  204. ProtobufFieldName: "log",
  205. ProtobufType: "int32",
  206. ProtobufPos: 7,
  207. },
  208. &ColumnInfo{
  209. Index: 7,
  210. Name: "created_at",
  211. Comment: ``,
  212. Notes: ``,
  213. Nullable: false,
  214. DatabaseTypeName: "timestamp",
  215. DatabaseTypePretty: "timestamp",
  216. IsPrimaryKey: false,
  217. IsAutoIncrement: false,
  218. IsArray: false,
  219. ColumnType: "timestamp",
  220. ColumnLength: -1,
  221. GoFieldName: "CreatedAt",
  222. GoFieldType: "time.Time",
  223. JSONFieldName: "created_at",
  224. ProtobufFieldName: "created_at",
  225. ProtobufType: "uint64",
  226. ProtobufPos: 8,
  227. },
  228. &ColumnInfo{
  229. Index: 8,
  230. Name: "updated_at",
  231. Comment: ``,
  232. Notes: ``,
  233. Nullable: false,
  234. DatabaseTypeName: "timestamp",
  235. DatabaseTypePretty: "timestamp",
  236. IsPrimaryKey: false,
  237. IsAutoIncrement: false,
  238. IsArray: false,
  239. ColumnType: "timestamp",
  240. ColumnLength: -1,
  241. GoFieldName: "UpdatedAt",
  242. GoFieldType: "time.Time",
  243. JSONFieldName: "updated_at",
  244. ProtobufFieldName: "updated_at",
  245. ProtobufType: "uint64",
  246. ProtobufPos: 9,
  247. },
  248. &ColumnInfo{
  249. Index: 9,
  250. Name: "deleted_at",
  251. Comment: ``,
  252. Notes: ``,
  253. Nullable: true,
  254. DatabaseTypeName: "timestamp",
  255. DatabaseTypePretty: "timestamp",
  256. IsPrimaryKey: false,
  257. IsAutoIncrement: false,
  258. IsArray: false,
  259. ColumnType: "timestamp",
  260. ColumnLength: -1,
  261. GoFieldName: "DeletedAt",
  262. GoFieldType: "null.Time",
  263. JSONFieldName: "deleted_at",
  264. ProtobufFieldName: "deleted_at",
  265. ProtobufType: "uint64",
  266. ProtobufPos: 10,
  267. },
  268. },
  269. }
  270. // TableName sets the insert table name for this struct type
  271. func (a *AdminPermission) TableName() string {
  272. return "admin_permission"
  273. }
  274. // BeforeSave invoked before saving, return an error if field is not populated.
  275. func (a *AdminPermission) BeforeSave(*gorm.DB) error {
  276. return nil
  277. }
  278. // Prepare invoked before saving, can be used to populate fields etc.
  279. func (a *AdminPermission) Prepare() {
  280. }
  281. // Validate invoked before performing action, return an error if field is not populated.
  282. func (a *AdminPermission) Validate(action Action) error {
  283. return nil
  284. }
  285. // TableInfo return table meta data
  286. func (a *AdminPermission) TableInfo() *TableInfo {
  287. return admin_permissionTableInfo
  288. }