mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
add License seed, genericize Seed()
This commit is contained in:
parent
bb1823ac4c
commit
254af58933
5 changed files with 111 additions and 6 deletions
|
|
@ -29,15 +29,16 @@ public static bool AllMigrationsApplied(this DbContext context)
|
|||
|
||||
public static void EnsureSeeded(this FilterListsDbContext context)
|
||||
{
|
||||
SeedFilterLists(context);
|
||||
if (context.FilterLists.Any()) return;
|
||||
Seed<License>(context);
|
||||
Seed<FilterList>(context);
|
||||
}
|
||||
|
||||
private static void SeedFilterLists(FilterListsDbContext context)
|
||||
private static void Seed<T>(DbContext context)
|
||||
{
|
||||
if (context.FilterLists.Any()) return;
|
||||
var types = JsonConvert.DeserializeObject<List<FilterList>>(
|
||||
File.ReadAllText(SeedDirectory + Path.DirectorySeparatorChar + "FilterLists.json"));
|
||||
context.AddRange(types);
|
||||
var rows = JsonConvert.DeserializeObject<List<T>>(
|
||||
File.ReadAllText(SeedDirectory + Path.DirectorySeparatorChar + typeof(T) + ".json"));
|
||||
context.AddRange(rows);
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
17
src/FilterLists.Api/Seed/FilterList.sql
Normal file
17
src/FilterLists.Api/Seed/FilterList.sql
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
select
|
||||
Id,
|
||||
Description,
|
||||
DescriptionSourceUrl,
|
||||
DiscontinuedDate,
|
||||
DonateUrl,
|
||||
EmailAddress,
|
||||
ForumUrl,
|
||||
HomeUrl,
|
||||
IssuesUrl,
|
||||
LicenseId,
|
||||
Name,
|
||||
SubmissionUrl,
|
||||
SyntaxId,
|
||||
ViewUrl
|
||||
from
|
||||
filterlists
|
||||
79
src/FilterLists.Api/Seed/License.json
Normal file
79
src/FilterLists.Api/Seed/License.json
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
[
|
||||
{
|
||||
"Id": 1,
|
||||
"DescriptionUrl": "https://creativecommons.org/licenses/by-nc-nd/4.0/",
|
||||
"Name": "CC BY-NC-ND 4.0",
|
||||
"PermissiveAdaptation": 0,
|
||||
"PermissiveCommercial": 0
|
||||
},
|
||||
{
|
||||
"Id": 2,
|
||||
"DescriptionUrl": "https://opensource.org/licenses/MIT",
|
||||
"Name": "The MIT License",
|
||||
"PermissiveAdaptation": 1,
|
||||
"PermissiveCommercial": 1
|
||||
},
|
||||
{
|
||||
"Id": 3,
|
||||
"DescriptionUrl": null,
|
||||
"Name": "Restricted (General)",
|
||||
"PermissiveAdaptation": 0,
|
||||
"PermissiveCommercial": 0
|
||||
},
|
||||
{
|
||||
"Id": 4,
|
||||
"DescriptionUrl": "https://www.gnu.org/licenses/gpl-3.0.en.html",
|
||||
"Name": "GPLv3",
|
||||
"PermissiveAdaptation": 1,
|
||||
"PermissiveCommercial": 1
|
||||
},
|
||||
{
|
||||
"Id": 5,
|
||||
"DescriptionUrl": "https://en.wikipedia.org/wiki/All_rights_reserved",
|
||||
"Name": "All Rights Reserved (Default)",
|
||||
"PermissiveAdaptation": 0,
|
||||
"PermissiveCommercial": 0
|
||||
},
|
||||
{
|
||||
"Id": 6,
|
||||
"DescriptionUrl": "https://creativecommons.org/licenses/by-nc-sa/3.0/",
|
||||
"Name": "CC BY-NC-SA 3.0",
|
||||
"PermissiveAdaptation": 1,
|
||||
"PermissiveCommercial": 0
|
||||
},
|
||||
{
|
||||
"Id": 7,
|
||||
"DescriptionUrl": null,
|
||||
"Name": "Permissive (General)",
|
||||
"PermissiveAdaptation": 1,
|
||||
"PermissiveCommercial": 1
|
||||
},
|
||||
{
|
||||
"Id": 8,
|
||||
"DescriptionUrl": "https://creativecommons.org/licenses/by-sa/4.0/",
|
||||
"Name": "CC BY-SA 4.0",
|
||||
"PermissiveAdaptation": 1,
|
||||
"PermissiveCommercial": 1
|
||||
},
|
||||
{
|
||||
"Id": 9,
|
||||
"DescriptionUrl": "https://creativecommons.org/licenses/by-nc-sa/4.0/",
|
||||
"Name": "CC BY-NC-SA 4.0",
|
||||
"PermissiveAdaptation": 1,
|
||||
"PermissiveCommercial": 0
|
||||
},
|
||||
{
|
||||
"Id": 10,
|
||||
"DescriptionUrl": "https://opensource.org/licenses/BSD-3-Clause",
|
||||
"Name": "BSD-3-Clause",
|
||||
"PermissiveAdaptation": 1,
|
||||
"PermissiveCommercial": 1
|
||||
},
|
||||
{
|
||||
"Id": 11,
|
||||
"DescriptionUrl": "https://unlicense.org/",
|
||||
"Name": "The Unlicense",
|
||||
"PermissiveAdaptation": 1,
|
||||
"PermissiveCommercial": 1
|
||||
}
|
||||
]
|
||||
8
src/FilterLists.Api/Seed/License.sql
Normal file
8
src/FilterLists.Api/Seed/License.sql
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
SELECT
|
||||
Id,
|
||||
DescriptionUrl,
|
||||
Name,
|
||||
PermissiveAdaptation,
|
||||
PermissiveCommercial
|
||||
FROM
|
||||
filterlistsdata.licenses;
|
||||
Loading…
Reference in a new issue